Skip to content

Commit

Permalink
rename HydraConfig to ClientConfig and retry config block to retry_po…
Browse files Browse the repository at this point in the history
…licy
  • Loading branch information
tjorri committed May 28, 2024
1 parent 426eeba commit 3593df7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions internal/provider/data_source_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
schema.DescriptionKind = schema.StringMarkdown
}

type HydraConfig struct {
type ClientConfig struct {
hydraClient *hydra.APIClient
backOff *backoff.ExponentialBackOff
}
Expand All @@ -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,
Expand Down Expand Up @@ -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{})
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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)
}
Expand All @@ -97,15 +97,15 @@ 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) {
var err error
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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_oauth2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand All @@ -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

Expand All @@ -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) {
Expand All @@ -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)

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 3593df7

Please sign in to comment.