Skip to content
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

chore: Update charm libraries #70

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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 = 27
LIBPATCH = 28

PYDEPS = ["ops>=2.0.0"]

Expand Down Expand Up @@ -1796,6 +1796,17 @@ def database(self) -> Optional[str]:
class DatabaseRequestedEvent(DatabaseProvidesEvent, ExtraRoleEvent):
"""Event emitted when a new database is requested for use on this relation."""

@property
def external_node_connectivity(self) -> bool:
"""Returns the requested external_node_connectivity field."""
if not self.relation.app:
return False

return (
self.relation.data[self.relation.app].get("external-node-connectivity", "false")
== "true"
)


class DatabaseProvidesEvents(CharmEvents):
"""Database events.
Expand Down Expand Up @@ -2014,11 +2025,13 @@ def __init__(
extra_user_roles: Optional[str] = None,
relations_aliases: Optional[List[str]] = None,
additional_secret_fields: Optional[List[str]] = [],
external_node_connectivity: bool = False,
):
"""Manager of database client relations."""
super().__init__(charm, relation_name, extra_user_roles, additional_secret_fields)
self.database = database_name
self.relations_aliases = relations_aliases
self.external_node_connectivity = external_node_connectivity

# Define custom event names for each alias.
if relations_aliases:
Expand Down Expand Up @@ -2169,16 +2182,16 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
if not self.local_unit.is_leader():
return

event_data = {"database": self.database}

if self.extra_user_roles:
self.update_relation_data(
event.relation.id,
{
"database": self.database,
"extra-user-roles": self.extra_user_roles,
},
)
else:
self.update_relation_data(event.relation.id, {"database": self.database})
event_data["extra-user-roles"] = self.extra_user_roles

# set external-node-connectivity field
if self.external_node_connectivity:
event_data["external-node-connectivity"] = "true"

self.update_relation_data(event.relation.id, event_data)

def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
"""Event emitted when the database relation has changed."""
Expand Down
Loading