From 92230ce18ad28a63d9f60fbda62fcb49dd9df37b Mon Sep 17 00:00:00 2001 From: Mia Altieri <32723809+MiaAltieri@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:47:05 +0100 Subject: [PATCH] Apply Mehdi's suggestions from code review Co-authored-by: Mehdi Bendriss --- lib/charms/mongodb/v0/mongodb_tls.py | 3 +-- lib/charms/mongodb/v1/shards_interface.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/charms/mongodb/v0/mongodb_tls.py b/lib/charms/mongodb/v0/mongodb_tls.py index 70f9ca73f..ad303bfb8 100644 --- a/lib/charms/mongodb/v0/mongodb_tls.py +++ b/lib/charms/mongodb/v0/mongodb_tls.py @@ -306,7 +306,6 @@ def _get_subject_name(self) -> str: if self.charm.is_role(Config.Role.SHARD): # until integrated with config-server use current app name as # subject name - subject_name = self.charm.shard.get_config_server_name() or self.charm.app.name - return subject_name + return self.charm.shard.get_config_server_name() or self.charm.app.name return self.charm.app.name diff --git a/lib/charms/mongodb/v1/shards_interface.py b/lib/charms/mongodb/v1/shards_interface.py index dd6f77d69..0ccd9c9fd 100644 --- a/lib/charms/mongodb/v1/shards_interface.py +++ b/lib/charms/mongodb/v1/shards_interface.py @@ -561,7 +561,7 @@ def _handle_changed_secrets(self, event) -> None: # FUTURE PR: if config-server does not have TLS enabled log a useful message and go into # blocked in relation_changed and other status checks - def get_membership_auth_modes(self, event) -> Tuple: + def get_membership_auth_modes(self, event: RelationChangedEvent) -> Tuple[bool, bool]: """Returns the available authentication membership forms.""" key_file_contents = self.database_requires.fetch_relation_field( event.relation.id, KEYFILE_KEY @@ -569,9 +569,11 @@ def get_membership_auth_modes(self, event) -> Tuple: tls_ca = self.database_requires.fetch_relation_field(event.relation.id, INT_TLS_CA_KEY) return (key_file_contents is not None, tls_ca is not None) - def update_member_auth(self, event, membership_auth) -> None: + def update_member_auth( + self, event: RelationChangedEvent, membership_auth: Tuple[bool, bool] + ) -> None: """Updates the shard to have the same membership auth as the config-server.""" - (key_file_contents, cluster_tls_ca) = membership_auth + is_key_file_contents_auth, is_tls_auth = membership_auth tls_integrated = self.charm.model.get_relation(Config.TLS.TLS_PEER_RELATION) # Edge case: shard has TLS enabled before having connected to the config-server. For TLS in @@ -596,7 +598,7 @@ def update_member_auth(self, event, membership_auth) -> None: # Future PR - status updating for inconsistencies with TLS (i.e. shard has TLS but # config-server does not and vice versa or CA-mismatch) - def get_cluster_passwords(self, event) -> Tuple: + def get_cluster_passwords(self, event: RelationChangedEvent) -> Tuple[Optional[str], Optional[str]]: """Retrieves shared cluster passwords.""" operator_password = self.database_requires.fetch_relation_field( event.relation.id, OPERATOR_PASSWORD_KEY @@ -606,7 +608,9 @@ def get_cluster_passwords(self, event) -> Tuple: ) return (operator_password, backup_password) - def update_cluster_passwords(self, event, operator_password, backup_password): + def update_cluster_passwords( + self, event: RelationChangedEvent, operator_password: str, backup_password: str + ) -> None: """Updates shared cluster passwords.""" try: self.update_password(