Skip to content

Commit 3114e95

Browse files
chore: update charm libraries (#263)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Yanks Yoon <[email protected]>
1 parent 266f742 commit 3114e95

File tree

3 files changed

+560
-412
lines changed

3 files changed

+560
-412
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 39
334+
LIBPATCH = 41
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -391,6 +391,10 @@ class IllegalOperationError(DataInterfacesError):
391391
"""To be used when an operation is not allowed to be performed."""
392392

393393

394+
class PrematureDataAccessError(DataInterfacesError):
395+
"""To be raised when the Relation Data may be accessed (written) before protocol init complete."""
396+
397+
394398
##############################################################################
395399
# Global helpers / utilities
396400
##############################################################################
@@ -605,7 +609,7 @@ def get_group(self, group: str) -> Optional[SecretGroup]:
605609
class CachedSecret:
606610
"""Locally cache a secret.
607611
608-
The data structure is precisely re-using/simulating as in the actual Secret Storage
612+
The data structure is precisely reusing/simulating as in the actual Secret Storage
609613
"""
610614

611615
KNOWN_MODEL_ERRORS = [MODEL_ERRORS["no_label_and_uri"], MODEL_ERRORS["owner_no_refresh"]]
@@ -1453,6 +1457,8 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
14531457
class ProviderData(Data):
14541458
"""Base provides-side of the data products relation."""
14551459

1460+
RESOURCE_FIELD = "database"
1461+
14561462
def __init__(
14571463
self,
14581464
model: Model,
@@ -1618,6 +1624,15 @@ def _fetch_my_specific_relation_data(
16181624
def _update_relation_data(self, relation: Relation, data: Dict[str, str]) -> None:
16191625
"""Set values for fields not caring whether it's a secret or not."""
16201626
req_secret_fields = []
1627+
1628+
keys = set(data.keys())
1629+
if self.fetch_relation_field(relation.id, self.RESOURCE_FIELD) is None and (
1630+
keys - {"endpoints", "read-only-endpoints", "replset"}
1631+
):
1632+
raise PrematureDataAccessError(
1633+
"Premature access to relation data, update is forbidden before the connection is initialized."
1634+
)
1635+
16211636
if relation.app:
16221637
req_secret_fields = get_encoded_list(relation, relation.app, REQ_SECRET_FIELDS)
16231638

@@ -2348,7 +2363,6 @@ def _update_relation_data(self, relation: Relation, data: Dict[str, str]) -> Non
23482363
def _delete_relation_data(self, relation: Relation, fields: List[str]) -> None:
23492364
"""Delete data available (directily or indirectly -- i.e. secrets) from the relation for owner/this_app."""
23502365
if self.secret_fields and self.deleted_label:
2351-
23522366
_, normal_fields = self._process_secret_fields(
23532367
relation,
23542368
self.secret_fields,
@@ -3290,6 +3304,8 @@ class KafkaRequiresEvents(CharmEvents):
32903304
class KafkaProviderData(ProviderData):
32913305
"""Provider-side of the Kafka relation."""
32923306

3307+
RESOURCE_FIELD = "topic"
3308+
32933309
def __init__(self, model: Model, relation_name: str) -> None:
32943310
super().__init__(model, relation_name)
32953311

@@ -3539,6 +3555,8 @@ class OpenSearchRequiresEvents(CharmEvents):
35393555
class OpenSearchProvidesData(ProviderData):
35403556
"""Provider-side of the OpenSearch relation."""
35413557

3558+
RESOURCE_FIELD = "index"
3559+
35423560
def __init__(self, model: Model, relation_name: str) -> None:
35433561
super().__init__(model, relation_name)
35443562

0 commit comments

Comments
 (0)