Skip to content

Commit

Permalink
update libraries and fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
paliwalvimal committed Apr 2, 2024
1 parent d3a7bad commit 175327f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 44 deletions.
43 changes: 14 additions & 29 deletions src/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,57 +170,46 @@ def send_email(
Thanks,\n
Your Security Team"""

mail_body_html = (
"""
mail_body_html = f"""
<!DOCTYPE html>
<html style="font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
box-sizing: border-box; font-size: 14px; margin: 0;">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<title>%s</title>
<title>{mail_subject}</title>
<style type="text/css">
body {{
body {{{{
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: none;
width: 100% !important;
height: 100%;
line-height: 1.6em;
}}
}}}}
</style>
</head>
<body>
<p>Hey &#x1F44B; %s,</p>
<p>Hey &#x1F44B; {user_name},</p>
<p>A new access key pair has been generated for you.
Please update the same wherever necessary.</p>
<p>
Account: <b>%s (%s)</b>
Account: <b>{account_id} ({account_name})</b>
<br/>
Access Key: <b>%s</b>
Access Key: <b>{access_key}</b>
<br/>
Secret Access Key: <b>%s</b>
Secret Access Key: <b>{secret_key}</b>
<br/>
Instruction: <b>%s</b>
Instruction: <b>{instruction}</b>
</p>
<p><b>Note:</b> Existing key pair <b>%s</b> will be deleted after
<b>%s</b> days so please update the key pair wherever required.</p>
<p><b>Note:</b> Existing key pair <b>{existing_access_key}</b> will be deleted after
<b>{existing_key_delete_age}</b> days so please update the key pair wherever required.</p>
<p>
Thanks,<br/>
Your Security Team
</p>
</body>
</html>""",
mail_subject,
user_name,
account_id,
account_name,
access_key,
secret_key,
instruction,
existing_access_key,
existing_key_delete_age,
)
</html>"""

logger.info("Using %s as mail client", MAIL_CLIENT)

Expand Down Expand Up @@ -259,7 +248,7 @@ def send_email(
)
else:
logger.error(
"%s: Invalid mail client. Supported mail clients: AWS SES and Mailgun",
"%s: Invalid mail client",
MAIL_CLIENT,
)
except (Exception, ClientError) as ce:
Expand Down Expand Up @@ -344,11 +333,7 @@ def create_user_key(user_name, user):
resp["AccessKey"]["AccessKeyId"],
resp["AccessKey"]["SecretAccessKey"],
)
user_instruction = (
"The above key pair is encrypted so you need to decrypt it using the encryption key stored in SSM parameter /ikr/secret/iam/%s before using the key pair. You can use the *decryption.py* file present in the *skildops/aws-iam-key-rotator* repo. %s",
user_name,
user["attributes"]["instruction"],
)
user_instruction = f'{user["attributes"]["instruction"]} (The above key pair is encrypted so you need to decrypt it using the encryption key stored in SSM parameter /ikr/secret/iam/{user_name} before using the key pair. You can use the *decryption.py* file present in the *skildops/aws-iam-key-rotator* repo)'
else:
user_access_key = resp["AccessKey"]["AccessKeyId"]
user_secret_access_key = resp["AccessKey"]["SecretAccessKey"]
Expand Down
23 changes: 8 additions & 15 deletions src/destructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,39 @@ def send_email(email, user_name, existing_access_key):
Thanks,\n
Your Security Team"""

mail_body_html = (
"""
mail_body_html = f"""
<!DOCTYPE html>
<html style="font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
box-sizing: border-box; font-size: 14px; margin: 0;">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<title>%s</title>
<title>{mail_subject}</title>
<style type="text/css">
body {{
body {{{{
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: none;
width: 100% !important;
height: 100%;
line-height: 1.6em;
}}
}}}}
</style>
</head>
<body>
<p>Hey &#x1F44B; %s,</p>
<p>Hey &#x1F44B; {user_name},</p>
<p>An existing access key pair associated to your
username has been deleted because it reached End-Of-Life.<p/>
<p>
Account: <strong>%s (%s)</strong>
Account: <strong>{account_id} ({account_name})</strong>
<br/>
Access Key: <strong>%s</strong>
Access Key: <strong>{existing_access_key}</strong>
</p>
<p>
Thanks,<br/>
Your Security Team
</p>
</body>
</html>""",
mail_subject,
user_name,
account_id,
account_name,
existing_access_key,
)
</html>"""
try:
logger.info("Using %s as mail client", MAIL_CLIENT)
if MAIL_CLIENT == "smtp":
Expand Down
Binary file modified terraform/cryptography.zip
Binary file not shown.
Binary file modified terraform/pytz.zip
Binary file not shown.
Binary file modified terraform/requests.zip
Binary file not shown.

0 comments on commit 175327f

Please sign in to comment.