generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/save_chat_to_incident_timeline
- Loading branch information
Showing
19 changed files
with
795 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,7 @@ def submit(ack, view, say, body, client, logger): | |
say(text=text, channel=channel_id) | ||
|
||
# Reminder to brief up | ||
text = ":alphabet-yellow-question: Is this a `cybersecurity incident` (secret/data leak, account compromise, attack)? Please initiate the briefing process for CCCS and TBS OCIO Cyber." | ||
text = ":alphabet-yellow-question: Is this a `cybersecurity incident` (secret/data leak, account compromise, attack)? Please initiate the briefing process for CCCS and TBS OCIO Cyber. This just means we send a summary of the incident (or initial findings and updates if incident is ongoing) to [email protected] and CC [email protected], and [email protected]! CCCS will reach out with a case number, and any questions if they need more information." | ||
say(text=text, channel=channel_id) | ||
|
||
# Reminder to stop planned testing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
en-US: | ||
locale_button: "Français" | ||
locale_value: "en-US" | ||
locale_short: "en" | ||
submit: "Submit" | ||
close: "Close" | ||
title: "Share a new secret" | ||
label: "Secret" | ||
placeholder: "Enter your secret here" | ||
ttl: "Time to live" | ||
days: "days" | ||
day: "day" | ||
hours: "hours" | ||
hour: "hour" | ||
minutes: "minutes" | ||
minute: "minute" | ||
error: "There was an error creating your secret" | ||
link_available: "Your secret is available at the following link:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fr-FR: | ||
locale_button: "English" | ||
locale_value: "fr-FR" | ||
locale_short: "fr" | ||
submit: "Soumettre" | ||
close: "Fermer" | ||
title: "Partager secret" | ||
label: "Secret" | ||
placeholder: "Entrez votre secret ici" | ||
ttl: "Durée de vie" | ||
days: "jours" | ||
day: "jour" | ||
hours: "heures" | ||
hour: "heure" | ||
minutes: "minutes" | ||
minute: "minute" | ||
error: "Il y avait une erreur en créant votre secret" | ||
link_available: "Votre secret est disponible au lien suivant:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import i18n | ||
import requests | ||
import time | ||
from commands.utils import get_user_locale | ||
|
||
i18n.load_path.append("./commands/locales/") | ||
|
||
i18n.set("locale", "en-US") | ||
i18n.set("fallback", "en-US") | ||
|
||
|
||
def secret_command(client, ack, command, body): | ||
ack() | ||
if "user" in body: | ||
user_id = body["user"]["id"] | ||
else: | ||
user_id = body["user_id"] | ||
locale = get_user_locale(user_id, client) | ||
i18n.set("locale", locale) | ||
view = generate_secret_command_modal_view(command, user_id, locale) | ||
client.views_open(trigger_id=body["trigger_id"], view=view) | ||
|
||
|
||
def secret_view_handler(ack, client, view, logger): | ||
ack() | ||
locale = view["blocks"][0]["elements"][0]["value"] | ||
i18n.set("locale", locale) | ||
secret = view["state"]["values"]["secret_input"]["secret_submission"]["value"] | ||
ttl = view["state"]["values"]["product"]["secret_ttl"]["selected_option"]["value"] | ||
|
||
# Encrypted message API | ||
endpoint = "https://encrypted-message.cdssandbox.xyz/encrypt" | ||
json = {"body": secret, "ttl": int(ttl) + int(time.time())} | ||
response = requests.post( | ||
endpoint, json=json, timeout=10, headers={"Content-Type": "application/json"} | ||
) | ||
|
||
try: | ||
id = response.json()["id"] | ||
url = f"https://encrypted-message.cdssandbox.xyz/{i18n.t('secret.locale_short')}/view/{id}" | ||
client.chat_postEphemeral( | ||
channel=view["private_metadata"], | ||
user=view["private_metadata"], | ||
text=f"{i18n.t('secret.link_available')} {url}", | ||
) | ||
except Exception as e: | ||
logger.error(e) | ||
client.chat_postEphemeral( | ||
channel=view["private_metadata"], | ||
user=view["private_metadata"], | ||
text=i18n.t("secret.error"), | ||
) | ||
return | ||
|
||
|
||
def handle_change_locale_button(ack, client, body): | ||
ack() | ||
if "user" in body: | ||
user_id = body["user"]["id"] | ||
else: | ||
user_id = body["user_id"] | ||
locale = body["actions"][0]["value"] | ||
if locale == "en-US": | ||
locale = "fr-FR" | ||
else: | ||
locale = "en-US" | ||
i18n.set("locale", locale) | ||
command = { | ||
"text": body["view"]["state"]["values"]["secret_input"]["secret_submission"][ | ||
"value" | ||
] | ||
} | ||
if command["text"] is None: | ||
command["text"] = "" | ||
view = generate_secret_command_modal_view(command, user_id, locale) | ||
client.views_update(view_id=body["view"]["id"], view=view) | ||
|
||
|
||
def generate_secret_command_modal_view(command, user_id, locale="en-US"): | ||
ttl_options = [ | ||
{"name": "7 " + i18n.t("secret.days"), "value": "604800"}, | ||
{"name": "3 " + i18n.t("secret.days"), "value": "259200"}, | ||
{"name": "1 " + i18n.t("secret.day"), "value": "86400"}, | ||
{"name": "12 " + i18n.t("secret.hours"), "value": "43200"}, | ||
{"name": "4 " + i18n.t("secret.hours"), "value": "14400"}, | ||
{"name": "1 " + i18n.t("secret.hour"), "value": "3600"}, | ||
{"name": "30 " + i18n.t("secret.minutes"), "value": "1800"}, | ||
{"name": "5 " + i18n.t("secret.minutes"), "value": "300"}, | ||
] | ||
|
||
options = [ | ||
{ | ||
"text": {"type": "plain_text", "text": i["name"]}, | ||
"value": i["value"], | ||
} | ||
for i in ttl_options | ||
] | ||
return { | ||
"type": "modal", | ||
"private_metadata": user_id, | ||
"callback_id": "secret_view", | ||
"title": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.title"), | ||
}, | ||
"submit": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.submit"), | ||
}, | ||
"blocks": [ | ||
{ | ||
"type": "actions", | ||
"block_id": "locale", | ||
"elements": [ | ||
{ | ||
"type": "button", | ||
"text": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.locale_button"), | ||
"emoji": True, | ||
}, | ||
"value": locale, | ||
"action_id": "secret_change_locale", | ||
} | ||
], | ||
}, | ||
{ | ||
"type": "input", | ||
"block_id": "secret_input", | ||
"label": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.label"), | ||
}, | ||
"element": { | ||
"type": "plain_text_input", | ||
"action_id": "secret_submission", | ||
"initial_value": command["text"], | ||
"placeholder": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.placeholder"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
"block_id": "product", | ||
"type": "input", | ||
"element": { | ||
"type": "static_select", | ||
"placeholder": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.ttl"), | ||
}, | ||
"options": options, | ||
"action_id": "secret_ttl", | ||
}, | ||
"label": { | ||
"type": "plain_text", | ||
"text": i18n.t("secret.ttl"), | ||
"emoji": True, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.