Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Ratushnyy committed Sep 6, 2023
1 parent ee71c40 commit 56332c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
34 changes: 14 additions & 20 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def _on_secret_changed(self, event: SecretChangedEvent):
f"Secret {event._id}:{event.secret.id} changed, but it's irrelevant for us"
)
return
self._update_secrets_cache(scope)
self._update_juju_secrets_cache(scope)
self._connect_mongodb_exporter()

# END: charm event handlers
Expand Down Expand Up @@ -1063,7 +1063,6 @@ def auth_enabled(self) -> bool:

return any("MONGOD_ARGS" in line and "--auth" in line for line in env_vars)

<<<<<<< HEAD
def has_backup_service(self):
"""Verifies the backup service is available."""
snap_cache = snap.SnapCache()
Expand Down Expand Up @@ -1110,9 +1109,6 @@ def restart_backup_service(self) -> None:
charmed_mongodb_snap.restart(services=["pbm-agent"])


# pbm_snap.restart(services=["pbm-agent"])
# END: helper functions
=======
def _scope_obj(self, scope: Scopes):
if scope == APP_SCOPE:
return self.app
Expand All @@ -1128,7 +1124,7 @@ def _peer_data(self, scope: Scopes):
def _juju_secret_set(self, scope: Scopes, key: str, value: str) -> str:
"""Helper function setting Juju secret in Juju versions >3.0."""
peer_data = self._peer_data(scope)
self._juju_secrets_get(scope)
self._update_juju_secrets_cache(scope)

secret = self.secrets[scope].get(Config.Secrets.SECRET_LABEL)

Expand Down Expand Up @@ -1166,7 +1162,7 @@ def _juju_secret_set(self, scope: Scopes, key: str, value: str) -> str:

return self.secrets[scope][Config.Secrets.SECRET_LABEL].id

def _juju_secrets_get(self, scope: Scopes) -> Optional[bool]:
def _update_juju_secrets_cache(self, scope: Scopes) -> None:
"""Helper function to get Juju secret."""
peer_data = self._peer_data(scope)

Expand All @@ -1191,27 +1187,26 @@ def _juju_secrets_get(self, scope: Scopes) -> Optional[bool]:
# We retrieve and cache actual secret data for the lifetime of the event scope
self.secrets[scope][Config.Secrets.SECRET_CACHE_LABEL] = secret.get_content()

if self.secrets[scope].get(Config.Secrets.SECRET_CACHE_LABEL):
return True
return False
def _get_juju_secrets_cache(self, scope: Scopes):
return self.secrets[scope].get(Config.Secrets.SECRET_CACHE_LABEL)

def _juju_secret_get(self, scope: Scopes, key: str) -> Optional[str]:
"""Helper function to get Juju secret."""
if not key:
return

if self._juju_secrets_get(scope):
secret_cache = self.secrets[scope].get(Config.Secrets.SECRET_CACHE_LABEL)
if secret_cache:
secret_data = secret_cache.get(key)
if secret_data and secret_data != Config.Secrets.SECRET_DELETED_LABEL:
logging.debug(f"Getting secret {scope}:{key}")
return secret_data
self._update_juju_secrets_cache(scope)
secret_cache = self._get_juju_secrets_cache(scope)
if secret_cache:
secret_data = secret_cache.get(key)
if secret_data and secret_data != Config.Secrets.SECRET_DELETED_LABEL:
logging.debug(f"Getting secret {scope}:{key}")
return secret_data
logging.debug(f"No value found for secret {scope}:{key}")

def _juju_secret_remove(self, scope: Scopes, key: str) -> None:
"""Remove a Juju 3.x secret."""
self._juju_secrets_get(scope)
self._update_juju_secrets_cache(scope)

secret = self.secrets[scope].get(Config.Secrets.SECRET_LABEL)
if not secret:
Expand All @@ -1228,7 +1223,6 @@ def _juju_secret_remove(self, scope: Scopes, key: str) -> None:
logging.debug(f"Secret {scope}:{key}")

# END: helper functions
>>>>>>> 008665e (WIP: Fixing issue with charm)


if __name__ == "__main__":
Expand Down
16 changes: 8 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
pytest-mock
-r {tox_root}/requirements.txt
Expand All @@ -89,7 +89,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand All @@ -103,7 +103,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand All @@ -117,7 +117,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand All @@ -131,7 +131,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
pytest-mock
-r {tox_root}/requirements.txt
Expand All @@ -151,7 +151,7 @@ pass_env =
GCP_SECRET_KEY
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
pytest-mock
-r {tox_root}/requirements.txt
Expand All @@ -166,7 +166,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand All @@ -181,7 +181,7 @@ pass_env =
CI_PACKED_CHARMS
deps =
pytest
juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0
juju==3.2.0.1
pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand Down

0 comments on commit 56332c7

Please sign in to comment.