Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pydantic ImportString for oauth_cb in ConnectionConfig #679

Closed
mkp-jansen opened this issue Dec 9, 2024 · 5 comments
Closed

Pydantic ImportString for oauth_cb in ConnectionConfig #679

mkp-jansen opened this issue Dec 9, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@mkp-jansen
Copy link
Contributor

Is your feature request related to a problem? Please describe.
We would like to configure our Quix applications with OAuth authentication through YAML files. For example:

quix-app:
  broker_address:
    bootstrap_servers: localhost:9092
    security_protocol: sasl_ssl
    sasl_mechanism: OAUTHBEARER
  consumer_group: quix-consumer
  auto_offset_reset: earliest

Currently, this can easily be achieved with something like this:

# in my_module.py
def my_oauth_cb(config: str) -> Tuple[str, float]:
    # get token with config
    return "token", 1.0

with open("config.yml") as f:
    config = yaml.safe_load(f)

# setting oauth_cb in the code
config["quix-app"]["broker_address"]["oauth_cb"] = my_oauth_cb

app = Application(
    **config["quix-app"]
)

However, passing the oauth_cb function has to be done in the code. It would be beneficial if we could specify the callback via Pydantic's ImportString directly from the YAML file. For example:

quix-app:
  broker_address:
    ...
    oauth_cb: my_module.my_oauth_cb
    ...

Only a minor adjustment in quixstreams/kafka/configuration.py would be necessary - without impacting any existing functionality:

# file: quixstreams/kafka/configuration.py - lines: 55 - 62
oauth_cb: Optional[Union[Callable[[str], Tuple[str, float]], ImportString]] = (
    pydantic.Field(
        # Prevent the AliasGenerator from changing the field name to "oauth.cb"
        default=None,
        alias_priority=2,
        serialization_alias="oauth_cb",
    )
)

If it is OK, I would create a PR for the feature.

@mkp-jansen
Copy link
Contributor Author

#680

@daniil-quix
Copy link
Collaborator

Hey @mkp-jansen !
The change makes sense to me.
I'll review the PR 👍

@daniil-quix
Copy link
Collaborator

It's merged 👍
I'll drop a comment here when it's released

@mkp-jansen
Copy link
Contributor Author

thanks, again!

@daniil-quix
Copy link
Collaborator

Released in v3.5.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants