Skip to content

Commit

Permalink
fix if not exists
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Descamps <lefred.descamps@gmail.com>
  • Loading branch information
lefred committed Sep 22, 2023
1 parent e0bd2ed commit aa5c6bb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion user/clone.py
Expand Up @@ -144,7 +144,7 @@ def copy_users_grants(userfrom=None, userto=None, dryrun=False, ocimds=False, fo
auth_string = auth_user[0]
auth_string_bin = auth_user[1]
hex_string = auth_string_bin.hex()
create_user = re.sub(r"AS '(.*)' ", r"AS 0x{} ".format(hex_string), create_user)
create_user = re.sub(r" AS '(.*)' ", r" AS 0x{} ".format(hex_string), create_user)
if dryrun:
print("-- User `{}`@`{}`".format(user[0], user[1]))
print(create_user)
Expand Down
2 changes: 1 addition & 1 deletion user/copy.py
Expand Up @@ -213,7 +213,7 @@ def copy_users_grants(dryrun=False, ocimds=False, force=False, session=None):
auth_string = auth_user[0]
auth_string_bin = auth_user[1]
hex_string = auth_string_bin.hex()
create_user = re.sub(r"AS '(.*)' ", r"AS 0x{} ".format(hex_string), create_user)
create_user = re.sub(r" AS '(.*)' ", r" AS 0x{} ".format(hex_string), create_user)
if mysql_major_int < 8 and mysql_version != "5.7":
if len(old_format) > 0 and not back_tick:
# we need to find the password
Expand Down
4 changes: 2 additions & 2 deletions user/grants.py
Expand Up @@ -128,15 +128,15 @@ def get_users_grants(find=None, exclude=None, ocimds=False, session=None):
else:
stmt = """SHOW CREATE USER `{}`@`{}`""".format(user[0], user[1])
create_user = session.run_sql(stmt).fetch_one()[0] + ";"
create_user = create_user.replace("CREATE USER '{}'@'".format(user[0]),"CREATE USER IF NOT EXISTS '{}'@'".format(user[0]))
create_user = create_user.replace("CREATE USER `{}`@`".format(user[0]),"CREATE USER IF NOT EXISTS `{}`@`".format(user[0]))
# we need to find the password in binary format
stmt = """SELECT authentication_string, convert(authentication_string using binary) authbin
FROM mysql.user where user='{}' and host='{}'""".format(user[0], user[1])
auth_user = session.run_sql(stmt).fetch_one()
auth_string = auth_user[0]
auth_string_bin = auth_user[1]
hex_string = auth_string_bin.hex()
create_user = re.sub(r"AS '(.*)' ", r"AS 0x{} ".format(hex_string), create_user)
create_user = re.sub(r" AS '(.*)' ", r" AS 0x{} ".format(hex_string), create_user)
if mysql_major_int < 8:
if old_format:
if len(old_format) > 0 and not back_tick:
Expand Down

0 comments on commit aa5c6bb

Please sign in to comment.