@@ -320,7 +320,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
320
320
321
321
# Increment this PATCH version before using `charmcraft publish-lib` or reset
322
322
# to 0 if you are raising the major API version
323
- LIBPATCH = 26
323
+ LIBPATCH = 27
324
324
325
325
PYDEPS = ["ops>=2.0.0" ]
326
326
@@ -422,15 +422,15 @@ def diff(event: RelationChangedEvent, bucket: Union[Unit, Application]) -> Diff:
422
422
)
423
423
424
424
# These are the keys that were added to the databag and triggered this event.
425
- added = new_data .keys () - old_data .keys () # pyright: ignore [reportGeneralTypeIssues ]
425
+ added = new_data .keys () - old_data .keys () # pyright: ignore [reportAssignmentType ]
426
426
# These are the keys that were removed from the databag and triggered this event.
427
- deleted = old_data .keys () - new_data .keys () # pyright: ignore [reportGeneralTypeIssues ]
427
+ deleted = old_data .keys () - new_data .keys () # pyright: ignore [reportAssignmentType ]
428
428
# These are the keys that already existed in the databag,
429
429
# but had their values changed.
430
430
changed = {
431
431
key
432
- for key in old_data .keys () & new_data .keys () # pyright: ignore [reportGeneralTypeIssues ]
433
- if old_data [key ] != new_data [key ] # pyright: ignore [reportGeneralTypeIssues ]
432
+ for key in old_data .keys () & new_data .keys () # pyright: ignore [reportAssignmentType ]
433
+ if old_data [key ] != new_data [key ] # pyright: ignore [reportAssignmentType ]
434
434
}
435
435
# Convert the new_data to a serializable format and save it for a next diff check.
436
436
set_encoded_field (event .relation , bucket , "data" , new_data )
@@ -1619,7 +1619,8 @@ def _delete_relation_data(self, relation: Relation, fields: List[str]) -> None:
1619
1619
current_data .get (relation .id , [])
1620
1620
):
1621
1621
logger .error (
1622
- "Non-existing secret %s was attempted to be removed." , non_existent
1622
+ "Non-existing secret %s was attempted to be removed." ,
1623
+ ", " .join (non_existent ),
1623
1624
)
1624
1625
1625
1626
_ , normal_fields = self ._process_secret_fields (
@@ -1686,12 +1687,8 @@ def extra_user_roles(self) -> Optional[str]:
1686
1687
return self .relation .data [self .relation .app ].get ("extra-user-roles" )
1687
1688
1688
1689
1689
- class AuthenticationEvent (RelationEvent ):
1690
- """Base class for authentication fields for events.
1691
-
1692
- The amount of logic added here is not ideal -- but this was the only way to preserve
1693
- the interface when moving to Juju Secrets
1694
- """
1690
+ class RelationEventWithSecret (RelationEvent ):
1691
+ """Base class for Relation Events that need to handle secrets."""
1695
1692
1696
1693
@property
1697
1694
def _secrets (self ) -> dict :
@@ -1703,18 +1700,6 @@ def _secrets(self) -> dict:
1703
1700
self ._cached_secrets = {}
1704
1701
return self ._cached_secrets
1705
1702
1706
- @property
1707
- def _jujuversion (self ) -> JujuVersion :
1708
- """Caching jujuversion to avoid a Juju call on each field evaluation.
1709
-
1710
- DON'T USE the encapsulated helper variable outside of this function
1711
- """
1712
- if not hasattr (self , "_cached_jujuversion" ):
1713
- self ._cached_jujuversion = None
1714
- if not self ._cached_jujuversion :
1715
- self ._cached_jujuversion = JujuVersion .from_environ ()
1716
- return self ._cached_jujuversion
1717
-
1718
1703
def _get_secret (self , group ) -> Optional [Dict [str , str ]]:
1719
1704
"""Retrieveing secrets."""
1720
1705
if not self .app :
@@ -1730,7 +1715,15 @@ def _get_secret(self, group) -> Optional[Dict[str, str]]:
1730
1715
@property
1731
1716
def secrets_enabled (self ):
1732
1717
"""Is this Juju version allowing for Secrets usage?"""
1733
- return self ._jujuversion .has_secrets
1718
+ return JujuVersion .from_environ ().has_secrets
1719
+
1720
+
1721
+ class AuthenticationEvent (RelationEventWithSecret ):
1722
+ """Base class for authentication fields for events.
1723
+
1724
+ The amount of logic added here is not ideal -- but this was the only way to preserve
1725
+ the interface when moving to Juju Secrets
1726
+ """
1734
1727
1735
1728
@property
1736
1729
def username (self ) -> Optional [str ]:
@@ -1813,7 +1806,7 @@ class DatabaseProvidesEvents(CharmEvents):
1813
1806
database_requested = EventSource (DatabaseRequestedEvent )
1814
1807
1815
1808
1816
- class DatabaseRequiresEvent (RelationEvent ):
1809
+ class DatabaseRequiresEvent (RelationEventWithSecret ):
1817
1810
"""Base class for database events."""
1818
1811
1819
1812
@property
@@ -1868,6 +1861,11 @@ def uris(self) -> Optional[str]:
1868
1861
if not self .relation .app :
1869
1862
return None
1870
1863
1864
+ if self .secrets_enabled :
1865
+ secret = self ._get_secret ("user" )
1866
+ if secret :
1867
+ return secret .get ("uris" )
1868
+
1871
1869
return self .relation .data [self .relation .app ].get ("uris" )
1872
1870
1873
1871
@property
@@ -1911,7 +1909,7 @@ class DatabaseRequiresEvents(CharmEvents):
1911
1909
class DatabaseProvides (DataProvides ):
1912
1910
"""Provider-side of the database relations."""
1913
1911
1914
- on = DatabaseProvidesEvents () # pyright: ignore [reportGeneralTypeIssues ]
1912
+ on = DatabaseProvidesEvents () # pyright: ignore [reportAssignmentType ]
1915
1913
1916
1914
def __init__ (self , charm : CharmBase , relation_name : str ) -> None :
1917
1915
super ().__init__ (charm , relation_name )
@@ -2006,7 +2004,7 @@ def set_version(self, relation_id: int, version: str) -> None:
2006
2004
class DatabaseRequires (DataRequires ):
2007
2005
"""Requires-side of the database relation."""
2008
2006
2009
- on = DatabaseRequiresEvents () # pyright: ignore [reportGeneralTypeIssues ]
2007
+ on = DatabaseRequiresEvents () # pyright: ignore [reportAssignmentType ]
2010
2008
2011
2009
def __init__ (
2012
2010
self ,
@@ -2335,7 +2333,7 @@ class KafkaRequiresEvents(CharmEvents):
2335
2333
class KafkaProvides (DataProvides ):
2336
2334
"""Provider-side of the Kafka relation."""
2337
2335
2338
- on = KafkaProvidesEvents () # pyright: ignore [reportGeneralTypeIssues ]
2336
+ on = KafkaProvidesEvents () # pyright: ignore [reportAssignmentType ]
2339
2337
2340
2338
def __init__ (self , charm : CharmBase , relation_name : str ) -> None :
2341
2339
super ().__init__ (charm , relation_name )
@@ -2396,7 +2394,7 @@ def set_zookeeper_uris(self, relation_id: int, zookeeper_uris: str) -> None:
2396
2394
class KafkaRequires (DataRequires ):
2397
2395
"""Requires-side of the Kafka relation."""
2398
2396
2399
- on = KafkaRequiresEvents () # pyright: ignore [reportGeneralTypeIssues ]
2397
+ on = KafkaRequiresEvents () # pyright: ignore [reportAssignmentType ]
2400
2398
2401
2399
def __init__ (
2402
2400
self ,
@@ -2533,7 +2531,7 @@ class OpenSearchRequiresEvents(CharmEvents):
2533
2531
class OpenSearchProvides (DataProvides ):
2534
2532
"""Provider-side of the OpenSearch relation."""
2535
2533
2536
- on = OpenSearchProvidesEvents () # pyright: ignore[reportGeneralTypeIssues ]
2534
+ on = OpenSearchProvidesEvents () # pyright: ignore[reportAssignmentType ]
2537
2535
2538
2536
def __init__ (self , charm : CharmBase , relation_name : str ) -> None :
2539
2537
super ().__init__ (charm , relation_name )
@@ -2586,7 +2584,7 @@ def set_version(self, relation_id: int, version: str) -> None:
2586
2584
class OpenSearchRequires (DataRequires ):
2587
2585
"""Requires-side of the OpenSearch relation."""
2588
2586
2589
- on = OpenSearchRequiresEvents () # pyright: ignore[reportGeneralTypeIssues ]
2587
+ on = OpenSearchRequiresEvents () # pyright: ignore[reportAssignmentType ]
2590
2588
2591
2589
def __init__ (
2592
2590
self ,
0 commit comments