Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading VictorOps API key from file #3111

Merged
merged 8 commits into from Oct 25, 2022

Conversation

OktarianTB
Copy link
Contributor

Related to issue #2498. Basically a copy of #2728.

#2554 can be closed as a result.

Signed-off-by: Oktarian Tilney-Bassett 馃槃

Oktarian Tilney-Bassett added 6 commits October 20, 2022 17:23
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>
Copy link
Member

@simonpasquier simonpasquier left a 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...

docs/configuration.md Show resolved Hide resolved
docs/configuration.md Outdated Show resolved Hide resolved
if n.conf.APIKey != "" {
apiKey = string(n.conf.APIKey)
} else {
content, fileErr := os.ReadFile(n.conf.APIKeyFile)
Copy link
Member

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 :)

Suggested change
content, fileErr := os.ReadFile(n.conf.APIKeyFile)
content, err := os.ReadFile(n.conf.APIKeyFile)

Copy link
Contributor Author

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: 馃檪

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()
)

Copy link
Member

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 tmplErrvariable 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 :)

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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? 馃弫

Oktarian T-B and others added 2 commits October 22, 2022 10:28
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>
@simonpasquier simonpasquier merged commit dd7214e into prometheus:main Oct 25, 2022
qinxx108 pushed a commit to qinxx108/alertmanager that referenced this pull request Nov 16, 2022
* 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>
qinxx108 pushed a commit to qinxx108/alertmanager that referenced this pull request Dec 13, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants