frontier icon indicating copy to clipboard operation
frontier copied to clipboard

fix: fix tags for shield config

Open bsushmith opened this issue 3 years ago • 4 comments

Add mapstructure tags to parse shield config through viper in expected ways

bsushmith avatar Feb 23 '22 11:02 bsushmith

@bsushmith can you explain the changes ?

krtkvrm avatar Feb 24 '22 03:02 krtkvrm

Currently, the way the config is read and parsed is thru viper, and viper uses mapstructure tags and if those are not present, it uses the var names(lowercase) in the struct itself as the config key string to parse from config file.

https://github.com/odpf/salt/blob/main/config/config.go#L174 uses mapstructure tags to get the flattened keys. At the moment, we have mapstructure tags are present for all internal fields in the shield config, but not at the top level.

example:

type SpiceDBConfig struct {
	Host         string `yaml:"host"`
	Port         string `yaml:"port" default:"50051"`
	PreSharedKey string `yaml:"pre_shared_key" mapstructure:"pre_shared_key"`
}

without these changes, the config for example spicedb would be expected as spicedb.pre_shared_key rather than spice_db.pre_shared_key which leads to confusion as to half of it is getting parsed using one way and other part in other way.

bsushmith avatar Feb 24 '22 04:02 bsushmith

These changes will break the current env keys, we need to update the env keys to handle this change. viper create different keys with yaml/json and mapstructure tags ex. yaml spicedb will remove the underscore and create env SPICEDB but with map structure, env keys preserve the underscore. SPICE_DB

rsbh avatar Feb 24 '22 04:02 rsbh

These changes will break the current env keys, we need to update the env keys to handle this change. viper create different keys with yaml/json and mapstructure tags ex. yaml spicedb will remove the underscore and create env SPICEDB but with map structure, env keys preserve the underscore. SPICE_DB

I think this is configurable.

ravisuhag avatar Jul 12 '22 08:07 ravisuhag

This is already handled in a separate PR.

ravisuhag avatar Aug 21 '22 17:08 ravisuhag