Skip to content

Commit

Permalink
Merge pull request #81 from lacroi-m-insta/main
Browse files Browse the repository at this point in the history
feat: add support for retry_delay_ms, max_retries, retryable_errors
  • Loading branch information
AtzeDeVries authored Sep 13, 2024
2 parents 77af79a + e84b1a0 commit afa3f3e
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions internal/clients/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
keyAppAuthPemFile = "pem_file"
keyWriteDelayMs = "write_delay_ms"
keyReadDelayMs = "read_delay_ms"
keyRetryDelayMs = "retry_delay_ms"
keyMaxRetries = "max_retries"
keyRetryableErrors = "retryable_errors"
)

type appAuth struct {
Expand All @@ -49,22 +52,19 @@ type appAuth struct {
}

type githubConfig struct {
BaseURL *string `json:"base_url,omitempty"`
Owner *string `json:"owner,omitempty"`
Token *string `json:"token,omitempty"`
AppAuth *[]appAuth `json:"app_auth,omitempty"`
WriteDelayMs *int `json:"write_delay_ms,omitempty"`
ReadDelayMs *int `json:"read_delay_ms,omitempty"`
BaseURL *string `json:"base_url,omitempty"`
Owner *string `json:"owner,omitempty"`
Token *string `json:"token,omitempty"`
AppAuth *[]appAuth `json:"app_auth,omitempty"`
WriteDelayMs *int `json:"write_delay_ms,omitempty"`
ReadDelayMs *int `json:"read_delay_ms,omitempty"`
RetryDelayMs *int `json:"retry_delay_ms,omitempty"`
MaxRetries *int `json:"max_retries,omitempty"`
RetryableErrors []int `json:"retryable_errors,omitempty"`
}

func terraformProviderConfigurationBuilder(creds githubConfig) (terraform.ProviderConfiguration, error) {

cnf := terraform.ProviderConfiguration{}

if creds.BaseURL != nil {
cnf[keyBaseURL] = *creds.BaseURL
}

// setCredentialConfigs will add credential type fields (Owner, Token, AppAuth) to terraform providerConfiguration
func setCredentialConfigs(creds githubConfig, cnf terraform.ProviderConfiguration) (terraform.ProviderConfiguration, error) {
if creds.Owner != nil {
cnf[keyOwner] = *creds.Owner
}
Expand All @@ -90,6 +90,11 @@ func terraformProviderConfigurationBuilder(creds githubConfig) (terraform.Provid
cnf[keyAppAuth] = aaList
}

return cnf, nil
}

// setParameterConfigs will add configuration type fields (WriteDelayMs, ReadDelayMs, RetryDelayMs, MaxRetries, RetryableErrors) to terraform providerConfiguration
func setParameterConfigs(creds githubConfig, cnf terraform.ProviderConfiguration) terraform.ProviderConfiguration {
if creds.WriteDelayMs != nil {
cnf[keyWriteDelayMs] = *creds.WriteDelayMs
}
Expand All @@ -98,6 +103,36 @@ func terraformProviderConfigurationBuilder(creds githubConfig) (terraform.Provid
cnf[keyReadDelayMs] = *creds.ReadDelayMs
}

if creds.RetryDelayMs != nil {
cnf[keyRetryDelayMs] = *creds.RetryDelayMs
}

if creds.MaxRetries != nil {
cnf[keyMaxRetries] = *creds.MaxRetries
}

if creds.RetryableErrors != nil {
cnf[keyRetryableErrors] = creds.RetryableErrors
}

return cnf
}

func terraformProviderConfigurationBuilder(creds githubConfig) (terraform.ProviderConfiguration, error) {

cnf := terraform.ProviderConfiguration{}

if creds.BaseURL != nil {
cnf[keyBaseURL] = *creds.BaseURL
}

cnf, err := setCredentialConfigs(creds, cnf)
if err != nil {
return cnf, errors.Errorf(errTerraformProviderMissingOwner)
}

cnf = setParameterConfigs(creds, cnf)

return cnf, nil

}
Expand Down

0 comments on commit afa3f3e

Please sign in to comment.