Skip to content

Commit 36640b2

Browse files
committed
Add constants
1 parent 05b707e commit 36640b2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/charm.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from requests import ConnectionError
3131
from tenacity import RetryError
3232

33-
from constants import PEER, USER
33+
from constants import PEER, REPLICATION_PASSWORD_KEY, USER, USER_PASSWORD_KEY
3434
from patroni import NotReadyError, Patroni
3535
from relations.db import DbProvides
3636
from relations.postgresql_provider import PostgreSQLProvider
@@ -291,11 +291,11 @@ def _get_hostname_from_unit(self, member: str) -> str:
291291

292292
def _on_leader_elected(self, event: LeaderElectedEvent) -> None:
293293
"""Handle the leader-elected event."""
294-
if self._get_secret("app", "operator-password") is None:
295-
self._set_secret("app", "operator-password", new_password())
294+
if self._get_secret("app", USER_PASSWORD_KEY) is None:
295+
self._set_secret("app", USER_PASSWORD_KEY, new_password())
296296

297-
if self._get_secret("app", "replication-password") is None:
298-
self._set_secret("app", "replication-password", new_password())
297+
if self._get_secret("app", REPLICATION_PASSWORD_KEY) is None:
298+
self._set_secret("app", REPLICATION_PASSWORD_KEY, new_password())
299299

300300
# Create resources and add labels needed for replication.
301301
self._create_resources()
@@ -427,7 +427,7 @@ def _create_resources(self) -> None:
427427

428428
def _on_get_operator_password(self, event: ActionEvent) -> None:
429429
"""Returns the password for the operator user as an action response."""
430-
event.set_results({"operator-password": self._get_operator_password()})
430+
event.set_results({USER_PASSWORD_KEY: self._get_operator_password()})
431431

432432
def _on_get_primary(self, event: ActionEvent) -> None:
433433
"""Get primary instance."""
@@ -536,12 +536,12 @@ def _peers(self) -> Relation:
536536

537537
def _get_operator_password(self) -> str:
538538
"""Get operator user password."""
539-
return self._get_secret("app", "operator-password")
539+
return self._get_secret("app", USER_PASSWORD_KEY)
540540

541541
@property
542542
def _replication_password(self) -> str:
543543
"""Get replication user password."""
544-
return self._get_secret("app", "replication-password")
544+
return self._get_secret("app", REPLICATION_PASSWORD_KEY)
545545

546546
def _unit_name_to_pod_name(self, unit_name: str) -> str:
547547
"""Converts unit name to pod name.

src/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
DATABASE_PORT = "5432"
77
PEER = "database-peers"
8+
REPLICATION_PASSWORD_KEY = "replication-password"
89
USER = "operator"
10+
USER_PASSWORD_KEY = "operator-password"

0 commit comments

Comments
 (0)