Skip to content

Commit

Permalink
Flatten endpoint_params as a map of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
DRuggeri committed Aug 5, 2024
1 parent f1b8ec8 commit cae0619
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
6 changes: 2 additions & 4 deletions .release_info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## Fixed
- Do not attempt to send data if `read_data` is not set

## Misc
- Adjust checks for when data should be sent in `update|read|destroy_data` operations to be more deterministic
- Thanks to a proposal in #202 by @harshavmb, the long broken `endpoint_params` in `oauth_client_credentials` is working!
- Fix incorrect state after failed updates when errors are detected. Thanks for the report #152, @jollyroger and the PR #265, @ugur-zongur!
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ provider "restapi" {
- `insecure` (Boolean) When using https, this disables TLS verification of the host.
- `key_file` (String) When set with the cert_file parameter, the provider will load a client certificate as a file for mTLS authentication. Note that this mechanism simply delegates to golang's tls.LoadX509KeyPair which does not support passphrase protected private keys. The most robust security protections available to the key_file are simple file system permissions.
- `key_string` (String) When set with the cert_string parameter, the provider will load a client certificate as a string for mTLS authentication. Note that this mechanism simply delegates to golang's tls.LoadX509KeyPair which does not support passphrase protected private keys. The most robust security protections available to the key_file are simple file system permissions.
- `oauth_client_credentials` (Block List, Max: 1) Configuration for oauth client credential flow (see [below for nested schema](#nestedblock--oauth_client_credentials))
- `oauth_client_credentials` (Block List, Max: 1) Configuration for oauth client credential flow using the https://pkg.go.dev/golang.org/x/oauth2 implementation (see [below for nested schema](#nestedblock--oauth_client_credentials))
- `password` (String) When set, will use this password for BASIC auth to the API.
- `rate_limit` (Number) Set this to limit the number of requests per second made to the API.
- `read_method` (String) Defaults to `GET`. The HTTP method used to READ objects of this type on the API server.
Expand All @@ -73,5 +73,5 @@ Required:

Optional:

- `endpoint_params` (Map of List of String) Additional key/values to pass to the underlying Oauth client library (as EndpointParams)
- `endpoint_params` (Map of String) Additional key/values to pass to the underlying Oauth client library (as EndpointParams)
- `oauth_scopes` (List of String) scopes
13 changes: 8 additions & 5 deletions examples/workingexamples/provider_with_oauth.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ provider "restapi" {
write_returns_object = true

oauth_client_credentials {
oauth_client_id = "example"
oauth_client_secret = "example"
oauth_token_endpoint = "https://example.com/tokenendpoint"
oauth_scopes = ["openid"]
oauth_client_id = "example"
oauth_client_secret = "example"
oauth_token_endpoint = "https://example.com/tokenendpoint"
oauth_scopes = ["openid"]
endpoint_params = {
audience = "myCoolAPI"
}
}
}
}
11 changes: 4 additions & 7 deletions restapi/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Provider() *schema.Provider {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration for oauth client credential flow",
Description: "Configuration for oauth client credential flow using the https://pkg.go.dev/golang.org/x/oauth2 implementation",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"oauth_client_id": {
Expand Down Expand Up @@ -161,8 +161,7 @@ func Provider() *schema.Provider {
Optional: true,
Description: "Additional key/values to pass to the underlying Oauth client library (as EndpointParams)",
Elem: &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeString,
},
},
},
Expand Down Expand Up @@ -264,10 +263,8 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
if tmp, ok := oauthConfig["endpoint_params"]; ok {
m := tmp.(map[string]interface{})
setVals := url.Values{}
for k, vals := range m {
for _, val := range vals.([]string) {
setVals.Add(k, val)
}
for k, val := range m {
setVals.Add(k, val.(string))
}
opt.oauthEndpointParams = setVals
}
Expand Down
13 changes: 3 additions & 10 deletions restapi/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ func TestResourceProvider_Oauth(t *testing.T) {
"uri": "http://foo.bar/baz",
"oauth_client_credentials": map[string]interface{}{
"oauth_client_id": "test",
/*
Commented out 2022-06-27. Although terraform allows the provider to define this as
array of strings, it panics during unmarshal on the terraform provider SDK
"oauth_client_credentials": map[string]interface{}{
"test": []string{
"value1",
"value2",
},
},
*/
"oauth_client_credentials": map[string]interface{}{
"audience": "coolAPI",
},
},
}

Expand Down

0 comments on commit cae0619

Please sign in to comment.