Skip to content

Commit 0ec2e9d

Browse files
author
antovera
authored
Merge pull request #2 from aws-samples/percent-symbol-fix
Supports MySQL/Maria grants containing percent symbols.
2 parents d43685f + edd300a commit 0ec2e9d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

SecretsManagerRDSMariaDBRotationMultiUser/lambda_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def set_secret(service_client, arn, token):
188188
for row in cur.fetchall():
189189
grant = row[0].split(' TO ')
190190
new_grant = "%s TO %s" % (grant[0], pending_dict['username'])
191-
cur.execute(new_grant + " IDENTIFIED BY %s", pending_dict['password'])
191+
new_grant_escaped = new_grant.replace('%','%%') # % is a special character in Python format strings.
192+
cur.execute(new_grant_escaped + " IDENTIFIED BY %s", pending_dict['password'])
192193
conn.commit()
193194
logger.info("setSecret: Successfully set password for %s in MariaDB DB for secret arn %s." % (pending_dict['username'], arn))
194195
finally:

SecretsManagerRDSMySQLRotationMultiUser/lambda_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def set_secret(service_client, arn, token):
188188
for row in cur.fetchall():
189189
grant = row[0].split(' TO ')
190190
new_grant = "%s TO '%s'" % (grant[0], pending_dict['username'])
191-
cur.execute(new_grant + " IDENTIFIED BY %s", pending_dict['password'])
191+
new_grant_escaped = new_grant.replace('%','%%') # % is a special character in Python format strings.
192+
cur.execute(new_grant_escaped + " IDENTIFIED BY %s", pending_dict['password'])
192193
conn.commit()
193194
logger.info("setSecret: Successfully set password for %s in MySQL DB for secret arn %s." % (pending_dict['username'], arn))
194195
finally:

0 commit comments

Comments
 (0)