Commit 1ac0b172 authored by John Jarvis's avatar John Jarvis

Set tokens via the env

parent a9af1bd6
Pipeline #42471251 failed with stage
in 1 minute and 9 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
}
......@@ -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_TOKEN
# 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