Rm unused slack callback, refactor spam() to slack_post()
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Follow-up to d554fae7cd
This commit is contained in:
rasmus 2024-07-28 20:09:39 +03:00
parent 13ced6105d
commit f817fde37e
5 changed files with 16 additions and 14 deletions

View File

@ -25,8 +25,6 @@ spec:
value: "default"
- name: SLACK_DOORLOG_CALLBACK
value: "changeme"
- name: SLACK_INVENTORY_CALLBACK
value: "changeme"
- name: SLACK_VERIFICATION_TOKEN
value: "changeme"
- name: INVENTORY_API_KEY

View File

@ -110,7 +110,8 @@ def view_slack_doorboy():
status = "Permitted" if approved else "Denied"
subject = member.display_name
msg = "%s %s door access for %s via Slack bot" % (status, door, subject)
spam(msg)
slack_post(msg, "doorboy")
if approved:
return "Opening %s for %s" % (door, subject)
else:

View File

@ -93,15 +93,16 @@ def flatten(d, parent_key='', sep='.'):
items.append((new_key, v))
return dict(items)
def spam(msg, channel="doorboy"):
def slack_post(msg, channel):
if devenv:
print(f"{channel}: {msg}")
else:
urls = {
return
channels = {
"doorboy": const.SLACK_DOORLOG_CALLBACK,
"inventory": const.SLACK_INVENTORY_CALLBACK
}
url = urls.get(channel, const.SLACK_DOORLOG_CALLBACK)
url = channels.get(channel, const.SLACK_DOORLOG_CALLBACK)
requests.post(url, json={"text": msg })
def build_query(base_query, fields=[], sort_fields={}):

View File

@ -19,5 +19,4 @@ INVENTORY_ASSETS_BASE_URL = os.environ["INVENTORY_ASSETS_BASE_URL"]
MONGO_URI = os.environ["MONGO_URI"]
SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"] # used to verify (deprecated) incoming requests from slack
SLACK_DOORLOG_CALLBACK = os.environ["SLACK_DOORLOG_CALLBACK"] # used for sending logs to private channel
SLACK_INVENTORY_CALLBACK = os.environ["SLACK_INVENTORY_CALLBACK"] # used for sending logs to public channel
INVENTORY_API_KEY = os.environ["INVENTORY_API_KEY"]

View File

@ -168,10 +168,12 @@ def view_doorboy_open(door):
"member": user["name"],
"timestamp": datetime.utcnow(),
})
status = "Permitted" if approved else "Denied"
subject = user["name"]
msg = "%s %s door access for %s via https://inventory.k-space.ee/m/doorboy" % (status, door, subject)
spam(msg)
slack_post(msg, "doorboy")
if approved:
return redirect("/m/doorboy")
else:
@ -360,5 +362,6 @@ def view_swipe():
else:
subject = "Unknown"
msg = "%s %s door access for %s identified by keycard/keyfob" % (status, form["door"], subject)
spam(msg)
slack_post(msg, "doorboy")
return "ok"