Skip to content

Commit

Permalink
Refactor read requests to accept a token for auth
Browse files Browse the repository at this point in the history
Validate passed token as an access token, rather than refresh
  • Loading branch information
NeonDaniel committed Nov 12, 2024
1 parent 1fc41c9 commit 66d5bbf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions neon_data_models/models/api/mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

from pydantic import Field, TypeAdapter, model_validator

from neon_data_models.models.api.jwt import HanaToken
from neon_data_models.models.base.contexts import MQContext
from neon_data_models.models.user.database import User, TokenConfig
from neon_data_models.models.user.database import User


class CreateUserRequest(MQContext):
Expand All @@ -43,16 +44,19 @@ class ReadUserRequest(MQContext):
auth_user_spec: str = Field(
default="", description="Username or ID to authorize database read. "
"If unset, this will use `user_spec`")
access_token: Optional[TokenConfig] = Field(
access_token: Optional[HanaToken] = Field(
None, description="Token associated with `auth_username`")
password: Optional[str] = Field(None,
description="Password associated with "
"`auth_username`")

@model_validator(mode="after")
def get_auth_username(self) -> 'ReadUserRequest':
def validate_params(self) -> 'ReadUserRequest':
if not self.auth_user_spec:
self.auth_user_spec = self.user_spec
if self.access_token and self.access_token.purpose != "access":
raise ValueError(f"Expected an access token but got: "
f"{self.access_token.purpose}")
return self


Expand Down

0 comments on commit 66d5bbf

Please sign in to comment.