Eliminate viper references from token and webhook

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
This commit is contained in:
justusbunsi 2021-10-17 15:57:45 +02:00
parent 021d01b5fb
commit e01096a7fe
No known key found for this signature in database
GPG key ID: 82B29BF2507F9F8B
3 changed files with 10 additions and 14 deletions

View file

@ -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"),
}
}

View file

@ -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)

View file

@ -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)