Make API URL optional, clear up credential logic

Signed-off-by: Tyler Reid <tyler.reid@grafana.com>
This commit is contained in:
Tyler Reid 2021-06-21 12:29:03 -05:00
parent 4ebcaf9c23
commit 8911051770
3 changed files with 3 additions and 7 deletions

View File

@ -606,7 +606,7 @@ type SNSConfig struct {
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
APIUrl string `yaml:"api_url" json:"api_url"`
APIUrl string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
Sigv4 SigV4Config `yaml:"sigv4" json:"sigv4"`
TopicARN string `yaml:"topic_arn,omitempty" json:"topic_arn,omitempty"`
PhoneNumber string `yaml:"phone_number,omitempty" json:"phone_number,omitempty"`

View File

@ -698,7 +698,8 @@ value: <tmpl_string>
# Whether or not to notify about resolved alerts.
[ send_resolved: <boolean> | default = false ]
# The SNS API URL i.e. https://sns.us-east-2.amazonaws.com
# The SNS API URL i.e. https://sns.us-east-2.amazonaws.com.
# If not specified, the SNS API URL from the SNS SDK will be used.
[api_url: <tmpl_string>]
# Configures AWS's Signature Verification 4 signing process to sign requests.

View File

@ -79,16 +79,11 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
sess, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String(n.conf.Sigv4.Region),
Credentials: creds,
Endpoint: aws.String(tmpl(n.conf.APIUrl)),
},
Profile: n.conf.Sigv4.Profile,
})
if _, err := sess.Config.Credentials.Get(); err != nil {
return false, fmt.Errorf("could not get SigV4 credentials: %w", err)
}
if n.conf.Sigv4.RoleARN != "" {
sess.Config.Credentials = stscreds.NewCredentials(sess, n.conf.Sigv4.RoleARN)
}