Skip to content

Commit

Permalink
Merge pull request #41 from canonical/support-juju-317
Browse files Browse the repository at this point in the history
[DPE-4664] hotfix to support Juju secrets on 3.1.7
  • Loading branch information
Mehdi-Bendriss authored Jun 26, 2024
2 parents 9d7b720 + 48ad832 commit 0486be7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
with:
artifact-name: ${{ needs.build.outputs.artifact-name }}
cloud: lxd
juju-agent-version: 3.1.6
juju-agent-version: 3.1.7
18 changes: 16 additions & 2 deletions lib/charms/mongodb/v0/mongodb_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ops import Secret, SecretInfo
from ops.charm import CharmBase
from ops.model import SecretNotFoundError
from ops.model import ModelError, SecretNotFoundError

from config import Config
from exceptions import SecretAlreadyExistsError
Expand Down Expand Up @@ -93,7 +93,21 @@ def get_content(self) -> Dict[str, str]:
"""Getting cached secret content."""
if not self._secret_content:
if self.meta:
self._secret_content = self.meta.get_content()
try:
self._secret_content = self.meta.get_content(refresh=True)
except (ValueError, ModelError) as err:
# https://bugs.launchpad.net/juju/+bug/2042596
# Only triggered when 'refresh' is set
known_model_errors = [
"ERROR either URI or label should be used for getting an owned secret but not both",
"ERROR secret owner cannot use --refresh",
]
if isinstance(err, ModelError) and not any(
msg in str(err) for msg in known_model_errors
):
raise
# Due to: ValueError: Secret owner cannot use refresh=True
self._secret_content = self.meta.get_content()
return self._secret_content

def set_content(self, content: Dict[str, str]) -> None:
Expand Down

0 comments on commit 0486be7

Please sign in to comment.