forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ingestion/kafka): OAuth callback execution (datahub-project#11900)
- Loading branch information
Showing
15 changed files
with
183 additions
and
26 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
metadata-ingestion/src/datahub/configuration/kafka_consumer_config.py
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,35 @@ | ||
import logging | ||
from typing import Any, Dict, Optional | ||
|
||
from datahub.ingestion.api.registry import import_path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CallableConsumerConfig: | ||
CALLBACK_ATTRIBUTE: str = "oauth_cb" | ||
|
||
def __init__(self, config: Dict[str, Any]): | ||
self._config = config | ||
|
||
self._resolve_oauth_callback() | ||
|
||
def callable_config(self) -> Dict[str, Any]: | ||
return self._config | ||
|
||
@staticmethod | ||
def is_callable_config(config: Dict[str, Any]) -> bool: | ||
return CallableConsumerConfig.CALLBACK_ATTRIBUTE in config | ||
|
||
def get_call_back_attribute(self) -> Optional[str]: | ||
return self._config.get(CallableConsumerConfig.CALLBACK_ATTRIBUTE) | ||
|
||
def _resolve_oauth_callback(self) -> None: | ||
if not self.get_call_back_attribute(): | ||
return | ||
|
||
call_back = self.get_call_back_attribute() | ||
|
||
assert call_back # to silent lint | ||
# Set the callback | ||
self._config[CallableConsumerConfig.CALLBACK_ATTRIBUTE] = import_path(call_back) |
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
Empty file.
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
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
metadata-ingestion/tests/integration/kafka/kafka_to_file_oauth.yml
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,20 @@ | ||
run_id: kafka-test | ||
|
||
source: | ||
type: kafka | ||
config: | ||
connection: | ||
bootstrap: "localhost:29092" | ||
schema_registry_url: "http://localhost:28081" | ||
consumer_config: | ||
security.protocol: "SASL_PLAINTEXT" | ||
sasl.mechanism: "OAUTHBEARER" | ||
oauth_cb: "oauth:create_token" | ||
domain: | ||
"urn:li:domain:sales": | ||
allow: | ||
- "key_value_topic" | ||
sink: | ||
type: file | ||
config: | ||
filename: "./kafka_mces.json" |
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,14 @@ | ||
import logging | ||
from typing import Any, Tuple | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
MESSAGE: str = "OAuth token `create_token` callback" | ||
|
||
|
||
def create_token(*args: Any, **kwargs: Any) -> Tuple[str, int]: | ||
logger.warning(MESSAGE) | ||
return ( | ||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRfaWQiOiJrYWZrYV9jbGllbnQiLCJleHAiOjE2OTg3NjYwMDB9.dummy_sig_abcdef123456", | ||
3600, | ||
) |
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