From 572de996b70bc03634820057c89fabad5972e63d Mon Sep 17 00:00:00 2001 From: gotjosh Date: Thu, 15 Dec 2022 11:48:01 -0400 Subject: [PATCH] Remove the `bot_token` Signed-off-by: gotjosh --- config/notifiers.go | 11 ++++------- config/notifiers_test.go | 8 +++++--- docs/configuration.md | 5 +---- notify/webex/webex.go | 7 ------- notify/webex/webex_test.go | 12 ------------ 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/config/notifiers.go b/config/notifiers.go index 00612f15..d67a7236 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -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 diff --git a/config/notifiers_test.go b/config/notifiers_test.go index fb10de4f..a58f8d95 100644 --- a/config/notifiers_test.go +++ b/config/notifiers_test.go @@ -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" `, }, } diff --git a/docs/configuration.md b/docs/configuration.md index 6ed1ead8..0f6ded9c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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: | default = global.webex_api_url ] -# Webex bot token -[ bot_token: ] - # ID of the Webex Teams room where to send the messages. [ room_id: ] # Message template [ message: 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: | default = global.http_config ] ``` diff --git a/notify/webex/webex.go b/notify/webex/webex.go index cd94adc4..d3e6ad63 100644 --- a/notify/webex/webex.go +++ b/notify/webex/webex.go @@ -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 diff --git a/notify/webex/webex_test.go b/notify/webex/webex_test.go index bf85e32d..161751fb 100644 --- a/notify/webex/webex_test.go +++ b/notify/webex/webex_test.go @@ -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)