-
Notifications
You must be signed in to change notification settings - Fork 304
Python SDK: Use HatchetConfigurationError for invalid token validation #3017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c4188e4
a313760
b26d68e
7dd9658
29820f3
de43b9e
c82ef9e
7075531
269bf4b
5fb39db
1a2eeea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from pydantic import Field, field_validator, model_validator | ||
| from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
|
||
| from hatchet_sdk.exceptions import HatchetConfigurationError | ||
mrkaye97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from hatchet_sdk.token import get_addresses_from_jwt, get_tenant_id_from_jwt | ||
| from hatchet_sdk.utils.opentelemetry import OTelAttribute | ||
|
|
||
|
|
@@ -48,15 +49,13 @@ class HealthcheckConfig(BaseSettings): | |
| def validate_event_loop_block_threshold_seconds( | ||
| cls, value: timedelta | int | float | str | ||
| ) -> timedelta: | ||
| # Settings env vars are strings; interpret as seconds. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's leave this comment |
||
| if isinstance(value, timedelta): | ||
| return value | ||
|
|
||
| if isinstance(value, int | float): | ||
| return timedelta(seconds=float(value)) | ||
|
|
||
| v = value.strip() | ||
| # Allow a small convenience suffix, but keep "seconds" as the contract. | ||
| if v.endswith("s"): | ||
| v = v[:-1].strip() | ||
|
|
||
|
|
@@ -138,11 +137,15 @@ class ClientConfig(BaseSettings): | |
| @model_validator(mode="after") | ||
| def validate_token_and_tenant(self) -> "ClientConfig": | ||
| if not self.token: | ||
| raise ValueError("Token must be set") | ||
| raise HatchetConfigurationError( | ||
| "HATCHET_CLIENT_TOKEN must be set. " | ||
| "Provide it via environment variable or pass token=... to ClientConfig." | ||
| ) | ||
|
Comment on lines
139
to
+143
|
||
|
|
||
| if not self.token.startswith("ey"): | ||
| raise ValueError( | ||
| f"Token must be a valid JWT. Hint: These are the first few characters of the token provided: {self.token[:5]}" | ||
| raise HatchetConfigurationError( | ||
| "HATCHET_CLIENT_TOKEN must be a valid JWT. " | ||
| f"Received token starting with: '{self.token[:5]}...'" | ||
| ) | ||
|
Comment on lines
137
to
149
|
||
|
|
||
| if not self.tenant_id: | ||
|
|
@@ -152,8 +155,6 @@ def validate_token_and_tenant(self) -> "ClientConfig": | |
|
|
||
| @model_validator(mode="after") | ||
| def validate_addresses(self) -> "ClientConfig": | ||
| ## If nothing is set, read from the token | ||
| ## If either is set, override what's in the JWT | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's leave these comments |
||
| server_url_from_jwt, grpc_broadcast_address_from_jwt = get_addresses_from_jwt( | ||
| self.token | ||
| ) | ||
|
Comment on lines
156
to
160
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |||||||||||||||||||||||||||||
| from typing import cast | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
4
to
5
|
||||||||||||||||||||||||||||||
| __all__ = [ | |
| "HatchetConfigurationError", | |
| "InvalidDependencyError", | |
| "NonRetryableException", | |
| "DedupeViolationError", | |
| "TASK_RUN_ERROR_METADATA_KEY", | |
| "TaskRunError", | |
| "FailedTaskRunExceptionGroup", | |
| "LoopAlreadyRunningError", | |
| "IllegalTaskOutputError", | |
| "LifespanSetupError", | |
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry appears to (1) change the heading level from
### Changedto#### Changed(inconsistent with other entries) and (2) replace prior 1.23.4 bullets with new ones that mention changes (e.g., patch version bump / validator updates) that aren’t present in this PR. Please keep the changelog formatting consistent and ensure the 1.23.4 notes accurately reflect the actual code changes in this PR.