Skip to content

Commit

Permalink
do not overwrite environment if one was provided via URL
Browse files Browse the repository at this point in the history
  • Loading branch information
sagor999 committed Feb 9, 2021
1 parent 97f10e2 commit c077ce8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'

vars:
NAME: alertmanager-sentry-gateway
VERSION: 0.5.3
VERSION: 0.5.4
COMMIT: {sh: git rev-parse --verify HEAD}
BUILD_FLAGS: -ldflags "-X main.VERSION={{.VERSION}} -X main.COMMIT={{.COMMIT}}"

Expand Down
6 changes: 5 additions & 1 deletion sentry-gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func run(cmd *cobra.Command, args []string) error {
dsn := defaultDSN
env := defaultEnv

foundEnvInURL := false

if sentry, err := url.Parse(sentryURL); sentryURL != "" && err == nil {
if token, _, ok := r.BasicAuth(); ok && r.URL.Path != "/" {
params := strings.Split(r.URL.Path, "/")
Expand All @@ -209,6 +211,7 @@ func run(cmd *cobra.Command, args []string) error {
} else if len(params) == 3 {
dsn = fmt.Sprintf("%s://%s@%s/%s", sentry.Scheme, token, sentry.Host, params[1])
env = params[2]
foundEnvInURL = true
log.Debugf("dsn: %s, url: %s, env: %s", dsn, r.URL.Path, env)
} else {
log.Errorf("Unknown number of params in url string: %s, params: %v, len: %d", r.URL.Path, params, len(params))
Expand All @@ -228,7 +231,8 @@ func run(cmd *cobra.Command, args []string) error {

for _, alert := range wh.Alerts {
alert_env := env
if envLabel != "" {
// extract environmnent from label only if URL did not set one already, otherwise it takes precedence
if envLabel != "" && !foundEnvInURL {
e := getSentryEnvironmentFromAlert(alert, envLabel)
if e != "" {
alert_env = e
Expand Down

0 comments on commit c077ce8

Please sign in to comment.