Skip to content

Commit bbafb5f

Browse files
committed
Fix token processing in validation
1 parent b01005f commit bbafb5f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

simvue/config/parameters.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ def url_to_str(cls, v: typing.Any) -> str:
3131

3232
@pydantic.field_validator("token")
3333
def check_token(cls, v: typing.Any) -> str:
34-
if not (expiry := get_expiry(v)):
34+
value = v.get_secret_value()
35+
if not (expiry := get_expiry(value)):
3536
raise AssertionError("Failed to parse Simvue token - invalid token form")
3637
if time.time() - expiry > 0:
3738
raise AssertionError("Simvue token has expired")
38-
return v
39+
return value
3940

4041
@pydantic.model_validator(mode="after")
41-
def check_valid_server(cls, values: dict) -> bool:
42-
url = values["url"]
43-
token = values["token"]
42+
@classmethod
43+
def check_valid_server(cls, values: "ServerSpecifications") -> bool:
4444
headers: dict[str, str] = {
45-
"Authorization": f"Bearer {token}",
45+
"Authorization": f"Bearer {values.token}",
4646
"User-Agent": f"Simvue Python client {__version__}",
4747
}
4848
try:
49-
response = get(f"{url}/api/version", headers)
49+
response = get(f"{values.url}/api/version", headers)
5050

5151
if response.status_code != http.HTTPStatus.OK or not response.json().get(
5252
"version"
@@ -59,6 +59,8 @@ def check_valid_server(cls, values: dict) -> bool:
5959
except Exception as err:
6060
raise AssertionError(f"Exception retrieving server version: {str(err)}")
6161

62+
return values
63+
6264

6365
class DefaultRunSpecifications(pydantic.BaseModel):
6466
description: typing.Optional[str] = None

0 commit comments

Comments
 (0)