Skip to content

Commit

Permalink
[DPE-3308][3.1.7] Secrets fix 3.1.7 running on 3.1.7 (#331)
Browse files Browse the repository at this point in the history
Contents of #330
running on 3.1.7
  • Loading branch information
juditnovak committed Jan 15, 2024
1 parent 233846e commit c28e7b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ jobs:
with:
provider: lxd
juju-channel: 3.1/stable
bootstrap-options: "--agent-version 3.1.6"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
Expand Down
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 c28e7b9

Please sign in to comment.