forked from raystack/siren
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support slack channel passed as config in notification API (#86)
* feat: Support slack channel passed as config in notification API * fix: use any instead of using interface{} for RecieverSelectors * fix: refacotor method name error handling * fix: simplify code * fix: post notification override --------- Co-authored-by: Muhammad Abduh <mabdh@users.noreply.github.com>
- Loading branch information
1 parent
e8b3da4
commit cb051b1
Showing
13 changed files
with
458 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package notification | ||
|
||
import ( | ||
"github.com/goto/siren/pkg/errors" | ||
) | ||
|
||
type ReceiverSelectors []map[string]any | ||
|
||
func (rs ReceiverSelectors) parseAndValidate() ([]map[string]string, map[string]any, error) { | ||
// Check if any selector contains a config | ||
var selectorConfig map[string]any | ||
for i := 0; i < len(rs); i++ { | ||
selector := rs[i] | ||
if v, cok := selector["config"]; cok { | ||
if m, ok := v.(map[string]any); ok { | ||
selectorConfig = m | ||
delete(rs[i], "config") | ||
} else { | ||
return nil, nil, errors.ErrInvalid.WithMsgf("config should be in map and follow notification config") | ||
} | ||
break | ||
} | ||
} | ||
|
||
if selectorConfig != nil && len(rs) > 1 { | ||
return nil, nil, errors.ErrInvalid.WithMsgf("config override could only be used with one selector") | ||
} | ||
|
||
castedSelectors := make([]map[string]string, len(rs)) | ||
for i, selector := range rs { | ||
castedSelectors[i] = make(map[string]string) | ||
for k, v := range selector { | ||
if str, ok := v.(string); ok { | ||
castedSelectors[i][k] = str | ||
} else { | ||
return nil, nil, errors.ErrInvalid.WithMsgf("receiver selector value of '%s' should be a string", k) | ||
} | ||
} | ||
} | ||
|
||
return castedSelectors, selectorConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.