Skip to content

Commit

Permalink
Merge branch 'master' into ryanking/snowflake_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking authored May 17, 2019
2 parents edcdee9 + 876ec2a commit c2572fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions config/v2/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func ResolveStringMap(getter func(Common) map[string]string, commons ...Common)
// config objects passed in. Otherwise it will return nil.
func ResolveAWSProvider(commons ...Common) *AWSProvider {


// we may in the future want invert this implementation and walk the structs first
profile := lastNonNil(AWSProviderProfileGetter, commons...)
region := lastNonNil(AWSProviderRegionGetter, commons...)
Expand Down Expand Up @@ -209,12 +210,14 @@ func SnowflakeProviderAccountGetter(comm Common) *string {
}
return nil
}

func SnowflakeProviderRoleGetter(comm Common) *string {
if comm.Providers != nil && comm.Providers.Snowflake != nil {
return comm.Providers.Snowflake.Role
}
return nil
}

func SnowflakeProviderRegionGetter(comm Common) *string {
if comm.Providers != nil && comm.Providers.Snowflake != nil {
return comm.Providers.Snowflake.Region
Expand Down
31 changes: 17 additions & 14 deletions config/v2/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func (c *Config) WalkComponents(f func(component string, commons ...Common)) {
for componentName, component := range env.Components {
f(fmt.Sprintf("%s/%s", envName, componentName), c.Defaults.Common, env.Common, component.Common)
}
return errs
}

}

// validateInheritedStringField will walk all accounts and components and ensure that a given field is valid at at least
Expand All @@ -139,37 +141,38 @@ func (c *Config) validateInheritedStringField(fieldName string, getter func(Comm
var err *multierror.Error

// For each account, we need the field to be valid in either the defaults or account
for acctName, acct := range c.Accounts {
v := lastNonNil(getter, c.Defaults.Common, acct.Common)
for name, acct := range c.Accounts {
v := ResolveAWSProvider(c.Defaults.Common, acct.Common)
if v == nil {
err = multierror.Append(err, fmt.Errorf("account %s must have field %s at either the account or defaults level", acctName, fieldName))
} else if !validator(*v) {
err = multierror.Append(err, fmt.Errorf("account %s must have a valid %s set at either the account or defaults level", acctName, fieldName))
// nothing to validate
} else if e := validate(*v, fmt.Sprintf("accounts/%s", name)); e != nil {
errs = multierror.Append(errs, e)
}
}

// global
v := lastNonNil(getter, c.Defaults.Common, c.Global.Common)
v := ResolveAWSProvider(c.Defaults.Common, c.Global.Common)
if v == nil {
err = multierror.Append(err, fmt.Errorf("global must have a %s set at either the global or defaults level", fieldName))
} else if !validator(*v) {
err = multierror.Append(err, fmt.Errorf("global must have a valid %s set at either the global or defaults level", fieldName))
//nothing to do
} else if e := validate(*v, "global"); e != nil {
errs = multierror.Append(errs, e)
}

// For each component, we need the field to be valid at one of defaults, env or component
for envName, env := range c.Envs {
for componentName, component := range env.Components {
v := lastNonNil(getter, c.Defaults.Common, env.Common, component.Common)
v := ResolveAWSProvider(c.Defaults.Common, env.Common, component.Common)

if v == nil {
err = multierror.Append(err, fmt.Errorf("componnent %s/%s must have a %s", envName, componentName, fieldName))
} else if !validator(*v) {
err = multierror.Append(err, fmt.Errorf("componnent %s/%s must have a valid %s", envName, componentName, fieldName))
// nothing to validate
} else if e := validate(*v, fmt.Sprintf("%s/%s", envName, componentName)); e != nil {
errs = multierror.Append(errs, e)
}
}
}

return err
return errs.ErrorOrNil()

}

// validateExtraVars make sure users don't specify reserved variables
Expand Down

0 comments on commit c2572fd

Please sign in to comment.