diff --git a/.release_info.md b/.release_info.md index da1acba..0dc03b1 100644 --- a/.release_info.md +++ b/.release_info.md @@ -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! \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 38b1857..5a69665 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. @@ -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 diff --git a/examples/workingexamples/provider_with_oauth.tf b/examples/workingexamples/provider_with_oauth.tf index ebcd90e..494810c 100644 --- a/examples/workingexamples/provider_with_oauth.tf +++ b/examples/workingexamples/provider_with_oauth.tf @@ -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" + } } -} +} \ No newline at end of file diff --git a/restapi/provider.go b/restapi/provider.go index 6dab97a..20a4dbd 100644 --- a/restapi/provider.go +++ b/restapi/provider.go @@ -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": { @@ -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, }, }, }, @@ -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 } diff --git a/restapi/provider_test.go b/restapi/provider_test.go index febace7..700f2ee 100644 --- a/restapi/provider_test.go +++ b/restapi/provider_test.go @@ -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", + }, }, }