Skip to content

Commit cca854f

Browse files
committed
WIP broken Quart/Slack implementation
1 parent 2b34567 commit cca854f

File tree

6 files changed

+128
-3
lines changed

6 files changed

+128
-3
lines changed

docs/source/configuration.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Configuration
44
=============
55

6-
TBD.
6+
Configuration of the machine-access-control (MAC) server is accomplished by some JSON configuration files and optional environment variables, as detailed below.
77

88
.. _configuration.users-json:
99

@@ -27,6 +27,36 @@ The schema of this file is as follows:
2727

2828
.. jsonschema:: dm_mac.models.machine.CONFIG_SCHEMA
2929

30+
.. _configuration.env-vars:
31+
32+
Environment Variables
33+
---------------------
34+
35+
.. list-table:: Environment Variables
36+
:header-rows: 1
37+
38+
* - Variable
39+
- Required?
40+
- Description
41+
* - ``USERS_CONFIG``
42+
- no
43+
- path to users configuration file; default ``./users.json``
44+
* - ``MACHINES_CONFIG``
45+
- no
46+
- path to machines configuration file; default ``./machines.json``
47+
* - ``MACHINE_STATE_DIR``
48+
- no
49+
- path to machine state directory; default ``./machine_state``
50+
* - ``SLACK_BOT_TOKEN``
51+
- no
52+
- If using the Slack integration, the Bot User OAuth Token for your installation of the app.
53+
* - ``SLACK_APP_TOKEN``
54+
- no
55+
- If using the Slack integration, the Socket OAuth Token for your installation of the app.
56+
* - ``SLACK_SIGNING_SECRET``
57+
- no
58+
- If using the Slack integration, the Signing Secret for your installation of the app.
59+
3060
.. _configuration.machine-state-dir:
3161

3262
Machine State Directory

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Introduction <introduction>
1111
Installation <installation>
1212
Configuration <configuration>
13+
Slack Integration <slack>
1314
Hardware <hardware>
1415
Administration <admin>
1516
Contributing and Development <contributing>

docs/source/slack.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _slack:
2+
3+
Slack Integration
4+
=================
5+
6+
machine-access-control (MAC) offers a Slack integration for logging and control.
7+
8+
.. _slack.setup:
9+
10+
Setup
11+
-----
12+
13+
To set up the Slack integration:
14+
15+
1. `Create a new Slack app <https://api.slack.com/apps?new_app=1&track=hello-world-bolt>`_
16+
17+
1. Create your new app "from scratch".
18+
2. Set a meaningful name, such as ``machine-access-control`` and create the app in your Workspace.
19+
3. In the left menu, navigate to ``OAuth & Permissions``.
20+
4. In the "Scopes" pane, under "Bot Token Scopes", click "Add an OAuth Scope" and add scopes for ``app_mentions:read``, ``canvases:read``, ``canvases:write``, ``channels:read``, ``chat:write``, ``groups:read``, ``groups:write``, ``incoming-webhook``, ``users.profile:read``, and ``users:read``.
21+
22+
2. In your workspace, create a new private channel for admins to interact with MAC in, and MAC to post status updates to.
23+
3. In the left menu, navigate to ``Install App``. Click on the button to install to your workspace. When prompted for a channel for the app to post in, select the private channel that you created in the previous step.
24+
4. On the next screen, ``Installed App Settings``, copy the ``Bot User OAuth Token`` and set this as the ``SLACK_BOT_TOKEN`` environment variable for the MAC server.
25+
5. Go back to the main settings for your app and navigate to ``Socket Mode`` under ``Settings`` on the left menu; toggle on ``Enable Socket Mode``. For ``Token Name``, enter ``socket-mode-token`` and click ``Generate``. Copy the generated token and set it as the ``SLACK_APP_TOKEN`` environment variable for the MAC server **TBD is this needed? document on config page.**
26+
6. Go back to the main settings for your app and navigate to ``Basic Information`` under ``Settings`` on the left menu; in the ``App Credentials`` pane click ``Show`` in the ``Signing Secret`` box and then copy that value; set it as the ``SLACK_SIGNING_SECRET`` environment variable for the MAC server.
27+
28+
.. _slack.configuration:
29+
30+
Configuration
31+
-------------
32+
33+
TBD.
34+
35+
.. _slack.usage:
36+
37+
Usage
38+
-----
39+
40+
TBD.

poetry.lock

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ filelock = "^3.15.4"
3030
prometheus-client = "^0.20.0"
3131
quart = "^0.19.8"
3232
asyncio = "^3.4.3"
33+
slack-bolt = "^1.21.2"
3334

3435
[tool.poetry.group.dev.dependencies]
3536
Pygments = ">=2.10.0"

src/dm_mac/slack_app.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Slack app."""
2+
3+
import os
4+
from slack_bolt import App
5+
from slack_bolt.adapter.quart import AsyncQuartReceiver
6+
from quart import Quart
7+
import logging
8+
9+
logger: logging.Logger = logging.getLogger(__name__)
10+
11+
12+
class SlackApp:
13+
"""MAC Slack App."""
14+
15+
def __init__(self, app: Quart) -> None:
16+
receiver: AsyncQuartReceiver = AsyncQuartReceiver(app)
17+
self.app: App = App(
18+
token=os.environ("SLACK_APP_TOKEN"),
19+
signing_secret=os.environ("SLACK_SIGNING_SECRET"),
20+
receiver=receiver
21+
)
22+
23+
@self.app.event("app_mention")
24+
async def handle_app_mention(self, event, say):
25+
logging.info("app mention event=%s say=%s", event, say)

0 commit comments

Comments
 (0)