cloudandthings / terraform-aws-clickops-notifier

Get notified when actions are taken in the AWS Console.
https://registry.terraform.io/modules/cloudandthings/clickops-notifier/aws/latest
MIT License
207 stars 17 forks source link

Use slack token as alternative to webhook #89

Open nitrocode opened 5 months ago

nitrocode commented 5 months ago

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