Skip to content

Commit 175327f

Browse files
committed
update libraries and fix syntax
1 parent d3a7bad commit 175327f

File tree

5 files changed

+22
-44
lines changed

5 files changed

+22
-44
lines changed

src/creator.py

+14-29
Original file line numberDiff line numberDiff line change
@@ -170,57 +170,46 @@ def send_email(
170170
Thanks,\n
171171
Your Security Team"""
172172

173-
mail_body_html = (
174-
"""
173+
mail_body_html = f"""
175174
<!DOCTYPE html>
176175
<html style="font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
177176
box-sizing: border-box; font-size: 14px; margin: 0;">
178177
<head>
179178
<meta name="viewport" content="width=device-width" />
180179
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
181-
<title>%s</title>
180+
<title>{mail_subject}</title>
182181
183182
<style type="text/css">
184-
body {{
183+
body {{{{
185184
-webkit-font-smoothing: antialiased;
186185
-webkit-text-size-adjust: none;
187186
width: 100% !important;
188187
height: 100%;
189188
line-height: 1.6em;
190-
}}
189+
}}}}
191190
</style>
192191
</head>
193192
<body>
194-
<p>Hey &#x1F44B; %s,</p>
193+
<p>Hey &#x1F44B; {user_name},</p>
195194
<p>A new access key pair has been generated for you.
196195
Please update the same wherever necessary.</p>
197196
<p>
198-
Account: <b>%s (%s)</b>
197+
Account: <b>{account_id} ({account_name})</b>
199198
<br/>
200-
Access Key: <b>%s</b>
199+
Access Key: <b>{access_key}</b>
201200
<br/>
202-
Secret Access Key: <b>%s</b>
201+
Secret Access Key: <b>{secret_key}</b>
203202
<br/>
204-
Instruction: <b>%s</b>
203+
Instruction: <b>{instruction}</b>
205204
</p>
206-
<p><b>Note:</b> Existing key pair <b>%s</b> will be deleted after
207-
<b>%s</b> days so please update the key pair wherever required.</p>
205+
<p><b>Note:</b> Existing key pair <b>{existing_access_key}</b> will be deleted after
206+
<b>{existing_key_delete_age}</b> days so please update the key pair wherever required.</p>
208207
<p>
209208
Thanks,<br/>
210209
Your Security Team
211210
</p>
212211
</body>
213-
</html>""",
214-
mail_subject,
215-
user_name,
216-
account_id,
217-
account_name,
218-
access_key,
219-
secret_key,
220-
instruction,
221-
existing_access_key,
222-
existing_key_delete_age,
223-
)
212+
</html>"""
224213

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

@@ -259,7 +248,7 @@ def send_email(
259248
)
260249
else:
261250
logger.error(
262-
"%s: Invalid mail client. Supported mail clients: AWS SES and Mailgun",
251+
"%s: Invalid mail client",
263252
MAIL_CLIENT,
264253
)
265254
except (Exception, ClientError) as ce:
@@ -344,11 +333,7 @@ def create_user_key(user_name, user):
344333
resp["AccessKey"]["AccessKeyId"],
345334
resp["AccessKey"]["SecretAccessKey"],
346335
)
347-
user_instruction = (
348-
"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",
349-
user_name,
350-
user["attributes"]["instruction"],
351-
)
336+
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)'
352337
else:
353338
user_access_key = resp["AccessKey"]["AccessKeyId"]
354339
user_secret_access_key = resp["AccessKey"]["SecretAccessKey"]

src/destructor.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -52,46 +52,39 @@ def send_email(email, user_name, existing_access_key):
5252
Thanks,\n
5353
Your Security Team"""
5454

55-
mail_body_html = (
56-
"""
55+
mail_body_html = f"""
5756
<!DOCTYPE html>
5857
<html style="font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
5958
box-sizing: border-box; font-size: 14px; margin: 0;">
6059
<head>
6160
<meta name="viewport" content="width=device-width" />
6261
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
63-
<title>%s</title>
62+
<title>{mail_subject}</title>
6463
<style type="text/css">
65-
body {{
64+
body {{{{
6665
-webkit-font-smoothing: antialiased;
6766
-webkit-text-size-adjust: none;
6867
width: 100% !important;
6968
height: 100%;
7069
line-height: 1.6em;
71-
}}
70+
}}}}
7271
</style>
7372
</head>
7473
<body>
75-
<p>Hey &#x1F44B; %s,</p>
74+
<p>Hey &#x1F44B; {user_name},</p>
7675
<p>An existing access key pair associated to your
7776
username has been deleted because it reached End-Of-Life.<p/>
7877
<p>
79-
Account: <strong>%s (%s)</strong>
78+
Account: <strong>{account_id} ({account_name})</strong>
8079
<br/>
81-
Access Key: <strong>%s</strong>
80+
Access Key: <strong>{existing_access_key}</strong>
8281
</p>
8382
<p>
8483
Thanks,<br/>
8584
Your Security Team
8685
</p>
8786
</body>
88-
</html>""",
89-
mail_subject,
90-
user_name,
91-
account_id,
92-
account_name,
93-
existing_access_key,
94-
)
87+
</html>"""
9588
try:
9689
logger.info("Using %s as mail client", MAIL_CLIENT)
9790
if MAIL_CLIENT == "smtp":

terraform/cryptography.zip

1.81 MB
Binary file not shown.

terraform/pytz.zip

64.9 KB
Binary file not shown.

terraform/requests.zip

665 KB
Binary file not shown.

0 commit comments

Comments
 (0)