Export webhook and token struct

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

View file

@ -7,6 +7,6 @@ type GiteaRepository struct {
type giteaConfig struct { type giteaConfig struct {
Url string Url string
Token *token Token *Token
Webhook *webhook Webhook *Webhook
} }

View file

@ -58,10 +58,10 @@ func TestLoadGiteaStructure(t *testing.T) {
expected := giteaConfig{ expected := giteaConfig{
Url: "https://example.com/gitea", Url: "https://example.com/gitea",
Token: &token{ Token: &Token{
Value: "d0fcdeb5eaa99c506831f9eb4e63fc7cc484a565", Value: "d0fcdeb5eaa99c506831f9eb4e63fc7cc484a565",
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "haxxor-gitea-secret", Secret: "haxxor-gitea-secret",
}, },
} }
@ -77,10 +77,10 @@ func TestLoadGiteaStructureInjectedEnvs(t *testing.T) {
expected := giteaConfig{ expected := giteaConfig{
Url: "https://example.com/gitea", Url: "https://example.com/gitea",
Token: &token{ Token: &Token{
Value: "injected-token", Value: "injected-token",
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "injected-webhook-secret", Secret: "injected-webhook-secret",
}, },
} }
@ -99,10 +99,10 @@ func TestLoadSonarQubeStructure(t *testing.T) {
expected := sonarQubeConfig{ expected := sonarQubeConfig{
Url: "https://example.com/sonarqube", Url: "https://example.com/sonarqube",
Token: &token{ Token: &Token{
Value: "a09eb5785b25bb2cbacf48808a677a0709f02d8e", Value: "a09eb5785b25bb2cbacf48808a677a0709f02d8e",
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "haxxor-sonarqube-secret", Secret: "haxxor-sonarqube-secret",
}, },
} }
@ -133,10 +133,10 @@ projects:
expected := sonarQubeConfig{ expected := sonarQubeConfig{
Url: "https://example.com/sonarqube", Url: "https://example.com/sonarqube",
Token: &token{ Token: &Token{
Value: "fake-sonarqube-token", Value: "fake-sonarqube-token",
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "", Secret: "",
}, },
AdditionalMetrics: []string{ AdditionalMetrics: []string{
@ -157,10 +157,10 @@ func TestLoadSonarQubeStructureInjectedEnvs(t *testing.T) {
expected := sonarQubeConfig{ expected := sonarQubeConfig{
Url: "https://example.com/sonarqube", Url: "https://example.com/sonarqube",
Token: &token{ Token: &Token{
Value: "injected-token", Value: "injected-token",
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "injected-webhook-secret", Secret: "injected-webhook-secret",
}, },
} }
@ -209,11 +209,11 @@ projects:
expectedGitea := giteaConfig{ expectedGitea := giteaConfig{
Url: "https://example.com/gitea", Url: "https://example.com/gitea",
Token: &token{ Token: &Token{
Value: "d0fcdeb5eaa99c506831f9eb4e63fc7cc484a565", Value: "d0fcdeb5eaa99c506831f9eb4e63fc7cc484a565",
file: giteaTokenFile, file: giteaTokenFile,
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "gitea-totally-secret", Secret: "gitea-totally-secret",
secretFile: giteaWebhookSecretFile, secretFile: giteaWebhookSecretFile,
}, },
@ -221,11 +221,11 @@ projects:
expectedSonarQube := sonarQubeConfig{ expectedSonarQube := sonarQubeConfig{
Url: "https://example.com/sonarqube", Url: "https://example.com/sonarqube",
Token: &token{ Token: &Token{
Value: "a09eb5785b25bb2cbacf48808a677a0709f02d8e", Value: "a09eb5785b25bb2cbacf48808a677a0709f02d8e",
file: sonarqubeTokenFile, file: sonarqubeTokenFile,
}, },
Webhook: &webhook{ Webhook: &Webhook{
Secret: "sonarqube-totally-secret", Secret: "sonarqube-totally-secret",
secretFile: sonarqubeWebhookSecretFile, secretFile: sonarqubeWebhookSecretFile,
}, },

View file

@ -4,8 +4,8 @@ import "strings"
type sonarQubeConfig struct { type sonarQubeConfig struct {
Url string Url string
Token *token Token *Token
Webhook *webhook Webhook *Webhook
AdditionalMetrics []string AdditionalMetrics []string
} }

View file

@ -5,12 +5,12 @@ import (
"io/ioutil" "io/ioutil"
) )
type token struct { type Token struct {
Value string Value string
file string file string
} }
func (t *token) lookupSecret(errCallback func(string)) { func (t *Token) lookupSecret(errCallback func(string)) {
if t.file == "" { if t.file == "" {
return return
} }
@ -24,8 +24,8 @@ func (t *token) lookupSecret(errCallback func(string)) {
t.Value = string(content) t.Value = string(content)
} }
func NewToken(extractor func(string) string, confContainer string, errCallback func(string)) *token { func NewToken(extractor func(string) string, confContainer string, errCallback func(string)) *Token {
t := &token{ t := &Token{
Value: extractor(fmt.Sprintf("%s.token.value", confContainer)), Value: extractor(fmt.Sprintf("%s.token.value", confContainer)),
file: extractor(fmt.Sprintf("%s.token.file", confContainer)), file: extractor(fmt.Sprintf("%s.token.file", confContainer)),
} }

View file

@ -5,12 +5,12 @@ import (
"io/ioutil" "io/ioutil"
) )
type webhook struct { type Webhook struct {
Secret string Secret string
secretFile string secretFile string
} }
func (w *webhook) lookupSecret(errCallback func(string)) { func (w *Webhook) lookupSecret(errCallback func(string)) {
if w.secretFile == "" { if w.secretFile == "" {
return return
} }
@ -24,8 +24,8 @@ func (w *webhook) lookupSecret(errCallback func(string)) {
w.Secret = string(content) w.Secret = string(content)
} }
func NewWebhook(extractor func(string) string, confContainer string, errCallback func(string)) *webhook { func NewWebhook(extractor func(string) string, confContainer string, errCallback func(string)) *Webhook {
w := &webhook{ w := &Webhook{
Secret: extractor(fmt.Sprintf("%s.webhook.secret", confContainer)), Secret: extractor(fmt.Sprintf("%s.webhook.secret", confContainer)),
secretFile: extractor(fmt.Sprintf("%s.webhook.secretFile", confContainer)), secretFile: extractor(fmt.Sprintf("%s.webhook.secretFile", confContainer)),
} }