terraform-aws-clickops-notifier
terraform-aws-clickops-notifier copied to clipboard
Use slack token as alternative to webhook
Background
A slack token is the new method of authentication
It allows multiple slack channels and specific scopes.
How
Here's how to hit the API using the token instead of the webhook
https://api.slack.com/tutorials/tracks/posting-messages-with-curl
# test auth
auth_test = requests.post(
'https://slack.com/api/auth.test',
headers=({'Authorization': f'Bearer {self.slack_token}'})
).json()
# send message
requests.post(
'https://slack.com/api/chat.postMessage',
headers=({'Authorization': f'Bearer {self.slack_token}'}),
json=payload
)
Code references
https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/app.py#L57-L64
https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/messenger.py#L10-L15
https://github.com/cloudandthings/terraform-aws-clickops-notifier/blob/be9694cda07dbe74fad9e332723be3b38bb5267b/clickopsnotifier/messenger.py#L63
Related to #76