Skip to content

Commit

Permalink
Move config version validation before unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel committed Oct 25, 2023
1 parent e4bd026 commit b14d5c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/cc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func NewConfig(configPath Path, log *zerolog.Logger, overrides Overrider, certsG
if err := v.ReadConfig(r); err != nil {
return nil, errors.Wrapf(err, "failed to parse config file '%s'", file)
}

err = validateVersion(v.GetInt("version"))
if err != nil {
return nil, err
}
}

v.AutomaticEnv()
Expand Down
8 changes: 6 additions & 2 deletions pkg/cc/config/topaz_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ func (co *CallOptions) ForPath(path string) *Options {
func defaults(v *viper.Viper) {
}

func (c *Config) validation() error {
if c.Version != ConfigFileVersion {
func validateVersion(version int) error {
if version != ConfigFileVersion {
return errors.New("unsupported config version")
}
return nil
}

func (c *Config) validation() error {
if _, ok := c.APIConfig.Services["authorizer"]; ok {
if c.Command.Mode == CommandModeRun && c.OPA.InstanceID == "" {
return errors.New("opa.instance_id not set")
Expand Down

0 comments on commit b14d5c4

Please sign in to comment.