-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Oauth config from the oauth interface (#77)
- Loading branch information
Showing
12 changed files
with
1,124 additions
and
61 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
"""Manager for handling Kafka OAuth configuration.""" | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from charms.hydra.v0.oauth import ClientConfig, OAuthRequirer | ||
from ops.framework import EventBase, Object | ||
|
||
from literals import OAUTH_REL_NAME | ||
|
||
if TYPE_CHECKING: | ||
from charm import KafkaCharm | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class OAuthHandler(Object): | ||
"""Handler for managing oauth relations.""" | ||
|
||
def __init__(self, charm): | ||
super().__init__(charm, "oauth") | ||
self.charm: "KafkaCharm" = charm | ||
|
||
client_config = ClientConfig("https://kafka.local", "openid email", ["client_credentials"]) | ||
self.oauth = OAuthRequirer(charm, client_config, relation_name=OAUTH_REL_NAME) | ||
self.framework.observe( | ||
self.charm.on[OAUTH_REL_NAME].relation_changed, self._on_oauth_relation_changed | ||
) | ||
self.framework.observe( | ||
self.charm.on[OAUTH_REL_NAME].relation_broken, self._on_oauth_relation_changed | ||
) | ||
|
||
def _on_oauth_relation_changed(self, event: EventBase) -> None: | ||
"""Handler for `_on_oauth_relation_changed` event.""" | ||
if not self.charm.unit.is_leader() or not self.charm.state.brokers: | ||
return | ||
self.charm._on_config_changed(event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.