Skip to content

Commit 2b4b259

Browse files
authored
feat(sdk): hacky way to set extra headers for the gql client (wandb#5237)
1 parent 1cdafd4 commit 2b4b259

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

wandb/sdk/internal/internal_api.py

+12
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class DefaultSettings(TypedDict):
8787
api_key: Optional[str]
8888
entity: Optional[str]
8989
project: Optional[str]
90+
_extra_http_headers: Optional[Mapping[str, str]]
9091

9192
_Response = MutableMapping
9293
SweepState = Literal["RUNNING", "PAUSED", "CANCELED", "FINISHED"]
@@ -178,6 +179,7 @@ def __init__(
178179
"api_key": None,
179180
"entity": None,
180181
"project": None,
182+
"_extra_http_headers": None,
181183
}
182184
self.retry_timedelta = retry_timedelta
183185
# todo: Old Settings do not follow the SupportsKeysAndGetItem Protocol
@@ -194,12 +196,22 @@ def __init__(
194196
"system_samples": 15,
195197
"heartbeat_seconds": 30,
196198
}
199+
200+
# todo: remove this hacky hack after settings refactor is complete
201+
# keeping this code here to limit scope and so that it is easy to remove later
202+
extra_http_headers = self.settings(
203+
"_extra_http_headers"
204+
) or wandb.sdk.wandb_settings._str_as_dict(
205+
self._environ.get("WANDB__EXTRA_HTTP_HEADERS", {})
206+
)
207+
197208
self.client = Client(
198209
transport=GraphQLSession(
199210
headers={
200211
"User-Agent": self.user_agent,
201212
"X-WANDB-USERNAME": env.get_username(env=self._environ),
202213
"X-WANDB-USER-EMAIL": env.get_user_email(env=self._environ),
214+
**extra_http_headers,
203215
},
204216
use_json=True,
205217
# this timeout won't apply when the DNS lookup fails. in that case, it will be 60s

wandb/sdk/internal/settings_static.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SettingsStatic:
6262
_flow_control_custom: bool
6363
disable_job_creation: bool
6464
_async_upload_concurrency_limit: Optional[int]
65+
_extra_http_headers: Optional[Mapping[str, str]]
6566

6667
# TODO(jhr): clean this up, it is only in SettingsStatic and not in Settings
6768
_log_level: int

wandb/sdk/lib/_settings_toposort_generated.py

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wandb/sdk/wandb_settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ class Settings:
395395
_disable_viewer: bool # Prevent early viewer query
396396
_except_exit: bool
397397
_executable: str
398+
_extra_http_headers: Mapping[str, str]
398399
_flow_control_custom: bool
399400
_flow_control_disabled: bool
400401
_internal_check_process: Union[int, float]
@@ -540,6 +541,7 @@ def _default_props(self) -> Dict[str, Dict[str, Any]]:
540541
},
541542
_disable_stats={"preprocessor": _str_as_bool},
542543
_disable_viewer={"preprocessor": _str_as_bool},
544+
_extra_http_headers={"preprocessor": _str_as_dict},
543545
_network_buffer={"preprocessor": int},
544546
_colab={
545547
"hook": lambda _: "google.colab" in sys.modules,

0 commit comments

Comments
 (0)