From 3593df76c8ed46492c9a95a377e61191029dfd69 Mon Sep 17 00:00:00 2001 From: Tuomo Date: Tue, 28 May 2024 12:47:14 +0300 Subject: [PATCH] rename HydraConfig to ClientConfig and retry config block to retry_policy --- internal/provider/data_source_jwks.go | 4 ++-- internal/provider/provider.go | 8 ++++---- internal/provider/resource_jwks.go | 16 ++++++++-------- internal/provider/resource_oauth2_client.go | 16 ++++++++-------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/provider/data_source_jwks.go b/internal/provider/data_source_jwks.go index fe6f4c0..edee0c0 100644 --- a/internal/provider/data_source_jwks.go +++ b/internal/provider/data_source_jwks.go @@ -32,7 +32,7 @@ A JSON Web Key is identified by its set and key id. ORY Hydra uses this function func readJWKSDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { data.SetId(data.Get("name").(string)) - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient var jsonWebKeySet *hydra.JsonWebKeySet @@ -41,7 +41,7 @@ func readJWKSDataSource(ctx context.Context, data *schema.ResourceData, meta int var resp *http.Response jsonWebKeySet, resp, err = hydraClient.JwkApi.GetJsonWebKeySet(ctx, data.Id()).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2ba3a09..57aa983 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -22,7 +22,7 @@ func init() { schema.DescriptionKind = schema.StringMarkdown } -type HydraConfig struct { +type ClientConfig struct { hydraClient *hydra.APIClient backOff *backoff.ExponentialBackOff } @@ -35,7 +35,7 @@ func New() *schema.Provider { Required: true, DefaultFunc: schema.EnvDefaultFunc("HYDRA_ADMIN_URL", nil), }, - "retry": { + "retry_policy": { Type: schema.TypeList, Optional: true, MaxItems: 1, @@ -232,7 +232,7 @@ func providerConfigure(ctx context.Context, data *schema.ResourceData) (interfac } var backOff *backoff.ExponentialBackOff - if retry, ok := data.GetOk("retry.0"); ok && data.Get("retry.0.enabled").(bool) { + if retry, ok := data.GetOk("retry_policy.0"); ok && data.Get("retry_policy.0.enabled").(bool) { backOff = backoff.NewExponentialBackOff() retryConfig := retry.(map[string]interface{}) @@ -246,7 +246,7 @@ func providerConfigure(ctx context.Context, data *schema.ResourceData) (interfac backOff.RandomizationFactor = randomizationFactor } - return &HydraConfig{ + return &ClientConfig{ hydraClient: hydra.NewAPIClient(cfg), backOff: backOff, }, nil diff --git a/internal/provider/resource_jwks.go b/internal/provider/resource_jwks.go index 9aee068..35f677d 100644 --- a/internal/provider/resource_jwks.go +++ b/internal/provider/resource_jwks.go @@ -77,7 +77,7 @@ func createJWKSResource(ctx context.Context, data *schema.ResourceData, meta int } func generateJWKSResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient setName := data.Get("name").(string) generators := data.Get("generator").([]interface{}) @@ -86,7 +86,7 @@ func generateJWKSResource(ctx context.Context, data *schema.ResourceData, meta i err := retryThrottledHydraAction(func() (*http.Response, error) { _, resp, err := hydraClient.JwkApi.CreateJsonWebKeySet(ctx, setName).CreateJsonWebKeySet(*dataToJWKGeneratorRequest(generator)).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } @@ -97,7 +97,7 @@ func generateJWKSResource(ctx context.Context, data *schema.ResourceData, meta i } func readJWKSResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient var jsonWebKeySet *hydra.JsonWebKeySet err := retryThrottledHydraAction(func() (*http.Response, error) { @@ -105,7 +105,7 @@ func readJWKSResource(ctx context.Context, data *schema.ResourceData, meta inter var resp *http.Response jsonWebKeySet, resp, err = hydraClient.JwkApi.GetJsonWebKeySet(ctx, data.Id()).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } @@ -116,14 +116,14 @@ func readJWKSResource(ctx context.Context, data *schema.ResourceData, meta inter } func updateJWKSResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient setName := data.Get("name").(string) err := retryThrottledHydraAction(func() (*http.Response, error) { _, resp, err := hydraClient.JwkApi.SetJsonWebKeySet(ctx, setName).JsonWebKeySet(*dataToJWKS(data, "key")).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } @@ -134,13 +134,13 @@ func updateJWKSResource(ctx context.Context, data *schema.ResourceData, meta int } func deleteJWKSResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient setName := data.Get("name").(string) err := retryThrottledHydraAction(func() (*http.Response, error) { return hydraClient.JwkApi.DeleteJsonWebKeySet(ctx, setName).Execute() - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } diff --git a/internal/provider/resource_oauth2_client.go b/internal/provider/resource_oauth2_client.go index 0973bd2..69c0955 100644 --- a/internal/provider/resource_oauth2_client.go +++ b/internal/provider/resource_oauth2_client.go @@ -322,7 +322,7 @@ The default, if omitted, is for the UserInfo Response to return the Claims as a } func createOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient var oAuth2Client *hydra.OAuth2Client @@ -333,7 +333,7 @@ func createOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, var resp *http.Response oAuth2Client, resp, err = hydraClient.OAuth2Api.CreateOAuth2Client(ctx).OAuth2Client(*client).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } @@ -342,7 +342,7 @@ func createOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, } func readOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient var oAuth2Client *hydra.OAuth2Client @@ -353,7 +353,7 @@ func readOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, me oAuth2Client, resp, err = hydraClient.OAuth2Api.GetOAuth2Client(ctx, data.Id()).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { var genericOpenAPIError *hydra.GenericOpenAPIError if errors.As(err, &genericOpenAPIError) { @@ -370,7 +370,7 @@ func readOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, me } func updateOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient oAuthClient := dataToClient(data) @@ -380,7 +380,7 @@ func updateOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, oAuthClient, resp, err = hydraClient.OAuth2Api.SetOAuth2Client(ctx, data.Id()).OAuth2Client(*oAuthClient).Execute() return resp, err - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) if err != nil { return diag.FromErr(err) } @@ -389,11 +389,11 @@ func updateOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, } func deleteOAuth2ClientResource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - hydraClient := meta.(*HydraConfig).hydraClient + hydraClient := meta.(*ClientConfig).hydraClient err := retryThrottledHydraAction(func() (*http.Response, error) { return hydraClient.OAuth2Api.DeleteOAuth2Client(ctx, data.Id()).Execute() - }, meta.(*HydraConfig).backOff) + }, meta.(*ClientConfig).backOff) return diag.FromErr(err) }