Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def to_trino_auth(self):

model_cls = CLASSES_BY_AUTH_TYPE[auth_type]["auth_model"]
model = model_cls(**self.config)
return trino_auth_cls(**model.model_dump())
kwargs = {
field: value.get_secret_value() if isinstance(value, SecretStr) else value
for field, value in model.model_dump().items()
}
return trino_auth_cls(**kwargs)


class TrinoOfflineStoreConfig(FeastConfigBaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from pydantic import SecretStr
from trino.auth import BasicAuthentication, JWTAuthentication, OAuth2Authentication

from feast.infra.offline_stores.contrib.trino_offline_store.trino import (
CLASSES_BY_AUTH_TYPE,
AuthConfig,
FeastConfigBaseModel,
)


def test_jwt_auth_produces_plain_str_token():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker: While this test ensures OAuth2 auth still works, it could be enhanced to test a config with actual OAuth2 parameters to ensure non-SecretStr fields are handled correctly in the new code path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion - OAuth2 doesn't actually have any config parameters in CLASSES_BY_AUTH_TYPE (its auth_model is None, and to_trino_auth() short-circuits to trino_auth_cls() with no fields at all), so there's no non-SecretStr field handling to exercise on that path. The new test_to_trino_auth_unwraps_only_secret_fields_in_mixed_model and test_basic_auth_with_plain_fields_unaffected tests cover the non-SecretStr field handling instead.

auth = AuthConfig(type="jwt", config={"token": "my-secret-token"})

trino_auth = auth.to_trino_auth()

assert isinstance(trino_auth, JWTAuthentication)
assert trino_auth.token == "my-secret-token"
assert isinstance(trino_auth.token, str)


def test_oauth2_auth_unchanged():
auth = AuthConfig(type="oauth2", config=None)

trino_auth = auth.to_trino_auth()

assert isinstance(trino_auth, OAuth2Authentication)


def test_basic_auth_with_plain_fields_unaffected():
auth = AuthConfig(type="basic", config={"username": "alice", "password": "hunter2"})

trino_auth = auth.to_trino_auth()

assert isinstance(trino_auth, BasicAuthentication)
assert trino_auth._username == "alice"
assert trino_auth._password == "hunter2"


class _MixedAuthModel(FeastConfigBaseModel):
username: str
token: SecretStr


class _MixedAuth:
def __init__(self, username: str, token: str):
self.username = username
self.token = token


def test_to_trino_auth_unwraps_only_secret_fields_in_mixed_model(monkeypatch):
monkeypatch.setitem(
CLASSES_BY_AUTH_TYPE,
"jwt",
{"auth_model": _MixedAuthModel, "trino_auth": _MixedAuth},
)
auth = AuthConfig(
type="jwt", config={"username": "alice", "token": "my-secret-token"}
)

trino_auth = auth.to_trino_auth()

assert trino_auth.username == "alice"
assert trino_auth.token == "my-secret-token"
assert isinstance(trino_auth.username, str)
assert isinstance(trino_auth.token, str)
Loading