style: minor changes

This commit is contained in:
xpk
2025-11-24 15:40:40 +08:00
parent 3e5bb0547a
commit 6c01a4f55c
3 changed files with 85 additions and 14 deletions
@@ -56,7 +56,7 @@ def lambda_handler(event, context):
step = event['Step']
# Secretsmanager sends 4 rotation events, but we will only use the createSecret event
# and send reminder out
# and the finishSecret event
if step == "createSecret":
# send notification and create a new secret from existing secret
send_notification(secret_id, token)
@@ -64,11 +64,11 @@ def lambda_handler(event, context):
# set new secret with version AWSCURRENT
swap_current_version(secret_id, token)
else:
print("Ignore step " + step)
print(f"Steps other than createSecret and finishSecret will be ignored: {step}")
return True
def send_notification(secret_id, token):
print("Clone secret and send notification for", secret_id)
def send_notification(secret_id: str, token: str) -> None:
print(f"Clone secret and send notification for {secret_id}")
sm_client = boto3.client('secretsmanager')
"""
A new secret version is required by rotation workflow
@@ -90,11 +90,11 @@ def send_notification(secret_id, token):
sns_client = boto3.client('sns')
sns_client.publish(
TopicArn=SNS_TOPIC_ARN,
Message='Please rotate the secret ' + secret_id + '\n\nThis message is generated by lambda function SecretRotationReminder',
Message=f'Your secret {secret_id} is due for update. Please change it on secretsmanager and on your applications.',
Subject='Secret rotation reminder for ' + secret_id.split(":")[6]
)
def swap_current_version(secret_id, token):
def swap_current_version(secret_id: str, token: str) -> None:
print("Point AWSCURRENT to new secret version")
sm_client = boto3.client('secretsmanager')
metadata = sm_client.describe_secret(SecretId=secret_id)
@@ -116,4 +116,3 @@ def swap_current_version(secret_id, token):
VersionStage='AWSPENDING',
RemoveFromVersionId=token
)
return True