|
30 | 30 | from requests import ConnectionError |
31 | 31 | from tenacity import RetryError |
32 | 32 |
|
33 | | -from constants import PEER, USER |
| 33 | +from constants import PEER, REPLICATION_PASSWORD_KEY, USER, USER_PASSWORD_KEY |
34 | 34 | from patroni import NotReadyError, Patroni |
35 | 35 | from relations.db import DbProvides |
36 | 36 | from relations.postgresql_provider import PostgreSQLProvider |
@@ -291,11 +291,11 @@ def _get_hostname_from_unit(self, member: str) -> str: |
291 | 291 |
|
292 | 292 | def _on_leader_elected(self, event: LeaderElectedEvent) -> None: |
293 | 293 | """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()) |
296 | 296 |
|
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()) |
299 | 299 |
|
300 | 300 | # Create resources and add labels needed for replication. |
301 | 301 | self._create_resources() |
@@ -427,7 +427,7 @@ def _create_resources(self) -> None: |
427 | 427 |
|
428 | 428 | def _on_get_operator_password(self, event: ActionEvent) -> None: |
429 | 429 | """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()}) |
431 | 431 |
|
432 | 432 | def _on_get_primary(self, event: ActionEvent) -> None: |
433 | 433 | """Get primary instance.""" |
@@ -536,12 +536,12 @@ def _peers(self) -> Relation: |
536 | 536 |
|
537 | 537 | def _get_operator_password(self) -> str: |
538 | 538 | """Get operator user password.""" |
539 | | - return self._get_secret("app", "operator-password") |
| 539 | + return self._get_secret("app", USER_PASSWORD_KEY) |
540 | 540 |
|
541 | 541 | @property |
542 | 542 | def _replication_password(self) -> str: |
543 | 543 | """Get replication user password.""" |
544 | | - return self._get_secret("app", "replication-password") |
| 544 | + return self._get_secret("app", REPLICATION_PASSWORD_KEY) |
545 | 545 |
|
546 | 546 | def _unit_name_to_pod_name(self, unit_name: str) -> str: |
547 | 547 | """Converts unit name to pod name. |
|
0 commit comments