Skip to content

Commit 1c47308

Browse files
Update Desktop API Stainless config
1 parent 1d8fdca commit 1c47308

3 files changed

Lines changed: 54 additions & 27 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 72
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/beeper/beeper-desktop-api-de1370e6a3183044fa135a886d2ee8f779d5e86228cdbd503d553b4c13cc7cbe.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/beeper/beeper-desktop-api-8ba2755730c4180ec88f92a300948445d7917898abfc912ca3fa6adc766a7520.yml
33
openapi_spec_hash: 30b435d7585d8b6951610e7147369779
4-
config_hash: 683b13ea6fb6aa9d6b1b8814cca24f1c
4+
config_hash: a53888715ed00d433e5a5dafab9f7b9f

src/beeper_desktop_api/_client.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
async_to_streamed_response_wrapper,
4242
)
4343
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
44-
from ._exceptions import APIStatusError, BeeperDesktopError
44+
from ._exceptions import APIStatusError
4545
from ._base_client import (
4646
DEFAULT_MAX_RETRIES,
4747
SyncAPIClient,
@@ -76,7 +76,7 @@
7676

7777
class BeeperDesktop(SyncAPIClient):
7878
# client options
79-
access_token: str
79+
access_token: str | None
8080

8181
def __init__(
8282
self,
@@ -107,10 +107,6 @@ def __init__(
107107
"""
108108
if access_token is None:
109109
access_token = os.environ.get("BEEPER_ACCESS_TOKEN")
110-
if access_token is None:
111-
raise BeeperDesktopError(
112-
"The access_token client option must be set either by passing access_token to the client or by setting the BEEPER_ACCESS_TOKEN environment variable"
113-
)
114110
self.access_token = access_token
115111

116112
if base_url is None:
@@ -219,6 +215,8 @@ def _auth_headers(self, security: SecurityOptions) -> dict[str, str]:
219215
@property
220216
def _bearer_auth(self) -> dict[str, str]:
221217
access_token = self.access_token
218+
if access_token is None:
219+
return {}
222220
return {"Authorization": f"Bearer {access_token}"}
223221

224222
@property
@@ -230,6 +228,15 @@ def default_headers(self) -> dict[str, str | Omit]:
230228
**self._custom_headers,
231229
}
232230

231+
@override
232+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
233+
if headers.get("Authorization") or isinstance(custom_headers.get("Authorization"), Omit):
234+
return
235+
236+
raise TypeError(
237+
'"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
238+
)
239+
233240
def copy(
234241
self,
235242
*,
@@ -409,7 +416,7 @@ def _make_status_error(
409416

410417
class AsyncBeeperDesktop(AsyncAPIClient):
411418
# client options
412-
access_token: str
419+
access_token: str | None
413420

414421
def __init__(
415422
self,
@@ -440,10 +447,6 @@ def __init__(
440447
"""
441448
if access_token is None:
442449
access_token = os.environ.get("BEEPER_ACCESS_TOKEN")
443-
if access_token is None:
444-
raise BeeperDesktopError(
445-
"The access_token client option must be set either by passing access_token to the client or by setting the BEEPER_ACCESS_TOKEN environment variable"
446-
)
447450
self.access_token = access_token
448451

449452
if base_url is None:
@@ -552,6 +555,8 @@ def _auth_headers(self, security: SecurityOptions) -> dict[str, str]:
552555
@property
553556
def _bearer_auth(self) -> dict[str, str]:
554557
access_token = self.access_token
558+
if access_token is None:
559+
return {}
555560
return {"Authorization": f"Bearer {access_token}"}
556561

557562
@property
@@ -563,6 +568,15 @@ def default_headers(self) -> dict[str, str | Omit]:
563568
**self._custom_headers,
564569
}
565570

571+
@override
572+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
573+
if headers.get("Authorization") or isinstance(custom_headers.get("Authorization"), Omit):
574+
return
575+
576+
raise TypeError(
577+
'"Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted"'
578+
)
579+
566580
def copy(
567581
self,
568582
*,

tests/test_client.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323
from beeper_desktop_api._types import Omit
2424
from beeper_desktop_api._utils import asyncify
2525
from beeper_desktop_api._models import BaseModel, FinalRequestOptions
26-
from beeper_desktop_api._exceptions import (
27-
APIStatusError,
28-
APITimeoutError,
29-
BeeperDesktopError,
30-
APIResponseValidationError,
31-
)
26+
from beeper_desktop_api._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
3227
from beeper_desktop_api._base_client import (
3328
DEFAULT_TIMEOUT,
3429
HTTPX_DEFAULT_TIMEOUT,
@@ -415,10 +410,19 @@ def test_validate_headers(self) -> None:
415410
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
416411
assert request.headers.get("Authorization") == f"Bearer {access_token}"
417412

418-
with pytest.raises(BeeperDesktopError):
419-
with update_env(**{"BEEPER_ACCESS_TOKEN": Omit()}):
420-
client2 = BeeperDesktop(base_url=base_url, access_token=None, _strict_response_validation=True)
421-
_ = client2
413+
with update_env(**{"BEEPER_ACCESS_TOKEN": Omit()}):
414+
client2 = BeeperDesktop(base_url=base_url, access_token=None, _strict_response_validation=True)
415+
416+
with pytest.raises(
417+
TypeError,
418+
match="Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted",
419+
):
420+
client2._build_request(FinalRequestOptions(method="get", url="/foo"))
421+
422+
request2 = client2._build_request(
423+
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
424+
)
425+
assert request2.headers.get("Authorization") is None
422426

423427
def test_default_query_option(self) -> None:
424428
client = BeeperDesktop(
@@ -1362,10 +1366,19 @@ def test_validate_headers(self) -> None:
13621366
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
13631367
assert request.headers.get("Authorization") == f"Bearer {access_token}"
13641368

1365-
with pytest.raises(BeeperDesktopError):
1366-
with update_env(**{"BEEPER_ACCESS_TOKEN": Omit()}):
1367-
client2 = AsyncBeeperDesktop(base_url=base_url, access_token=None, _strict_response_validation=True)
1368-
_ = client2
1369+
with update_env(**{"BEEPER_ACCESS_TOKEN": Omit()}):
1370+
client2 = AsyncBeeperDesktop(base_url=base_url, access_token=None, _strict_response_validation=True)
1371+
1372+
with pytest.raises(
1373+
TypeError,
1374+
match="Could not resolve authentication method. Expected the access_token to be set. Or for the `Authorization` headers to be explicitly omitted",
1375+
):
1376+
client2._build_request(FinalRequestOptions(method="get", url="/foo"))
1377+
1378+
request2 = client2._build_request(
1379+
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
1380+
)
1381+
assert request2.headers.get("Authorization") is None
13691382

13701383
async def test_default_query_option(self) -> None:
13711384
client = AsyncBeeperDesktop(

0 commit comments

Comments
 (0)