-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add chat_id_file configuration parameter for Telegram #4719
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
Conversation
8e07edb to
37a4eb7
Compare
|
|
||
| func (n *Notifier) getChatID() (int64, error) { | ||
| if len(n.conf.ChatIDFile) > 0 { | ||
| content, err := os.ReadFile(n.conf.ChatIDFile) |
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.
Do we expect the contents to change as we go? Would we consider saving the chatID to n.conf.ChatID after we read it, and then in this function return that one first, and only read the file if ChatID is still 0?
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've added the caching you suggested - getChatID() now returns the cached value first and only reads from file if ChatID is still 0, then caches it for future calls. This avoids the file I/O on every notification
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 think you removed this improvement when you removed the unrelated changes from the branch... You could cherry-pick just this one patch on top, or push to a version that has just those.
08960ca to
ff16850
Compare
ultrotter
left a comment
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.
Please can you remove the unrelated changes from this branch? Otherwise I don't think it can be merged, as is...
Thanks!
G
This adds support for reading chat_id from a file, similar to bot_token_file. This allows users to securely pass chat_id using secrets or volumes in docker-compose without exposing it in cleartext in the config file. Fixes prometheus#4672 Signed-off-by: tennisleng <tennisleng@users.noreply.github.com>
7585500 to
29885e2
Compare
|
If chat_id is considered a secret it also get mapped to a secret type. Right now it is mapeed to int and is visible unmasked in |
|
related #2498 |
This PR adds support for reading
chat_idfrom a file, similar tobot_token_file. This allows users to securely passchat_idusing secrets or volumes in docker-compose without exposing it in cleartext in the config file.Changes
ChatIDFilefield toTelegramConfigstructchat_idorchat_id_file(but not both)getChatID()method to read chat_id from fileNotify()method to use the newgetChatID()methodTesting
bot_token_filechat_idorchat_id_fileis providedFixes #4672