Skip to content

Commit 04999ee

Browse files
authored
Check is_user_in_hba output (#974)
1 parent f00d3f2 commit 04999ee

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

src/constants.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@
7171

7272
SECRET_KEY_OVERRIDES = {"ca": "cauth"}
7373

74-
ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE = (
75-
"Please choose one endpoint to use. No need to relate all of them simultaneously!"
76-
)
77-
7874
TRACING_PROTOCOL = "otlp_http"
7975

8076
BACKUP_TYPE_OVERRIDES = {"full": "full", "differential": "diff", "incremental": "incr"}

src/relations/postgresql_provider.py

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
PostgreSQLGetPostgreSQLVersionError,
2222
PostgreSQLListUsersError,
2323
)
24-
from ops.charm import RelationBrokenEvent, RelationChangedEvent
24+
from ops.charm import RelationBrokenEvent
2525
from ops.framework import Object
2626
from ops.model import ActiveStatus, BlockedStatus, Relation
2727
from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed
@@ -30,7 +30,6 @@
3030
ALL_CLIENT_RELATIONS,
3131
APP_SCOPE,
3232
DATABASE_PORT,
33-
ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE,
3433
)
3534
from utils import label2name, new_password
3635

@@ -62,10 +61,6 @@ def __init__(self, charm: "PostgresqlOperatorCharm", relation_name: str = "datab
6261
self.framework.observe(
6362
charm.on[self.relation_name].relation_broken, self._on_relation_broken
6463
)
65-
self.framework.observe(
66-
charm.on[self.relation_name].relation_changed,
67-
self._on_relation_changed_event,
68-
)
6964
self.charm = charm
7065

7166
# Charm events defined in the database provides charm library.
@@ -151,12 +146,14 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
151146
else f"Failed to initialize relation {self.relation_name}"
152147
)
153148
)
149+
return
154150

155151
# Try to wait for pg_hba trigger
156152
try:
157153
for attempt in Retrying(stop=stop_after_attempt(3), wait=wait_fixed(1)):
158154
with attempt:
159-
self.charm.postgresql.is_user_in_hba(user)
155+
if not self.charm.postgresql.is_user_in_hba(user):
156+
raise Exception("pg_hba not ready")
160157
self.charm.unit_peer_data.update({
161158
"pg_hba_needs_update_timestamp": str(datetime.now())
162159
})
@@ -299,11 +296,6 @@ def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None: # noq
299296
self.database_provides.set_tls(relation_id, tls)
300297
self.database_provides.set_tls_ca(relation_id, ca)
301298

302-
def _check_multiple_endpoints(self) -> bool:
303-
"""Checks if there are relations with other endpoints."""
304-
relation_names = {relation.name for relation in self.charm.client_relations}
305-
return "database" in relation_names and len(relation_names) > 1
306-
307299
def _update_unit_status(self, relation: Relation) -> None:
308300
"""# Clean up Blocked status if it's due to extensions request."""
309301
if (
@@ -317,27 +309,6 @@ def _update_unit_status(self, relation: Relation) -> None:
317309
):
318310
self.charm.set_unit_status(ActiveStatus())
319311

320-
self._update_unit_status_on_blocking_endpoint_simultaneously()
321-
322-
def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
323-
"""Event emitted when the relation has changed."""
324-
# Leader only
325-
if not self.charm.unit.is_leader():
326-
return
327-
328-
if self._check_multiple_endpoints():
329-
self.charm.set_unit_status(BlockedStatus(ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE))
330-
return
331-
332-
def _update_unit_status_on_blocking_endpoint_simultaneously(self):
333-
"""Clean up Blocked status if this is due related of multiple endpoints."""
334-
if (
335-
self.charm.is_blocked
336-
and self.charm.unit.status.message == ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE
337-
and not self._check_multiple_endpoints()
338-
):
339-
self.charm.set_unit_status(ActiveStatus())
340-
341312
def check_for_invalid_extra_user_roles(self, relation_id: int) -> bool:
342313
"""Checks if there are relations with invalid extra user roles.
343314

0 commit comments

Comments
 (0)