Skip to content

Commit 06228cb

Browse files
authored
[MISC] Check is_user_in_hba output (#973)
* Check is_user_in_hba output * Drop extra parameter
1 parent 2603544 commit 06228cb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3737
# to 0 if you are raising the major API version
38-
LIBPATCH = 56
38+
LIBPATCH = 53
3939

4040
# Groups to distinguish HBA access
4141
ACCESS_GROUP_IDENTITY = "identity_access"
@@ -780,6 +780,7 @@ def list_valid_privileges_and_roles(self) -> Tuple[Set[str], Set[str]]:
780780
def set_up_database(self) -> None:
781781
"""Set up postgres database with the right permissions."""
782782
connection = None
783+
cursor = None
783784
try:
784785
with self._connect_to_database(
785786
database="template1"
@@ -879,6 +880,8 @@ def set_up_database(self) -> None:
879880
logger.error(f"Failed to set up databases: {e}")
880881
raise PostgreSQLDatabasesSetupError() from e
881882
finally:
883+
if cursor is not None:
884+
cursor.close()
882885
if connection is not None:
883886
connection.close()
884887

src/relations/postgresql_provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
148148
try:
149149
for attempt in Retrying(stop=stop_after_attempt(3), wait=wait_fixed(1)):
150150
with attempt:
151-
self.charm.postgresql.is_user_in_hba(user)
151+
if not self.charm.postgresql.is_user_in_hba(user):
152+
raise Exception("pg_hba not ready")
152153
self.charm.unit_peer_data.update({
153154
"pg_hba_needs_update_timestamp": str(datetime.now())
154155
})

0 commit comments

Comments
 (0)