Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit 8b3d811

Browse files
authoredNov 21, 2023
chore: update charm libraries (#71)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 84de422 commit 8b3d811

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed
 

‎lib/charms/data_platform_libs/v0/data_interfaces.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
320320

321321
# Increment this PATCH version before using `charmcraft publish-lib` or reset
322322
# to 0 if you are raising the major API version
323-
LIBPATCH = 23
323+
LIBPATCH = 24
324324

325325
PYDEPS = ["ops>=2.0.0"]
326326

@@ -526,7 +526,16 @@ def get_content(self) -> Dict[str, str]:
526526
"""Getting cached secret content."""
527527
if not self._secret_content:
528528
if self.meta:
529-
self._secret_content = self.meta.get_content()
529+
try:
530+
self._secret_content = self.meta.get_content(refresh=True)
531+
except (ValueError, ModelError) as err:
532+
# https://bugs.launchpad.net/juju/+bug/2042596
533+
# Only triggered when 'refresh' is set
534+
msg = "ERROR either URI or label should be used for getting an owned secret but not both"
535+
if isinstance(err, ModelError) and msg not in str(err):
536+
raise
537+
# Due to: ValueError: Secret owner cannot use refresh=True
538+
self._secret_content = self.meta.get_content()
530539
return self._secret_content
531540

532541
def set_content(self, content: Dict[str, str]) -> None:
@@ -1085,7 +1094,7 @@ def _delete_relation_secret(
10851094
secret = self._get_relation_secret(relation.id, group)
10861095

10871096
if not secret:
1088-
logging.error("Can't update secret for relation %s", str(relation.id))
1097+
logging.error("Can't delete secret for relation %s", str(relation.id))
10891098
return False
10901099

10911100
old_content = secret.get_content()
@@ -1827,7 +1836,8 @@ def _assign_relation_alias(self, relation_id: int) -> None:
18271836

18281837
# We need to set relation alias also on the application level so,
18291838
# it will be accessible in show-unit juju command, executed for a consumer application unit
1830-
self.update_relation_data(relation_id, {"alias": available_aliases[0]})
1839+
if self.local_unit.is_leader():
1840+
self.update_relation_data(relation_id, {"alias": available_aliases[0]})
18311841

18321842
def _emit_aliased_event(self, event: RelationChangedEvent, event_name: str) -> None:
18331843
"""Emit an aliased event to a particular relation if it has an alias.
@@ -1914,6 +1924,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
19141924

19151925
# Sets both database and extra user roles in the relation
19161926
# if the roles are provided. Otherwise, sets only the database.
1927+
if not self.local_unit.is_leader():
1928+
return
1929+
19171930
if self.extra_user_roles:
19181931
self.update_relation_data(
19191932
event.relation.id,
@@ -2173,6 +2186,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
21732186
"""Event emitted when the Kafka relation is created."""
21742187
super()._on_relation_created_event(event)
21752188

2189+
if not self.local_unit.is_leader():
2190+
return
2191+
21762192
# Sets topic, extra user roles, and "consumer-group-prefix" in the relation
21772193
relation_data = {
21782194
f: getattr(self, f.replace("-", "_"), "")
@@ -2345,6 +2361,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
23452361
"""Event emitted when the OpenSearch relation is created."""
23462362
super()._on_relation_created_event(event)
23472363

2364+
if not self.local_unit.is_leader():
2365+
return
2366+
23482367
# Sets both index and extra user roles in the relation if the roles are provided.
23492368
# Otherwise, sets only the index.
23502369
data = {"index": self.index}

0 commit comments

Comments
 (0)
This repository has been archived.