Eliminate viper references from token and webhook
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
This commit is contained in:
parent
021d01b5fb
commit
e01096a7fe
|
@ -64,13 +64,13 @@ func Load(configPath string) {
|
|||
|
||||
Gitea = giteaConfig{
|
||||
Url: r.GetString("gitea.url"),
|
||||
Token: NewToken(r, "gitea", errCallback),
|
||||
Webhook: NewWebhook(r, "gitea", errCallback),
|
||||
Token: NewToken(r.GetString, "gitea", errCallback),
|
||||
Webhook: NewWebhook(r.GetString, "gitea", errCallback),
|
||||
}
|
||||
SonarQube = sonarQubeConfig{
|
||||
Url: r.GetString("sonarqube.url"),
|
||||
Token: NewToken(r, "sonarqube", errCallback),
|
||||
Webhook: NewWebhook(r, "sonarqube", errCallback),
|
||||
Token: NewToken(r.GetString, "sonarqube", errCallback),
|
||||
Webhook: NewWebhook(r.GetString, "sonarqube", errCallback),
|
||||
AdditionalMetrics: r.GetStringSlice("sonarqube.additionalMetrics"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package settings
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type token struct {
|
||||
|
@ -26,10 +24,10 @@ func (t *token) lookupSecret(errCallback func(string)) {
|
|||
t.Value = string(content)
|
||||
}
|
||||
|
||||
func NewToken(v *viper.Viper, confContainer string, errCallback func(string)) *token {
|
||||
func NewToken(extractor func(string) string, confContainer string, errCallback func(string)) *token {
|
||||
t := &token{
|
||||
Value: v.GetString(fmt.Sprintf("%s.token.value", confContainer)),
|
||||
file: v.GetString(fmt.Sprintf("%s.token.file", confContainer)),
|
||||
Value: extractor(fmt.Sprintf("%s.token.value", confContainer)),
|
||||
file: extractor(fmt.Sprintf("%s.token.file", confContainer)),
|
||||
}
|
||||
|
||||
t.lookupSecret(errCallback)
|
||||
|
|
|
@ -3,8 +3,6 @@ package settings
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type webhook struct {
|
||||
|
@ -26,10 +24,10 @@ func (w *webhook) lookupSecret(errCallback func(string)) {
|
|||
w.Secret = string(content)
|
||||
}
|
||||
|
||||
func NewWebhook(v *viper.Viper, confContainer string, errCallback func(string)) *webhook {
|
||||
func NewWebhook(extractor func(string) string, confContainer string, errCallback func(string)) *webhook {
|
||||
w := &webhook{
|
||||
Secret: v.GetString(fmt.Sprintf("%s.webhook.secret", confContainer)),
|
||||
secretFile: v.GetString(fmt.Sprintf("%s.webhook.secretFile", confContainer)),
|
||||
Secret: extractor(fmt.Sprintf("%s.webhook.secret", confContainer)),
|
||||
secretFile: extractor(fmt.Sprintf("%s.webhook.secretFile", confContainer)),
|
||||
}
|
||||
|
||||
w.lookupSecret(errCallback)
|
||||
|
|
Loading…
Reference in a new issue