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"
|
value: "default"
|
||||||
- name: SLACK_DOORLOG_CALLBACK
|
- name: SLACK_DOORLOG_CALLBACK
|
||||||
value: "changeme"
|
value: "changeme"
|
||||||
- name: SLACK_INVENTORY_CALLBACK
|
|
||||||
value: "changeme"
|
|
||||||
- name: SLACK_VERIFICATION_TOKEN
|
- name: SLACK_VERIFICATION_TOKEN
|
||||||
value: "changeme"
|
value: "changeme"
|
||||||
- name: INVENTORY_API_KEY
|
- name: INVENTORY_API_KEY
|
||||||
|
@ -110,7 +110,8 @@ def view_slack_doorboy():
|
|||||||
status = "Permitted" if approved else "Denied"
|
status = "Permitted" if approved else "Denied"
|
||||||
subject = member.display_name
|
subject = member.display_name
|
||||||
msg = "%s %s door access for %s via Slack bot" % (status, door, subject)
|
msg = "%s %s door access for %s via Slack bot" % (status, door, subject)
|
||||||
spam(msg)
|
slack_post(msg, "doorboy")
|
||||||
|
|
||||||
if approved:
|
if approved:
|
||||||
return "Opening %s for %s" % (door, subject)
|
return "Opening %s for %s" % (door, subject)
|
||||||
else:
|
else:
|
||||||
|
@ -93,15 +93,16 @@ def flatten(d, parent_key='', sep='.'):
|
|||||||
items.append((new_key, v))
|
items.append((new_key, v))
|
||||||
return dict(items)
|
return dict(items)
|
||||||
|
|
||||||
def spam(msg, channel="doorboy"):
|
def slack_post(msg, channel):
|
||||||
if devenv:
|
if devenv:
|
||||||
print(f"{channel}: {msg}")
|
print(f"{channel}: {msg}")
|
||||||
else:
|
return
|
||||||
urls = {
|
|
||||||
|
channels = {
|
||||||
"doorboy": const.SLACK_DOORLOG_CALLBACK,
|
"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 })
|
requests.post(url, json={"text": msg })
|
||||||
|
|
||||||
def build_query(base_query, fields=[], sort_fields={}):
|
def build_query(base_query, fields=[], sort_fields={}):
|
||||||
|
@ -19,5 +19,4 @@ INVENTORY_ASSETS_BASE_URL = os.environ["INVENTORY_ASSETS_BASE_URL"]
|
|||||||
MONGO_URI = os.environ["MONGO_URI"]
|
MONGO_URI = os.environ["MONGO_URI"]
|
||||||
SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"] # used to verify (deprecated) incoming requests from slack
|
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_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"]
|
INVENTORY_API_KEY = os.environ["INVENTORY_API_KEY"]
|
||||||
|
@ -168,10 +168,12 @@ def view_doorboy_open(door):
|
|||||||
"member": user["name"],
|
"member": user["name"],
|
||||||
"timestamp": datetime.utcnow(),
|
"timestamp": datetime.utcnow(),
|
||||||
})
|
})
|
||||||
|
|
||||||
status = "Permitted" if approved else "Denied"
|
status = "Permitted" if approved else "Denied"
|
||||||
subject = user["name"]
|
subject = user["name"]
|
||||||
msg = "%s %s door access for %s via https://inventory.k-space.ee/m/doorboy" % (status, door, subject)
|
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:
|
if approved:
|
||||||
return redirect("/m/doorboy")
|
return redirect("/m/doorboy")
|
||||||
else:
|
else:
|
||||||
@ -360,5 +362,6 @@ def view_swipe():
|
|||||||
else:
|
else:
|
||||||
subject = "Unknown"
|
subject = "Unknown"
|
||||||
msg = "%s %s door access for %s identified by keycard/keyfob" % (status, form["door"], subject)
|
msg = "%s %s door access for %s identified by keycard/keyfob" % (status, form["door"], subject)
|
||||||
spam(msg)
|
slack_post(msg, "doorboy")
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
|
Loading…
Reference in New Issue
Block a user