fix(report): prioritize env vars over config.toml (#1194)

This commit is contained in:
Kota Kanbe
2021-03-10 07:39:58 +09:00
committed by GitHub
parent 54e73c2f54
commit 5d47adb5c9
5 changed files with 22 additions and 29 deletions

View File

@@ -12,28 +12,21 @@ type HTTPConf struct {
Enabled bool `toml:"-" json:"-"`
}
const httpKey = "VULS_HTTP_URL"
// Validate validates configuration
func (c *HTTPConf) Validate() (errs []error) {
if !c.Enabled {
return nil
}
// overwrite if env var is not empty
if os.Getenv(httpKey) != "" {
c.URL = os.Getenv(httpKey)
}
if _, err := govalidator.ValidateStruct(c); err != nil {
errs = append(errs, err)
}
return errs
}
const httpKey = "VULS_HTTP_URL"
// Init set options with the following priority.
// 1. Environment variable
// 2. config.toml
func (c *HTTPConf) Init(url string) {
if os.Getenv(httpKey) != "" {
c.URL = os.Getenv(httpKey)
}
if url != "" {
c.URL = url
}
}