-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable environment overrides and built-in configuration defaults #963
Changes from all commits
7f3d7db
a5db28f
d255cdd
8ade783
5d8b9e2
bc67abb
2047fbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,45 +15,17 @@ | |
|
||
package config | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
saltMemory = 64 * 1024 | ||
saltIterations = 3 | ||
saltParameters = 2 | ||
saltLength = 16 | ||
saltKeyLength = 32 | ||
) | ||
|
||
// CryptoConfig is the configuration for the crypto package | ||
type CryptoConfig struct { | ||
Memory uint32 `mapstructure:"memory"` | ||
Iterations uint32 `mapstructure:"iterations"` | ||
Parallelism uint `mapstructure:"parallelism"` | ||
SaltLength uint32 `mapstructure:"salt_length"` | ||
KeyLength uint32 `mapstructure:"key_length"` | ||
} | ||
|
||
// SetCryptoViperDefaults sets the default values for the crypto configuration | ||
// to be picked up by viper | ||
func SetCryptoViperDefaults(v *viper.Viper) { | ||
// set default values when not set | ||
v.SetDefault("salt.memory", saltMemory) | ||
v.SetDefault("salt.iterations", saltIterations) | ||
v.SetDefault("salt.parallelism", saltParameters) | ||
v.SetDefault("salt.salt_length", saltLength) | ||
v.SetDefault("salt.key_length", saltKeyLength) | ||
Memory uint32 `mapstructure:"memory" default:"65536"` | ||
Iterations uint32 `mapstructure:"iterations" default:"50"` | ||
Parallelism uint `mapstructure:"parallelism" default:"4"` | ||
SaltLength uint32 `mapstructure:"salt_length" default:"16"` | ||
KeyLength uint32 `mapstructure:"key_length" default:"32"` | ||
} | ||
|
||
// GetCryptoConfigWithDefaults returns a CryptoConfig with default values | ||
// TODO: extract from struct default tags | ||
func GetCryptoConfigWithDefaults() CryptoConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to rename this function in a future patch, currently it's used only in tests and returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops, I do extract this from struct tags now, and you're right, I should either remove this and have the tests use |
||
return CryptoConfig{ | ||
Memory: saltMemory, | ||
Iterations: saltIterations, | ||
Parallelism: saltParameters, | ||
SaltLength: saltLength, | ||
KeyLength: saltKeyLength, | ||
} | ||
return DefaultConfigForTest().Salt | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,19 +15,9 @@ | |
|
||
package config | ||
|
||
import "github.com/spf13/viper" | ||
|
||
// LoggingConfig is the configuration for the logging package | ||
type LoggingConfig struct { | ||
Level string `mapstructure:"level"` | ||
Format string `mapstructure:"format"` | ||
LogFile string `mapstructure:"logFile"` | ||
} | ||
|
||
// SetLoggingViperDefaults sets the default values for the logging configuration | ||
// to be picked up by viper | ||
func SetLoggingViperDefaults(v *viper.Viper) { | ||
v.SetDefault("logging.level", "debug") | ||
v.SetDefault("logging.format", "json") | ||
v.SetDefault("logging.logFile", "") | ||
Level string `mapstructure:"level" default:"debug"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you didn't change this default, but do you think the default log level should be debug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 I'm fine with changing it, but the goal here was to make it so that the code actually had all the defaults. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR, but I was wondering if you had some thoughts about how verbose should the default deployment be based on your SaaS work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured we'd set the defaults to be appropriate for development work, though I could see preferring |
||
Format string `mapstructure:"format" default:"json"` | ||
LogFile string `mapstructure:"logFile" default:""` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think the other fields could also use defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I somehow lost just that one file in my commit. I suspect I hadn't saved the buffer.
Fixed!