-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add support for reading VictorOps API key from file #3111
Add support for reading VictorOps API key from file #3111
Conversation
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
Signed-off-by: Oktarian Tilney-Bassett <oktariantilneybassett@improbable.io>
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.
Good! Just a few nits...
if n.conf.APIKey != "" { | ||
apiKey = string(n.conf.APIKey) | ||
} else { | ||
content, fileErr := os.ReadFile(n.conf.APIKeyFile) |
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 might miss the reason why we need a new variable name but if there's none, I'd prefer to keep err
:)
content, fileErr := os.ReadFile(n.conf.APIKeyFile) | |
content, err := os.ReadFile(n.conf.APIKeyFile) |
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.
Declaring it as err
would be a shadow declaration of a previously defined err
variable used for templating errors: 🙂
alertmanager/notify/victorops/victorops.go
Lines 70 to 75 in 3f561cd
var err error | |
var ( | |
data = notify.GetTemplateData(ctx, n.tmpl, as, n.logger) | |
tmpl = notify.TmplText(n.tmpl, data, &err) | |
apiURL = n.conf.APIURL.Copy() | |
) |
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.
Hmm it shouldn't cause a direct problem as long as tmpl
isn't called in this branch but I don't mind keeping it explicit.
Other notifiers declare a tmplErr
variable to make it more obvious that the error variable shouldn't be reused for anything else but I feel that it's still a bit obfuscated (it's easy to call the templating function and forget checking the error). The general approach with a anonymous function might need to be revised but this isn't relevant to this change :)
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.
That makes sense! I agree that the templating error handling is not the best, just need to be careful I guess :)
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.
Are there any other changes needed for this PR btw? 🏁
Co-authored-by: Simon Pasquier <spasquie@redhat.com> Signed-off-by: Oktarian T-B <oktariantilneybassett@improbable.io>
Co-authored-by: Simon Pasquier <spasquie@redhat.com> Signed-off-by: Oktarian T-B <oktariantilneybassett@improbable.io>
* Read VictorOps API key from file * Update documentation * Improve tests Signed-off-by: Oktarian T-B <oktariantilneybassett@improbable.io> Signed-off-by: Yijie Qin <qinyijie@amazon.com>
* Read VictorOps API key from file * Update documentation * Improve tests Signed-off-by: Oktarian T-B <oktariantilneybassett@improbable.io> Signed-off-by: Yijie Qin <qinyijie@amazon.com>
Related to issue #2498. Basically a copy of #2728.
#2554 can be closed as a result.
Signed-off-by: Oktarian Tilney-Bassett 😄