Skip to content

Commit

Permalink
Fix assignment of user permissions to databases
Browse files Browse the repository at this point in the history
  • Loading branch information
swoehrl-mw committed Jun 5, 2024
1 parent 28f6aa9 commit 097dc44
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions hybridcloud/backends/azure_postgresqlflexible.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _backend_config(key, default=None, fail_if_missing=False):
EXTENSIONS_PARAMETER = "azure.extensions"
PRELOAD_LIST = ["timescaledb", "pg_cron", "pg_partman_bgw", "pg_partman", "pg_prewarm", "pg_stat_statements", "pgaudit", "pglogical", "wal2json"]

IGNORE_RESET_PARAMETERS = [PRELOAD_PARAMETER, EXTENSIONS_PARAMETER, "log_autovacuum_min_duration", "vacuum_cost_page_miss"]
IGNORE_RESET_PARAMETERS = [PRELOAD_PARAMETER, EXTENSIONS_PARAMETER, "log_autovacuum_min_duration", "vacuum_cost_page_miss", "temp_tablespaces"]


def _calc_name(namespace, name):
Expand Down Expand Up @@ -119,9 +119,11 @@ def compare():
return True
if server.maintenance_window != maintenance_window:
return True
if server.tags != tags:
return True
return False
tags_changed = False
for k, v in tags.items():
if server.tags.get(k) != v:
tags_changed = True
return tags_changed
changed = compare() or admin_password_changed
except:
server = None
Expand Down Expand Up @@ -149,7 +151,6 @@ def compare():
server = poller.result()
elif changed:
parameters = ServerForUpdate(
location=self._location,
sku=sku,
administrator_login_password=password,
storage=Storage(storage_size_gb=storage_gb),
Expand Down Expand Up @@ -216,18 +217,19 @@ def compare():
should_restart = False

if preload_extensions != applied_preload_extensions:
self._logger.info(f"Updating list of extensions from {','.join(applied_preload_extensions)} to {','.join(extensions)}")
self._logger.info(f"Updating list of preload extensions from \"{','.join(applied_preload_extensions)}\" to \"{','.join(preload_extensions)}\"")
# Update configuration
poller = self._db_client.configurations.begin_put(self._resource_group, server_name, PRELOAD_PARAMETER, Configuration(value=",".join(extensions), source="user-override"))
poller = self._db_client.configurations.begin_put(self._resource_group, server_name, PRELOAD_PARAMETER, Configuration(value=",".join(preload_extensions), source="user-override"))
poller.result()
should_restart = True

if extensions != applied_allowed_extenions:
self._logger.info(f"Updating list of extensions from \"{','.join(applied_allowed_extenions)}\" to \"{','.join(extensions)}\"")
# Update configuration
poller = self._db_client.configurations.begin_put(self._resource_group, server_name, EXTENSIONS_PARAMETER, Configuration(value=",".join(extensions), source="user-override"))
poller.result()
should_restart = True

# Iterate through the server properties that are currently set on the server
for parameter in self._db_client.configurations.list_by_server(self._resource_group, server_name):

Expand Down Expand Up @@ -262,7 +264,7 @@ def compare():

if should_restart:
# Restart server
self._logger.info("Restarting server due to changed server parameters")
self._logger.info("Restarting server due to changed server parameters or extensions")
poller = self._db_client.servers.begin_restart(self._resource_group, server_name)
poller.result()
self._logger.info("Initiated server restart")
Expand Down Expand Up @@ -320,7 +322,7 @@ def delete_database(self, namespace, server_name, database_name, admin_credentia
poller.result()

def create_or_update_user(self, namespace, server_name, database_name, username, password, admin_credentials=None):
pgclient = self._pgclient(admin_credentials)
pgclient = self._pgclient(admin_credentials, database_name)
newly_created = pgclient.create_or_update_user(username, password, database_name)
return newly_created, {
"username": username,
Expand Down

0 comments on commit 097dc44

Please sign in to comment.