Skip to content

Commit

Permalink
Merge branch 'main' into TELCO-952-Add-terraform-module
Browse files Browse the repository at this point in the history
  • Loading branch information
gatici authored Feb 12, 2024
2 parents 94b7b47 + d037535 commit 3628395
Showing 1 changed file with 23 additions and 10 deletions.
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

0 comments on commit 3628395

Please sign in to comment.