This commit is contained in:
cronekorkn 2024-02-04 11:06:53 +01:00
parent d6b109da01
commit 695bfb5dde
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw

View file

@ -1,7 +1,8 @@
from shlex import quote
def mariadb(sql):
return f"mariadb -Bsr --execute {quote(sql)}"
def mariadb(sql, **kwargs):
kwargs_string = ''.join(f" --{k} {v}" for k, v in kwargs.items())
return f"mariadb{kwargs_string} -Bsr --execute {quote(sql)}"
directories = {
'/var/lib/mysql': {
@ -56,3 +57,11 @@ for db, conf in node.metadata.get('mariadb/databases', {}).items():
f'action:mariadb_user_{db}_create',
],
}
print(mariadb(f"SHOW GRANTS FOR {db}") + f"grep -q '^GRANT ALL PRIVILEGES'")
actions[f'mariadb_grant_privileges_to_{db}'] = {
'command': mariadb(f"GRANT ALL PRIVILEGES ON *.* TO '{db}'", database=db),
'unless': mariadb(f"SHOW GRANTS FOR {db}") + f" | grep -q '^GRANT USAGE ON *.* TO `{db}`'",
'needs': [
f'action:mariadb_user_{db}_create',
],
}