Skip to content

Commit

Permalink
Refactoring / reformatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ngaberel committed Apr 11, 2023
1 parent 6dbd13d commit 918ef60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
27 changes: 9 additions & 18 deletions pkg/resources/password_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,40 +214,31 @@ func ReadPasswordPolicy(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("failed to parse result of describe: %w", err)
}

err = d.Set("min_length", output.MinLength)
if err != nil {
if err = d.Set("min_length", output.MinLength); err != nil {
return fmt.Errorf("error setting min_length: %w", err)
}
err = d.Set("max_length", output.MaxLength)
if err != nil {
if err = d.Set("max_length", output.MaxLength); err != nil {
return fmt.Errorf("error setting max_length: %w", err)
}
err = d.Set("min_upper_case_chars", output.MinUpperCaseChars)
if err != nil {
if err = d.Set("min_upper_case_chars", output.MinUpperCaseChars); err != nil {
return fmt.Errorf("error setting min_upper_case_chars: %w", err)
}
err = d.Set("min_lower_case_chars", output.MinLowerCaseChars)
if err != nil {
if err = d.Set("min_lower_case_chars", output.MinLowerCaseChars); err != nil {
return fmt.Errorf("error setting min_lower_case_chars: %w", err)
}
err = d.Set("min_numeric_chars", output.MinNumericChars)
if err != nil {
if err = d.Set("min_numeric_chars", output.MinNumericChars); err != nil {
return fmt.Errorf("error setting min_numeric_chars: %w", err)
}
err = d.Set("min_special_chars", output.MinSpecialChars)
if err != nil {
if err = d.Set("min_special_chars", output.MinSpecialChars); err != nil {
return fmt.Errorf("error setting min_special_chars: %w", err)
}
err = d.Set("max_age_days", output.MaxAgeDays)
if err != nil {
if err = d.Set("max_age_days", output.MaxAgeDays); err != nil {
return fmt.Errorf("error setting max_age_days: %w", err)
}
err = d.Set("max_retries", output.MaxRetries)
if err != nil {
if err = d.Set("max_retries", output.MaxRetries); err != nil {
return fmt.Errorf("error setting max_retries: %w", err)
}
err = d.Set("lockout_time_mins", output.LockoutTimeMins)
if err != nil {
if err = d.Set("lockout_time_mins", output.LockoutTimeMins); err != nil {
return fmt.Errorf("error setting lockout_time_mins: %w", err)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/snowflake/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ var (
StringList ParamType = "stringlist"
)

type Param struct {
type SQLParameter struct {
name string
paramType ParamType
}

type BuilderConfig struct {
beforeObjectType map[string]string
afterObjectType map[string]string
parameters map[string]*Param
parameters map[string]*SQLParameter
}

type NewBuilder struct {
Expand Down Expand Up @@ -57,7 +57,7 @@ func parseConfigFromType(t reflect.Type) (*BuilderConfig, error) {
config := &BuilderConfig{
beforeObjectType: map[string]string{},
afterObjectType: map[string]string{},
parameters: map[string]*Param{},
parameters: map[string]*SQLParameter{},
}

for i := 0; i < t.NumField(); i++ {
Expand Down Expand Up @@ -100,7 +100,7 @@ func parseConfigFromType(t reflect.Type) (*BuilderConfig, error) {
paramType = StringList
}

config.parameters[f.Name] = &Param{
config.parameters[f.Name] = &SQLParameter{
name: f.Tag.Get("db"),
paramType: paramType,
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (b *NewBuilder) renderKeywords(obj Identifier, kwConf map[string]string) (s
return sb.String(), nil
}

func (b *NewBuilder) renderParameters(obj Identifier, paramConf map[string]*Param, withValues bool) (string, error) {
func (b *NewBuilder) renderParameters(obj Identifier, paramConf map[string]*SQLParameter, withValues bool) (string, error) {
sb := strings.Builder{}

for key := range paramConf {
Expand Down
7 changes: 5 additions & 2 deletions pkg/snowflake/password_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func (m *PasswordPolicyManager) Create(x *PasswordPolicyCreateInput) (string, er
return m.genericBuilder.Create(x)
}

type PasswordPolicyReadInput = SchemaObjectIdentifier
type PasswordPolicyReadOutput = PasswordPolicy
type (
PasswordPolicyReadInput = SchemaObjectIdentifier
PasswordPolicyReadOutput = PasswordPolicy
)

func (m *PasswordPolicyManager) Read(x *PasswordPolicyReadInput) (string, error) {
return m.genericBuilder.Describe(x)
Expand All @@ -95,6 +97,7 @@ type PasswordPolicyUpdateInput struct {
func (m *PasswordPolicyManager) Update(x *PasswordPolicyUpdateInput) (string, error) {
return m.genericBuilder.Alter(x)
}

func (m *PasswordPolicyManager) Unset(x *PasswordPolicyUpdateInput) (string, error) {
return m.genericBuilder.Unset(x)
}
Expand Down

0 comments on commit 918ef60

Please sign in to comment.