Commit d6cd9ccf authored by John Jarvis's avatar John Jarvis

Merge branch 'jarv/set-tokens-env' into 'master'

Set tokens via the env

See merge request !26
parents a9af1bd6 deaf8cce
Pipeline #42472331 (#64) passed with stage
in 1 minute and 6 seconds
......@@ -91,6 +91,33 @@ func ReadConfig(f string, d bool) (*Config, error) {
if err != nil {
return nil, errors.New(err.Error())
}
if cfg.Projects.Infrastructure.ID == 0 {
return nil, errors.New("ERROR: It looks like you have an old settings file, please update using oncall-settings-example.yaml")
}
if cfg.Projects.Production.ID == 0 {
return nil, errors.New("ERROR: It looks like you have an old settings file, you are missing the production project ID. please update using oncall-settings-example.yaml")
}
if cfg.APITokens.GitLab == "" {
cfg.APITokens.GitLab = os.Getenv("GITLAB_API_TOKEN")
}
if cfg.APITokens.Grafana == "" {
cfg.APITokens.Grafana = os.Getenv("GRAFANA_API_TOKEN")
}
if cfg.APITokens.PagerDuty == "" {
cfg.APITokens.PagerDuty = os.Getenv("PAGER_DUTY_TOKEN")
}
if cfg.APITokens.GitLab == "" || cfg.APITokens.Grafana == "" || cfg.APITokens.PagerDuty == "" {
return nil, errors.New("ERROR: Please configure api tokens")
}
cfg.Debug = d
return &cfg, nil
}
func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}
......@@ -41,8 +41,8 @@ func TestParseConfigCorrectly(t *testing.T) {
if err != nil {
t.Fatalf("failed to parse the configuration: %s", err)
}
assertEquals(t, "gitlab token", "*** GITLAB API TOKEN GOES HERE ***", c.APITokens.GitLab)
assertEquals(t, "pagerduty token", "*** PD API TOKEN GOES HERE ***", c.APITokens.PagerDuty)
assertEquals(t, "gitlab token", "", c.APITokens.GitLab)
assertEquals(t, "pagerduty token", "", c.APITokens.PagerDuty)
}
func assertEquals(t *testing.T, name string, expected, actual interface{}) {
......
......@@ -36,14 +36,6 @@ func main() {
if err != nil {
log.Fatalln(err)
}
if config.Projects.Infrastructure.ID == 0 {
log.Fatalln("ERROR: It looks like you have an old settings file, please update using oncall-settings-example.yaml")
}
if config.Projects.Production.ID == 0 {
log.Fatalln("ERROR: It looks like you have an old settings file, you are missing the production project ID. please update using oncall-settings-example.yaml")
}
opts := oncall.ReportOptions{}
report := oncall.NewReport(config, opts)
title := "OnCall report for period: " +
......
......@@ -2,12 +2,12 @@
# and update api_tokens below
api_tokens:
gitlab: "*** GITLAB API TOKEN GOES HERE ***"
gitlab_dev: "*** GITLAB DEV API TOKEN GOES HERE ***"
gitlab: # GITLAB API TOKEN GOES HERE or set $GITLAB_API_TOKEN
gitlab_dev: # *** GITLAB DEV API TOKEN GOES HERE or set $GITLAB_DEV_API_TOKEN
# 1Password "oncall-robot grafana api key"
grafana: "*** GRAFANA API KEY GOES HERE ***"
grafana: # *** GRAFANA API KEY GOES HERE ***" or set $GRAFANA_API_KEY
# 1Password "oncall-robot pager duty api key"
pager_duty: "*** PD API TOKEN GOES HERE ***"
pager_duty: # *** PD API TOKEN GOES HERE ***" or set $PAGER_DUTY_TOKEN
# Projects
projects:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment