-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-4416] URI exists while re-creating secret with modified label #170
Changes from 5 commits
9e95539
fbad650
8f85434
760933e
3430095
9a30354
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent): | |
|
||
# Increment this PATCH version before using `charmcraft publish-lib` or reset | ||
# to 0 if you are raising the major API version | ||
LIBPATCH = 35 | ||
LIBPATCH = 36 | ||
|
||
PYDEPS = ["ops>=2.0.0"] | ||
|
||
|
@@ -642,16 +642,16 @@ def _move_to_new_label_if_needed(self): | |
return | ||
|
||
# Create a new secret with the new label | ||
old_meta = self._secret_meta | ||
content = self._secret_meta.get_content() | ||
self._secret_uri = None | ||
|
||
# I wish we could just check if we are the owners of the secret... | ||
try: | ||
self._secret_meta = self.add_secret(content, label=self.label) | ||
except ModelError as err: | ||
if "this unit is not the leader" not in str(err): | ||
raise | ||
old_meta.remove_all_revisions() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this in a long term, but I rather leave "garbage" around for now, and bring this code back after having verified that under no circumstances we may remove this data pre-mature. See issue on this matter #171 |
||
self.current_label = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is used to indicate when an upgrade was performed, where a secret label change may have happened. We detect dynamically if a secret with an old label may be "hanging around", from an old version of the charm. In order to ensure smooth upgrades, we are leaving the secret associated with the old label, as long as only read operations are performed on the secret. When the above code is executed, we are at the point of the first write operation impacting this secret. |
||
|
||
def set_content(self, content: Dict[str, str]) -> None: | ||
"""Setting cached secret content.""" | ||
|
@@ -1586,7 +1586,7 @@ def _register_secret_to_relation( | |
""" | ||
label = self._generate_secret_label(relation_name, relation_id, group) | ||
|
||
# Fetchin the Secret's meta information ensuring that it's locally getting registered with | ||
# Fetching the Secret's meta information ensuring that it's locally getting registered with | ||
CachedSecret(self._model, self.component, label, secret_id).meta | ||
|
||
def _register_secrets_to_relation(self, relation: Relation, params_name_list: List[str]): | ||
|
@@ -2309,7 +2309,7 @@ def _secrets(self) -> dict: | |
return self._cached_secrets | ||
|
||
def _get_secret(self, group) -> Optional[Dict[str, str]]: | ||
"""Retrieveing secrets.""" | ||
"""Retrieving secrets.""" | ||
if not self.app: | ||
return | ||
if not self._secrets.get(group): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Underlying logic: Normally this helper field is to hold the URI of a secret (in case the secret was newly created, or fetched by URI).
At this point, we are switching the
self
(CachedSecret) object to point to a new secret object (that's associated with the new label).Thus we have to "unlink" the object from the old URI. (Otherwise new secret creation is blocked: as the error in https://warthogs.atlassian.net/browse/DPE-4416 was indicating so.)