Skip to main content

Library for managing and deploying a lightweight approval workflow based on Slack and GCP

Project description

slack_approval

PyPI PyPI - Python Version

This python library serves as the basis for managing and deploying a lightweight approval workflow based on Slack and GCP. This library contains two key classes, SlackRequest and SlackProvision as well as the logic to deploy them to GCP, which is based on goblet.

Install library with pip install slack_approval

Slack Approval Flow


approval_flow

The user iniates a request to the reqest function. This function uses the SlackRequest class to then post a message into a private Slack channel with the option to approve or reject the request.

Sample message in the approvers channel.

sample_message

If approved by a member of the private channel, the message is then sent to the provision function, which executes logic based on the request. There is a second Slack channel for requesters to view the status of their request.

Onboarding New Requests for Approval


Provision

  • First add a provision file for your new request provision_{request name}.py
  • In the file, extend the from slack_approval.slack_provision import SlackProvision class and define your own approved() and optionally a rejected() method. By default, rejections log the event in the function and updates the messages in Slack. You only need to define it if other actions are necessary.
  • Import your new class in provision.py. This should be the only thing you need to change anything else in the base files

Request

  • The only requirement for the events sent to the request function is the provision_class field. This is what maps the event to the right class in the provision function. You can add any other fields here and they will show up in the request in Slack.
    • The value for provision_class should be the name of your provision class with spaces

      ie. class ProvisionLBEndpoint -> "provision_class": "Provision LB Endpoint"

  • Optionally, you can add approvers_channel and requesters_channel fields in your request to specify the approvers and requesters channels respectively.
    • If added, add environment variables with the same values.
    • If not provided, the function will look for APPROVERS_CHANNEL and REQUESTERS_CHANNEL environment variables by default.

Example:

curl -X POST -H "Content-Type:application/json" https://REGION-PROJECT.cloudfunctions.net/slack-request -d '{
	"provision_class": "Provision Service",
    "approvers_channel": "APPROVERS_CHANNEL",
    "requesters_channel": "REQUESTERS_CHANNEL",
	"field1": "value1",
	"field2": "value2",
}'
  • The entire data json is available to the provision classes as self.inputs

Deploying Functions


The functions that need to be deployed are found in the /functions folder or can be created by the slack_approval init command.

See the blog post Tutorial: Setting Up Approval Processes with Slack Apps for more detailed slack and GCP setup steps.

Before deploying you will need to modify the config.json file found in the .goblet folder with the required environment variables.

Request

  • APPROVERS_CHANNEL
  • REQUESTERS_CHANNEL
  • SLACK_BOT_TOKEN

Provision

  • SLACK_BOT_TOKEN

To deploy the functions all you need to do is run the following two commands.

  • goblet deploy --stage request

  • goblet deploy --stage provision

Blog post


See the blog post Tutorial: Setting Up Approval Processes with Slack Apps for more detailed slack and GCP setup steps.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slack_approval-0.1.5.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

slack_approval-0.1.5.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file slack_approval-0.1.5.1.tar.gz.

File metadata

  • Download URL: slack_approval-0.1.5.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for slack_approval-0.1.5.1.tar.gz
Algorithm Hash digest
SHA256 30e2edb12a77c2fc1e1d3272f3ce6899e71cb04a118f128bad5b282d551a4a18
MD5 9a0ec0a8f725262bd23fd986cbbf8bc5
BLAKE2b-256 f86e6c8f753b874769b205fb3cf6f5f2af3f183332031482623c2d9be19044c5

See more details on using hashes here.

File details

Details for the file slack_approval-0.1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for slack_approval-0.1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6b1d85da8b1c9355bd3586a258f3992141d847259babc49bc3486fad4d053c6
MD5 f72706b83d8f0494693a3b2d3b9fc764
BLAKE2b-256 fbde6714d8d263bf3681e5ee705c9855c4ce55e8ccfa2028b32784ea9bd191e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page