Export webhook and token struct
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
This commit is contained in:
parent
e01096a7fe
commit
21837f9b25
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue