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

[DPE-4212] Extend s3-integrator to watch for new applications #33

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 18 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@
logger = logging.getLogger(__name__)


S3_RELATION = "s3-credentials"


class S3IntegratorCharm(ops.charm.CharmBase):
"""Charm for s3 integrator service."""

def __init__(self, *args) -> None:
super().__init__(*args)
self.s3_provider = S3Provider(self, "s3-credentials")
self.s3_provider = S3Provider(self, S3_RELATION)
self.framework.observe(self.on.start, self._on_start)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(
self.s3_provider.on.credentials_requested, self._on_credential_requested
)
self.framework.observe(self.on[PEER].relation_changed, self._on_peer_relation_changed)

self.framework.observe(self.on[S3_RELATION].relation_created, self._on_new_app)

# actions
self.framework.observe(self.on.sync_s3_credentials_action, self._on_sync_s3_credentials)
self.framework.observe(self.on.get_s3_credentials_action, self.on_get_credentials_action)
Expand Down Expand Up @@ -68,8 +74,9 @@ def _on_start(self, _: StartEvent) -> None:
if missing_options:
self.unit.status = ops.model.BlockedStatus(f"Missing parameters: {missing_options}")

def _on_config_changed(self, _: ConfigChangedEvent) -> None:
"""Event handler for configuration changed events."""
@property
def _current_configs(self) -> dict[str, str]:
"""Returns the current configuration of s3-integrator."""
# Only execute in the unit leader
if not self.unit.is_leader():
return
Expand Down Expand Up @@ -105,10 +112,17 @@ def _on_config_changed(self, _: ConfigChangedEvent) -> None:
else:
update_config.update({option: self.config[option]})
self.set_secret("app", option, self.config[option])
return update_config

def _on_new_app(self, event) -> None:
"""Event handler for s3-credentials-created events."""
self.s3_provider.update_connection_info(event.relation.id, self._current_configs)

def _on_config_changed(self, _: ConfigChangedEvent) -> None:
"""Event handler for configuration changed events."""
if len(self.s3_provider.relations) > 0:
for relation in self.s3_provider.relations:
self.s3_provider.update_connection_info(relation.id, update_config)
self.s3_provider.update_connection_info(relation.id, self._current_configs)

def _on_credential_requested(self, event: CredentialRequestedEvent):
"""Handle the `credential-requested` event."""
Expand Down
Loading