mirror of
https://github.com/crazy-max/diun.git
synced 2026-01-03 03:27:31 +01:00
Missing token as secret setting for some notifiers (#289)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -17,13 +17,15 @@ Notifications can be sent using a [Gotify](https://gotify.net/) instance.
|
||||
| Name | Default | Description |
|
||||
|--------------------|---------------|---------------|
|
||||
| `endpoint`[^1] | | Gotify base URL |
|
||||
| `token`[^1] | | Application token |
|
||||
| `token` | | Application token |
|
||||
| `tokenFile` | | Use content of secret file as application token if `token` not defined |
|
||||
| `priority` | `1` | The priority of the message |
|
||||
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
||||
|
||||
!!! abstract "Environment variables"
|
||||
* `DIUN_NOTIF_GOTIFY_ENDPOINT`
|
||||
* `DIUN_NOTIF_GOTIFY_TOKEN`
|
||||
* `DIUN_NOTIF_GOTIFY_TOKENFILE`
|
||||
* `DIUN_NOTIF_GOTIFY_PRIORITY`
|
||||
* `DIUN_NOTIF_GOTIFY_TIMEOUT`
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ Allow to send notifications to your Rocket.Chat channel.
|
||||
| `endpoint`[^1] | | Rocket.Chat base URL |
|
||||
| `channel`[^1] | | Channel name with the prefix in front of it |
|
||||
| `userID`[^1] | | User ID |
|
||||
| `token`[^1] | | Authentication token |
|
||||
| `token` | | Authentication token |
|
||||
| `tokenFile` | | Use content of secret file as authentication token if `token` not defined |
|
||||
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
||||
|
||||
!!! warning
|
||||
@@ -31,6 +32,7 @@ Allow to send notifications to your Rocket.Chat channel.
|
||||
* `DIUN_NOTIF_ROCKETCHAT_CHANNEL`
|
||||
* `DIUN_NOTIF_ROCKETCHAT_USERID`
|
||||
* `DIUN_NOTIF_ROCKETCHAT_TOKEN`
|
||||
* `DIUN_NOTIF_ROCKETCHAT_TOKENFILE`
|
||||
* `DIUN_NOTIF_ROCKETCHAT_TIMEOUT`
|
||||
|
||||
## Sample
|
||||
|
||||
@@ -21,11 +21,13 @@ Multiple chat IDs can be provided in order to deliver notifications to multiple
|
||||
|
||||
| Name | Default | Description |
|
||||
|--------------------|---------------|---------------|
|
||||
| `token`[^1] | | Telegram bot token |
|
||||
| `token` | | Telegram bot token |
|
||||
| `tokenFile` | | Use content of secret file as Telegram bot token if `token` not defined |
|
||||
| `chatIDs`[^1] | | List of chat IDs to send notifications to |
|
||||
|
||||
!!! abstract "Environment variables"
|
||||
* `DIUN_NOTIF_TELEGRAM_TOKEN`
|
||||
* `DIUN_NOTIF_TELEGRAM_TOKENFILE`
|
||||
* `DIUN_NOTIF_TELEGRAM_CHATIDS` (comma separated)
|
||||
|
||||
## Sample
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
// NotifGotify holds gotify notification configuration details
|
||||
type NotifGotify struct {
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"required"`
|
||||
Priority int `yaml:"priority,omitempty" json:"priority,omitempty" validate:"omitempty,min=0"`
|
||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"`
|
||||
TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"`
|
||||
Priority int `yaml:"priority,omitempty" json:"priority,omitempty" validate:"omitempty,min=0"`
|
||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||
}
|
||||
|
||||
// GetDefaults gets the default values
|
||||
|
||||
@@ -8,11 +8,12 @@ import (
|
||||
|
||||
// NotifRocketChat holds Rocket.Chat notification configuration details
|
||||
type NotifRocketChat struct {
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
||||
Channel string `yaml:"channel,omitempty" json:"channel,omitempty" validate:"required"`
|
||||
UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"`
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"required"`
|
||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
||||
Channel string `yaml:"channel,omitempty" json:"channel,omitempty" validate:"required"`
|
||||
UserID string `yaml:"userID,omitempty" json:"userID,omitempty" validate:"required"`
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"`
|
||||
TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"`
|
||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||
}
|
||||
|
||||
// GetDefaults gets the default values
|
||||
|
||||
@@ -2,8 +2,9 @@ package model
|
||||
|
||||
// NotifTelegram holds Telegram notification configuration details
|
||||
type NotifTelegram struct {
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"required"`
|
||||
ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"required"`
|
||||
Token string `yaml:"token,omitempty" json:"token,omitempty" validate:"omitempty"`
|
||||
TokenFile string `yaml:"tokenFile,omitempty" json:"tokenFile,omitempty" validate:"omitempty,file"`
|
||||
ChatIDs []int64 `yaml:"chatIDs,omitempty" json:"chatIDs,omitempty" validate:"required"`
|
||||
}
|
||||
|
||||
// GetDefaults gets the default values
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/internal/msg"
|
||||
"github.com/crazy-max/diun/v4/internal/notif/notifier"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Client represents an active gotify notification object
|
||||
@@ -38,6 +40,11 @@ func (c *Client) Name() string {
|
||||
|
||||
// Send creates and sends a gotify notification with an entry
|
||||
func (c *Client) Send(entry model.NotifEntry) error {
|
||||
token, err := utl.GetSecret(c.cfg.Token, c.cfg.TokenFile)
|
||||
if err != nil {
|
||||
return errors.New("Cannot retrieve token secret for Gotify notifier")
|
||||
}
|
||||
|
||||
hc := http.Client{
|
||||
Timeout: *c.cfg.Timeout,
|
||||
}
|
||||
@@ -81,7 +88,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||
u.Path = path.Join(u.Path, "message")
|
||||
|
||||
q := u.Query()
|
||||
q.Set("token", c.cfg.Token)
|
||||
q.Set("token", token)
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(body))
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/internal/msg"
|
||||
"github.com/crazy-max/diun/v4/internal/notif/notifier"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Client represents an active rocketchat notification object
|
||||
@@ -42,6 +44,11 @@ func (c *Client) Name() string {
|
||||
// Send creates and sends a rocketchat notification with an entry
|
||||
// https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/
|
||||
func (c *Client) Send(entry model.NotifEntry) error {
|
||||
token, err := utl.GetSecret(c.cfg.Token, c.cfg.TokenFile)
|
||||
if err != nil {
|
||||
return errors.New("Cannot retrieve token secret for RocketChat notifier")
|
||||
}
|
||||
|
||||
hc := http.Client{
|
||||
Timeout: *c.cfg.Timeout,
|
||||
}
|
||||
@@ -125,7 +132,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("User-Agent", c.meta.UserAgent)
|
||||
req.Header.Add("X-User-Id", c.cfg.UserID)
|
||||
req.Header.Add("X-Auth-Token", c.cfg.Token)
|
||||
req.Header.Add("X-Auth-Token", token)
|
||||
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,9 @@ import (
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/internal/msg"
|
||||
"github.com/crazy-max/diun/v4/internal/notif/notifier"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Client represents an active Telegram notification object
|
||||
@@ -38,7 +40,12 @@ func (c *Client) Name() string {
|
||||
|
||||
// Send creates and sends a Telegram notification with an entry
|
||||
func (c *Client) Send(entry model.NotifEntry) error {
|
||||
bot, err := tgbotapi.NewBotAPI(c.cfg.Token)
|
||||
token, err := utl.GetSecret(c.cfg.Token, c.cfg.TokenFile)
|
||||
if err != nil {
|
||||
return errors.New("Cannot retrieve token secret for Telegram notifier")
|
||||
}
|
||||
|
||||
bot, err := tgbotapi.NewBotAPI(token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user