Remove the `bot_token`
Signed-off-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
parent
02660ba09e
commit
572de996b7
|
@ -180,9 +180,8 @@ type WebexConfig struct {
|
|||
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
||||
APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
||||
|
||||
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
||||
RoomID string `yaml:"room_id" json:"room_id"`
|
||||
BotToken Secret `yaml:"bot_token" json:"bot_token"`
|
||||
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
||||
RoomID string `yaml:"room_id" json:"room_id"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||
|
@ -197,10 +196,8 @@ func (c *WebexConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
return fmt.Errorf("missing room_id on webex_config")
|
||||
}
|
||||
|
||||
if c.BotToken == "" {
|
||||
if c.HTTPConfig == nil || c.HTTPConfig.Authorization == nil {
|
||||
return fmt.Errorf("missing one of webex_configs.http_config.authorization or bot_token")
|
||||
}
|
||||
if c.HTTPConfig == nil || c.HTTPConfig.Authorization == nil {
|
||||
return fmt.Errorf("missing webex_configs.http_config.authorization")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -877,15 +877,17 @@ func TestWebexConfiguration(t *testing.T) {
|
|||
{
|
||||
name: "with no room_id - it fails",
|
||||
in: `
|
||||
bot_token: xyz123
|
||||
message: xyz123
|
||||
`,
|
||||
expected: errors.New("missing room_id on webex_config"),
|
||||
},
|
||||
{
|
||||
name: "with room_id and bot_token present - it succeeds",
|
||||
name: "with room_id and http_config.authorization set - it succeeds",
|
||||
in: `
|
||||
room_id: 2
|
||||
bot_token: xyz123
|
||||
http_config:
|
||||
authorization:
|
||||
credentials: "xxxyyyzz"
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1124,15 +1124,12 @@ API](http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages).
|
|||
# If not specified, default API URL will be used.
|
||||
[ api_url: <string> | default = global.webex_api_url ]
|
||||
|
||||
# Webex bot token
|
||||
[ bot_token: <string> ]
|
||||
|
||||
# ID of the Webex Teams room where to send the messages.
|
||||
[ room_id: <string> ]
|
||||
|
||||
# Message template
|
||||
[ message: <tmpl_string> default = '{{ template "webex.default.message" .}}' ]
|
||||
|
||||
# The HTTP client's configuration. As an alternative, You can use this configuration to supply the bot token as part of the HTTP `Authorization` header.
|
||||
# The HTTP client's configuration. You must use this configuration to supply the bot token as part of the HTTP `Authorization` header.
|
||||
[ http_config: <http_config> | default = global.http_config ]
|
||||
```
|
||||
|
|
|
@ -45,13 +45,6 @@ type Notifier struct {
|
|||
|
||||
// New returns a new Webex notifier.
|
||||
func New(c *config.WebexConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
|
||||
if c.HTTPConfig.Authorization == nil && c.HTTPConfig.BearerToken == "" {
|
||||
c.HTTPConfig.Authorization = &commoncfg.Authorization{
|
||||
Type: "Bearer",
|
||||
Credentials: commoncfg.Secret(c.BotToken),
|
||||
}
|
||||
}
|
||||
|
||||
client, err := commoncfg.NewClientFromConfig(*c.HTTPConfig, "webex", httpOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -67,17 +67,6 @@ func TestWebexTemplating(t *testing.T) {
|
|||
errMsg string
|
||||
expHeader string
|
||||
}{
|
||||
{
|
||||
name: "with a valid message and a set bot_token, it is formatted as expected",
|
||||
cfg: &config.WebexConfig{
|
||||
Message: `{{ template "webex.default.message" . }}`,
|
||||
},
|
||||
commonCfg: &commoncfg.HTTPClientConfig{},
|
||||
|
||||
expJSON: `{"markdown":"\n\nAlerts Firing:\nLabels:\n - lbl1 = val1\n - lbl3 = val3\nAnnotations:\nSource: \nLabels:\n - lbl1 = val1\n - lbl2 = val2\nAnnotations:\nSource: \n\n\n\n"}`,
|
||||
retry: false,
|
||||
expHeader: "Bearer xxxyyyzz",
|
||||
},
|
||||
{
|
||||
name: "with a valid message and a set http_config.authorization, it is formatted as expected",
|
||||
cfg: &config.WebexConfig{
|
||||
|
@ -115,7 +104,6 @@ func TestWebexTemplating(t *testing.T) {
|
|||
u, _ := url.Parse(srv.URL)
|
||||
|
||||
tt.cfg.APIURL = &config.URL{URL: u}
|
||||
tt.cfg.BotToken = "xxxyyyzz"
|
||||
tt.cfg.HTTPConfig = tt.commonCfg
|
||||
notifierWebex, err := New(tt.cfg, test.CreateTmpl(t), log.NewNopLogger())
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in New Issue