Rm unused slack callback, refactor spam() to slack_post()
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Follow-up to d554fae7cd
This commit is contained in:
parent
13ced6105d
commit
f817fde37e
@ -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
|
||||
|
@ -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:
|
||||
|
@ -93,16 +93,17 @@ 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 = {
|
||||
"doorboy": const.SLACK_DOORLOG_CALLBACK,
|
||||
"inventory": const.SLACK_INVENTORY_CALLBACK
|
||||
}
|
||||
url = urls.get(channel, const.SLACK_DOORLOG_CALLBACK)
|
||||
requests.post(url, json={"text": msg })
|
||||
return
|
||||
|
||||
channels = {
|
||||
"doorboy": 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={}):
|
||||
selectors = []
|
||||
|
@ -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"]
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user