mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix pre-commit
This commit is contained in:
parent
53b8fe1e21
commit
0cf0214951
1 changed files with 39 additions and 39 deletions
|
@ -265,7 +265,7 @@ def __virtual__():
|
|||
|
||||
def __mysql_hash_password(password):
|
||||
_password = hashlib.sha1(password.encode()).digest()
|
||||
_password = "*{}".format(hashlib.sha1(_password).hexdigest().upper())
|
||||
_password = f"*{hashlib.sha1(_password).hexdigest().upper()}"
|
||||
return _password
|
||||
|
||||
|
||||
|
@ -277,7 +277,7 @@ def __check_table(name, table, **connection_args):
|
|||
s_name = quote_identifier(name)
|
||||
s_table = quote_identifier(table)
|
||||
# identifiers cannot be used as values
|
||||
qry = "CHECK TABLE {}.{}".format(s_name, s_table)
|
||||
qry = f"CHECK TABLE {s_name}.{s_table}"
|
||||
_execute(cur, qry)
|
||||
results = cur.fetchall()
|
||||
log.debug(results)
|
||||
|
@ -292,7 +292,7 @@ def __repair_table(name, table, **connection_args):
|
|||
s_name = quote_identifier(name)
|
||||
s_table = quote_identifier(table)
|
||||
# identifiers cannot be used as values
|
||||
qry = "REPAIR TABLE {}.{}".format(s_name, s_table)
|
||||
qry = f"REPAIR TABLE {s_name}.{s_table}"
|
||||
_execute(cur, qry)
|
||||
results = cur.fetchall()
|
||||
log.debug(results)
|
||||
|
@ -307,7 +307,7 @@ def __optimize_table(name, table, **connection_args):
|
|||
s_name = quote_identifier(name)
|
||||
s_table = quote_identifier(table)
|
||||
# identifiers cannot be used as values
|
||||
qry = "OPTIMIZE TABLE {}.{}".format(s_name, s_table)
|
||||
qry = f"OPTIMIZE TABLE {s_name}.{s_table}"
|
||||
_execute(cur, qry)
|
||||
results = cur.fetchall()
|
||||
log.debug(results)
|
||||
|
@ -388,7 +388,7 @@ def _connect(**kwargs):
|
|||
name = name[len(prefix) :]
|
||||
except IndexError:
|
||||
return
|
||||
val = __salt__["config.option"]("mysql.{}".format(name), None)
|
||||
val = __salt__["config.option"](f"mysql.{name}", None)
|
||||
if val is not None:
|
||||
connargs[key] = val
|
||||
|
||||
|
@ -583,7 +583,7 @@ def _grant_to_tokens(grant):
|
|||
if not column:
|
||||
current_grant = token
|
||||
else:
|
||||
token = "{}.{}".format(current_grant, token)
|
||||
token = f"{current_grant}.{token}"
|
||||
grant_tokens.append(token)
|
||||
else: # This is a multi-word, ala LOCK TABLES
|
||||
multiword_statement.append(token)
|
||||
|
@ -1251,7 +1251,7 @@ def db_tables(name, **connection_args):
|
|||
cur = dbc.cursor()
|
||||
s_name = quote_identifier(name)
|
||||
# identifiers cannot be used as values
|
||||
qry = "SHOW TABLES IN {}".format(s_name)
|
||||
qry = f"SHOW TABLES IN {s_name}"
|
||||
try:
|
||||
_execute(cur, qry)
|
||||
except MySQLdb.OperationalError as exc:
|
||||
|
@ -1330,7 +1330,7 @@ def db_create(name, character_set=None, collate=None, **connection_args):
|
|||
cur = dbc.cursor()
|
||||
s_name = quote_identifier(name)
|
||||
# identifiers cannot be used as values
|
||||
qry = "CREATE DATABASE IF NOT EXISTS {}".format(s_name)
|
||||
qry = f"CREATE DATABASE IF NOT EXISTS {s_name}"
|
||||
args = {}
|
||||
if character_set is not None:
|
||||
qry += " CHARACTER SET %(character_set)s"
|
||||
|
@ -1377,7 +1377,7 @@ def db_remove(name, **connection_args):
|
|||
cur = dbc.cursor()
|
||||
s_name = quote_identifier(name)
|
||||
# identifiers cannot be used as values
|
||||
qry = "DROP DATABASE {};".format(s_name)
|
||||
qry = f"DROP DATABASE {s_name};"
|
||||
try:
|
||||
_execute(cur, qry)
|
||||
except MySQLdb.OperationalError as exc:
|
||||
|
@ -1431,7 +1431,7 @@ def _mysql_user_exists(
|
|||
unix_socket=False,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
|
||||
server_version = salt.utils.data.decode(version(**connection_args))
|
||||
|
@ -1476,7 +1476,7 @@ def _mariadb_user_exists(
|
|||
unix_socket=False,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
|
||||
qry = "SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s"
|
||||
|
@ -1508,7 +1508,7 @@ def user_exists(
|
|||
passwordless=False,
|
||||
unix_socket=False,
|
||||
password_column=None,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Checks if a user exists on the MySQL server. A login can be checked to see
|
||||
|
@ -1553,7 +1553,7 @@ def user_exists(
|
|||
if (
|
||||
dbc is None
|
||||
and __context__["mysql.error"].startswith(
|
||||
"MySQL Error 1045: Access denied for user '{}'@".format(user)
|
||||
f"MySQL Error 1045: Access denied for user '{user}'@"
|
||||
)
|
||||
and password
|
||||
):
|
||||
|
@ -1580,7 +1580,7 @@ def user_exists(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
else:
|
||||
qry, args = _mysql_user_exists(
|
||||
|
@ -1592,7 +1592,7 @@ def user_exists(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -1647,7 +1647,7 @@ def _mysql_user_create(
|
|||
unix_socket=False,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
|
||||
server_version = salt.utils.data.decode(version(**connection_args))
|
||||
|
@ -1710,7 +1710,7 @@ def _mariadb_user_create(
|
|||
unix_socket=False,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
|
||||
qry = "CREATE USER %(user)s@%(host)s"
|
||||
|
@ -1756,7 +1756,7 @@ def user_create(
|
|||
unix_socket=False,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Creates a MySQL user
|
||||
|
@ -1846,7 +1846,7 @@ def user_create(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
else:
|
||||
qry, args = _mysql_user_create(
|
||||
|
@ -1858,7 +1858,7 @@ def user_create(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
|
||||
if isinstance(qry, bool):
|
||||
|
@ -1878,9 +1878,9 @@ def user_create(
|
|||
password,
|
||||
password_hash,
|
||||
password_column=password_column,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
msg = "User '{}'@'{}' has been created".format(user, host)
|
||||
msg = f"User '{user}'@'{host}' has been created"
|
||||
if not any((password, password_hash)):
|
||||
msg += " with passwordless login"
|
||||
log.info(msg)
|
||||
|
@ -1899,7 +1899,7 @@ def _mysql_user_chpass(
|
|||
unix_socket=None,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
server_version = salt.utils.data.decode(version(**connection_args))
|
||||
compare_version = "8.0.11"
|
||||
|
@ -1985,7 +1985,7 @@ def _mariadb_user_chpass(
|
|||
unix_socket=None,
|
||||
password_column=None,
|
||||
auth_plugin="mysql_native_password",
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
|
||||
server_version = salt.utils.data.decode(version(**connection_args))
|
||||
|
@ -2056,7 +2056,7 @@ def user_chpass(
|
|||
allow_passwordless=False,
|
||||
unix_socket=None,
|
||||
password_column=None,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Change password for a MySQL user
|
||||
|
@ -2141,7 +2141,7 @@ def user_chpass(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
else:
|
||||
qry, args = _mysql_user_chpass(
|
||||
|
@ -2153,7 +2153,7 @@ def user_chpass(
|
|||
unix_socket,
|
||||
password_column=password_column,
|
||||
auth_plugin=auth_plugin,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -2331,7 +2331,7 @@ def __grant_normalize(grant):
|
|||
exploded_grants = __grant_split(grant)
|
||||
for chkgrant, _ in exploded_grants:
|
||||
if chkgrant.strip().upper() not in __grants__:
|
||||
raise Exception("Invalid grant : '{}'".format(chkgrant))
|
||||
raise Exception(f"Invalid grant : '{chkgrant}'")
|
||||
|
||||
return grant
|
||||
|
||||
|
@ -2351,7 +2351,7 @@ def __ssl_option_sanitize(ssl_option):
|
|||
normal_key = key.strip().upper()
|
||||
|
||||
if normal_key not in __ssl_options__:
|
||||
raise Exception("Invalid SSL option : '{}'".format(key))
|
||||
raise Exception(f"Invalid SSL option : '{key}'")
|
||||
|
||||
if normal_key in __ssl_options_parameterized__:
|
||||
# SSL option parameters (cipher, issuer, subject) are pasted directly to SQL so
|
||||
|
@ -2399,7 +2399,7 @@ def __grant_generate(
|
|||
if table != "*":
|
||||
table = quote_identifier(table)
|
||||
# identifiers cannot be used as values, and same thing for grants
|
||||
qry = "GRANT {} ON {}.{} TO %(user)s@%(host)s".format(grant, dbc, table)
|
||||
qry = f"GRANT {grant} ON {dbc}.{table} TO %(user)s@%(host)s"
|
||||
args = {}
|
||||
args["user"] = user
|
||||
args["host"] = host
|
||||
|
@ -2446,7 +2446,7 @@ def user_grants(user, host="localhost", **connection_args):
|
|||
for grant in results:
|
||||
tmp = grant[0].split(" IDENTIFIED BY")[0]
|
||||
if "WITH GRANT OPTION" in grant[0] and "WITH GRANT OPTION" not in tmp:
|
||||
tmp = "{} WITH GRANT OPTION".format(tmp)
|
||||
tmp = f"{tmp} WITH GRANT OPTION"
|
||||
ret.append(tmp)
|
||||
log.debug(ret)
|
||||
return ret
|
||||
|
@ -2459,7 +2459,7 @@ def grant_exists(
|
|||
host="localhost",
|
||||
grant_option=False,
|
||||
escape=True,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Checks to see if a grant exists in the database
|
||||
|
@ -2580,7 +2580,7 @@ def grant_add(
|
|||
grant_option=False,
|
||||
escape=True,
|
||||
ssl_option=False,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Adds a grant to the MySQL server.
|
||||
|
@ -2636,7 +2636,7 @@ def grant_revoke(
|
|||
host="localhost",
|
||||
grant_option=False,
|
||||
escape=True,
|
||||
**connection_args
|
||||
**connection_args,
|
||||
):
|
||||
"""
|
||||
Removes a grant from the MySQL server.
|
||||
|
@ -2673,7 +2673,7 @@ def grant_revoke(
|
|||
if table != "*":
|
||||
table = quote_identifier(table)
|
||||
# identifiers cannot be used as values, same thing for grants
|
||||
qry = "REVOKE {} ON {}.{} FROM %(user)s@%(host)s;".format(grant, s_database, table)
|
||||
qry = f"REVOKE {grant} ON {s_database}.{table} FROM %(user)s@%(host)s;"
|
||||
args = {}
|
||||
args["user"] = user
|
||||
args["host"] = host
|
||||
|
@ -3038,12 +3038,12 @@ def plugin_add(name, soname=None, **connection_args):
|
|||
if dbc is None:
|
||||
return False
|
||||
cur = dbc.cursor()
|
||||
qry = "INSTALL PLUGIN {}".format(name)
|
||||
qry = f"INSTALL PLUGIN {name}"
|
||||
|
||||
if soname:
|
||||
qry += ' SONAME "{}"'.format(soname)
|
||||
qry += f' SONAME "{soname}"'
|
||||
else:
|
||||
qry += ' SONAME "{}.so"'.format(name)
|
||||
qry += f' SONAME "{name}.so"'
|
||||
|
||||
try:
|
||||
_execute(cur, qry)
|
||||
|
@ -3078,7 +3078,7 @@ def plugin_remove(name, **connection_args):
|
|||
if dbc is None:
|
||||
return False
|
||||
cur = dbc.cursor()
|
||||
qry = "UNINSTALL PLUGIN {}".format(name)
|
||||
qry = f"UNINSTALL PLUGIN {name}"
|
||||
args = {}
|
||||
args["name"] = name
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue