Skip to content

Commit

Permalink
feat: glauth-auxiliary interface integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wood-push-melon committed Jan 9, 2024
1 parent 324c06a commit 9a08e17
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
rev: v0.1.11
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 4 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ provides:
description: |
Provides LDAP configuration data
interface: ldap
glauth-auxiliary:
description: |
Provides auxiliary data for glauth-utils charmed operator
interface: glauth_auxiliary
25 changes: 24 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DatabaseRequires,
)
from charms.glauth_k8s.v0.ldap import LdapProvider, LdapRequestedEvent
from charms.glauth_utils.v0.glauth_auxiliary import AuxiliaryProvider, AuxiliaryRequestedEvent
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer, PromtailDigestError
from charms.observability_libs.v0.kubernetes_service_patch import KubernetesServicePatch
Expand All @@ -31,7 +32,7 @@
PROMETHEUS_SCRAPE_INTEGRATION_NAME,
WORKLOAD_CONTAINER,
)
from integrations import LdapIntegration
from integrations import AuxiliaryIntegration, LdapIntegration
from kubernetes_resource import ConfigMapResource, StatefulSetResource
from lightkube import Client
from ops.charm import (
Expand Down Expand Up @@ -81,6 +82,12 @@ def __init__(self, *args: Any):
self._on_ldap_requested,
)

self.auxiliary_provider = AuxiliaryProvider(self)
self.framework.observe(
self.auxiliary_provider.on.auxiliary_requested,
self._on_auxiliary_requested,
)

self.service_patcher = KubernetesServicePatch(self, [("ldap", GLAUTH_LDAP_PORT)])

self.loki_consumer = LogProxyConsumer(
Expand Down Expand Up @@ -113,6 +120,7 @@ def __init__(self, *args: Any):

self.config_file = ConfigFile(base_dn=self.config.get("base_dn"))
self._ldap_integration = LdapIntegration(self)
self._auxiliary_integration = AuxiliaryIntegration(self)

@after_config_updated
def _restart_glauth_service(self) -> None:
Expand Down Expand Up @@ -179,12 +187,20 @@ def _on_remove(self, event: RemoveEvent) -> None:
def _on_database_created(self, event: DatabaseCreatedEvent) -> None:
self.config_file.database_config = DatabaseConfig.load(self.database_requirer)
self._update_glauth_config()

self._container.add_layer(WORKLOAD_CONTAINER, pebble_layer, combine=True)
self._restart_glauth_service()
self.unit.status = ActiveStatus()

self.auxiliary_provider.update_relation_app_data(
data=self._auxiliary_integration.auxiliary_data,
)

def _on_database_changed(self, event: DatabaseEndpointsChangedEvent) -> None:
self._handle_event_update(event)
self.auxiliary_provider.update_relation_app_data(
data=self._auxiliary_integration.auxiliary_data,
)

def _on_config_changed(self, event: ConfigChangedEvent) -> None:
self.config_file.base_dn = self.config.get("base_dn")
Expand Down Expand Up @@ -215,6 +231,13 @@ def _on_ldap_requested(self, event: LdapRequestedEvent) -> None:
data=self._ldap_integration.provider_data,
)

@validate_database_resource
def _on_auxiliary_requested(self, event: AuxiliaryRequestedEvent) -> None:
self.auxiliary_provider.update_relation_app_data(
relation_id=event.relation.id,
data=self._auxiliary_integration.auxiliary_data,
)

def _on_promtail_error(self, event: PromtailDigestError) -> None:
logger.error(event.message)

Expand Down
17 changes: 17 additions & 0 deletions src/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional

from charms.glauth_k8s.v0.ldap import LdapProviderBaseData, LdapProviderData
from charms.glauth_utils.v0.glauth_auxiliary import AuxiliaryData
from configs import DatabaseConfig
from constants import DEFAULT_GID, DEFAULT_UID, GLAUTH_LDAP_PORT
from database import Capability, Group, Operation, User
Expand Down Expand Up @@ -81,3 +82,19 @@ def provider_data(self) -> Optional[LdapProviderData]:
auth_method="simple",
starttls=True,
)


class AuxiliaryIntegration:
def __init__(self, charm: CharmBase):
self._charm = charm

@property
def auxiliary_data(self) -> AuxiliaryData:
database_config = DatabaseConfig.load(self._charm.database_requirer)

return AuxiliaryData(
database=database_config.database,
endpoint=database_config.endpoint,
username=database_config.username,
password=database_config.password,
)

0 comments on commit 9a08e17

Please sign in to comment.