Qualify pinned database identity and restricted MySQL backup profile
ABSDEV Framework CI / framework-ci (push) Successful in 24s
ABSDEV Framework CI / framework-ci (push) Successful in 24s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""MySQL database command construction."""
|
||||
|
||||
from core.database import DatabaseAdapter
|
||||
from core.database import DatabaseAdapter, DatabaseError
|
||||
|
||||
|
||||
class MySQLAdapter(DatabaseAdapter):
|
||||
@@ -11,6 +11,21 @@ class MySQLAdapter(DatabaseAdapter):
|
||||
"--defaults-file=/run/secrets/absdev-client.cnf"
|
||||
)
|
||||
|
||||
def __init__(self, config, *, read_only_backup=False):
|
||||
super().__init__(config)
|
||||
if type(read_only_backup) is not bool:
|
||||
raise DatabaseError("Invalid MySQL backup option")
|
||||
self.read_only_backup = read_only_backup
|
||||
|
||||
def backup_inventory_command(self):
|
||||
if not self.read_only_backup:
|
||||
return None
|
||||
# The trusted definer procedure is installed outside the protected database.
|
||||
return self.query_command("CALL absdev_backup_control.check_inventory(DATABASE())")
|
||||
|
||||
def backup_grants_command(self):
|
||||
return self.query_command("SELECT @@GLOBAL.partial_revokes; SHOW GRANTS FOR CURRENT_USER()")
|
||||
|
||||
def connection_arguments(self):
|
||||
|
||||
return [
|
||||
@@ -68,9 +83,10 @@ class MySQLAdapter(DatabaseAdapter):
|
||||
"--skip-lock-tables",
|
||||
"--set-gtid-purged=OFF",
|
||||
"--hex-blob",
|
||||
"--triggers",
|
||||
"--routines",
|
||||
"--events",
|
||||
*(
|
||||
("--skip-triggers", "--skip-routines", "--skip-events")
|
||||
if self.read_only_backup else ("--triggers", "--routines", "--events")
|
||||
),
|
||||
self.database["name"],
|
||||
]
|
||||
)
|
||||
|
||||
@@ -55,6 +55,12 @@ class PostgreSQLAdapter(DatabaseAdapter):
|
||||
"SELECT current_database(), current_user"
|
||||
)
|
||||
|
||||
def live_identity_command(self):
|
||||
return self.query_command(
|
||||
"SELECT current_database(), current_user, system_identifier "
|
||||
"FROM pg_catalog.pg_control_system()"
|
||||
)
|
||||
|
||||
def backup_command(self):
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user