-
-
Notifications
You must be signed in to change notification settings - Fork 629
feat(alerting): Add support for Threema Gateway as an alerting provider (basic mode) #1468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(alerting): Add support for Threema Gateway as an alerting provider (basic mode) #1468
Conversation
5004226 to
c2d9183
Compare
| type RecipientType int // TODO#1464: Maybe move to separate file in package to keep things organized | ||
|
|
||
| const ( | ||
| RecipientTypeInvalid RecipientType = iota | ||
| RecipientTypeId | ||
| RecipientTypePhone | ||
| RecipientTypeEmail | ||
| ) | ||
|
|
||
| func parseRecipientType(s string) RecipientType { | ||
| if val, ok := validRecipientTypes[s]; ok { | ||
| return val | ||
| } | ||
| return RecipientTypeInvalid | ||
| } | ||
|
|
||
| type Recipient struct { | ||
| Value string `yaml:"-"` | ||
| Type RecipientType `yaml:"-"` | ||
| } | ||
|
|
||
| var _ encoding.TextUnmarshaler = (*Recipient)(nil) | ||
| var _ encoding.TextMarshaler = (*Recipient)(nil) | ||
|
|
||
| func (r *Recipient) UnmarshalText(text []byte) error { | ||
| parts := strings.Split(string(text), ":") | ||
| switch { | ||
| case len(parts) > 2: | ||
| return ErrInvalidRecipientFormat | ||
| case len(parts) == 2: | ||
| if r.Type = parseRecipientType(parts[0]); r.Type == RecipientTypeInvalid { | ||
| return ErrInvalidRecipientType | ||
| } | ||
| r.Value = parts[1] | ||
| default: | ||
| r.Type = defaultRecipientType | ||
| r.Value = parts[0] | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (r Recipient) MarshalText() ([]byte, error) { | ||
| return []byte(r.Value), nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not seen a solution to preprocess/parse string values from the yaml config like this anywhere else in the repo. This new provider was a good playground to test it out.
I think applied to the condition system it could improve code quality (and maybe performance, I have not enough experience with go to know how much) significantly, because then parsing of the condition and runtime evaluation would be completely separated.
@TwiN What do you think about my approach?
c2d9183 to
40dea85
Compare
40dea85 to
acafd93
Compare
91dadb9 to
fbef1ac
Compare
|
I have requested a Gateway ID from Threema. Once I have a working Gateway I will be able to test the alert provider against their API and once the tests are successful this PR will be ready. |
5697f3c to
b36b2e3
Compare
Summary
Closes #1464
Checklist
README.md, if applicable.