Skip to content

Commit

Permalink
Feature/admin auth (#13)
Browse files Browse the repository at this point in the history
* add admin auth config variables

* update readme

* code format

* rename basic auth variables and envs

* update readme

* update gokong with govendor

* just rebuild

* merge

* update newest commit

* can be null

* fix name

* lowercase for variables
  • Loading branch information
jochen42 authored and kevholditch committed Mar 20, 2018
1 parent 93ac940 commit b761b42
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 46 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ provider "kong" {
}
```

Optionaly you can configure Username and Password for BasicAuth:
```hcl
provider "kong" {
kong_admin_uri = "http://myKong:8001"
kong_admin_username = "youruser"
kong_admin_password = "yourpass"
}
```

By convention the provider will first check the env variable `KONG_ADMIN_ADDR` if that variable is not set then it will default to `http://localhost:8001` if
you do not provide a provider block as above.

Expand Down
22 changes: 22 additions & 0 deletions kong/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_ADDR", "http://localhost:8001"),
Description: "The address of the kong admin url e.g. http://localhost:8001",
},
"kong_admin_usermame": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_USERNAME", ""),
Description: "An basic auth user for kong admin",
},
"kong_admin_password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_PASSWORD", ""),
Description: "An basic auth password for kong admin",
},
},

ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -54,8 +66,18 @@ func envDefaultFuncWithDefault(key string, defaultValue string) schema.SchemaDef
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
username := ""
if d.Get("kong_admin_username") != nil {
username = d.Get("kong_admin_username").(string)
}
password := ""
if d.Get("kong_admin_password") != nil {
password = d.Get("kong_admin_password").(string)
}
config := &gokong.Config{
HostAddress: d.Get("kong_admin_uri").(string),
Username: username,
Password: password,
}

return gokong.NewClient(config), nil
Expand Down
8 changes: 8 additions & 0 deletions kong/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatalf("Could not set kong host address env variable: %v", err)
}
err = os.Setenv(gokong.EnvKongAdminPassword, "AnUsername")
if err != nil {
log.Fatalf("Could not set kong admin username env variable: %v", err)
}
err = os.Setenv(gokong.EnvKongAdminPassword, "AnyPassword")
if err != nil {
log.Fatalf("Could not set kong admin password env variable: %v", err)
}

code := m.Run()

Expand Down
13 changes: 13 additions & 0 deletions vendor/github.com/kevholditch/gokong/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions vendor/github.com/kevholditch/gokong/apis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions vendor/github.com/kevholditch/gokong/certificates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/kevholditch/gokong/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions vendor/github.com/kevholditch/gokong/consumers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions vendor/github.com/kevholditch/gokong/plugins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/kevholditch/gokong/request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b761b42

Please sign in to comment.