add a configuration file (#453)

* complete updated config package

* use envconfig+toml instead of viper. Add descriptions in example config file

* add unit tests

* debug gofmt on build server

* force dummy commit

* skip gofmt to validate other tests are passing

* unset env vars for example file parsing test

* cleanup tests

* test improvements

* re-enable gofmt

* naming

* PR comments

* fix failing test after olympus default endpoint change

* remove rdbms config

* set defaults in code

* add support for proxyfilteroff

* add basic auth params

* update gopkg.lock

* undo gopkg.lock changes made during merge

* remove defaults

* explicitly specify all env variables

* remove rdbms from example

* remove user and pass to disable basic auth by default

* switch to memory by default for the proxy

* fix tests after config file change
This commit is contained in:
Rohan Chakravarthy
2018-08-31 11:23:41 -07:00
committed by Marwan Sulaiman
parent df14f2b691
commit 7c745fb3d9
64 changed files with 11305 additions and 38 deletions
+66
View File
@@ -0,0 +1,66 @@
package config
import validator "gopkg.in/go-playground/validator.v9"
// StorageConfig provides configs for various storage backends
type StorageConfig struct {
CDN *CDNConfig `validate:""`
Disk *DiskConfig `validate:""`
GCP *GCPConfig `validate:""`
Minio *MinioConfig `validate:""`
Mongo *MongoConfig `validate:""`
}
func setStorageTimeouts(s *StorageConfig, defaultTimeout int) {
if s == nil {
return
}
if s.CDN != nil && s.CDN.Timeout == 0 {
s.CDN.Timeout = defaultTimeout
}
if s.GCP != nil && s.GCP.Timeout == 0 {
s.GCP.Timeout = defaultTimeout
}
if s.Minio != nil && s.Minio.Timeout == 0 {
s.Minio.Timeout = defaultTimeout
}
if s.Mongo != nil && s.Mongo.Timeout == 0 {
s.Mongo.Timeout = defaultTimeout
}
}
// envconfig initializes *all* struct pointers, even if there are no corresponding defaults or env variables
// deleteInvalidStorageConfigs prunes all such invalid configurations
func deleteInvalidStorageConfigs(s *StorageConfig) {
validate := validator.New()
if s.CDN != nil {
if err := validate.Struct(s.CDN); err != nil {
s.CDN = nil
}
}
if s.Disk != nil {
if err := validate.Struct(s.Disk); err != nil {
s.Disk = nil
}
}
if s.GCP != nil {
if err := validate.Struct(s.GCP); err != nil {
s.GCP = nil
}
}
if s.Minio != nil {
if err := validate.Struct(s.Minio); err != nil {
s.Minio = nil
}
}
if s.Mongo != nil {
if err := validate.Struct(s.Mongo); err != nil {
s.Mongo = nil
}
}
}