Skip to content

Commit e27af94

Browse files
feat(api): update via SDK Studio
1 parent 48a5274 commit e27af94

File tree

4 files changed

+183
-52
lines changed

4 files changed

+183
-52
lines changed

Diff for: README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ The full API of this library can be found in [api.md](api.md).
2929
```python
3030
from gitpod import Gitpod
3131

32-
client = Gitpod()
32+
client = Gitpod(
33+
auth_token="My Auth Token",
34+
)
3335

3436
runner = client.runners.create(
3537
connect_protocol_version=1,
@@ -45,7 +47,9 @@ Simply import `AsyncGitpod` instead of `Gitpod` and use `await` with each API ca
4547
import asyncio
4648
from gitpod import AsyncGitpod
4749

48-
client = AsyncGitpod()
50+
client = AsyncGitpod(
51+
auth_token="My Auth Token",
52+
)
4953

5054

5155
async def main() -> None:
@@ -82,7 +86,9 @@ All errors inherit from `gitpod.APIError`.
8286
import gitpod
8387
from gitpod import Gitpod
8488

85-
client = Gitpod()
89+
client = Gitpod(
90+
auth_token="My Auth Token",
91+
)
8692

8793
try:
8894
client.runners.create(
@@ -127,6 +133,7 @@ from gitpod import Gitpod
127133
client = Gitpod(
128134
# default is 2
129135
max_retries=0,
136+
auth_token="My Auth Token",
130137
)
131138

132139
# Or, configure per-request:
@@ -147,11 +154,13 @@ from gitpod import Gitpod
147154
client = Gitpod(
148155
# 20 seconds (default is 1 minute)
149156
timeout=20.0,
157+
auth_token="My Auth Token",
150158
)
151159

152160
# More granular control:
153161
client = Gitpod(
154162
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
163+
auth_token="My Auth Token",
155164
)
156165

157166
# Override per-request:
@@ -197,7 +206,9 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
197206
```py
198207
from gitpod import Gitpod
199208

200-
client = Gitpod()
209+
client = Gitpod(
210+
auth_token="My Auth Token",
211+
)
201212
response = client.runners.with_raw_response.create(
202213
connect_protocol_version=1,
203214
)
@@ -282,6 +293,7 @@ client = Gitpod(
282293
proxy="http://my.test.proxy.example.com",
283294
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
284295
),
296+
auth_token="My Auth Token",
285297
)
286298
```
287299

@@ -298,7 +310,9 @@ By default the library closes underlying HTTP connections whenever the client is
298310
```py
299311
from gitpod import Gitpod
300312

301-
with Gitpod() as client:
313+
with Gitpod(
314+
auth_token="My Auth Token",
315+
) as client:
302316
# make requests here
303317
...
304318

Diff for: src/gitpod/_client.py

+33-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from ._version import __version__
2727
from .resources import editors, projects, automations_files, environment_classes, personal_access_tokens
2828
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
29-
from ._exceptions import APIStatusError
29+
from ._exceptions import GitpodError, APIStatusError
3030
from ._base_client import (
3131
DEFAULT_MAX_RETRIES,
3232
SyncAPIClient,
@@ -54,10 +54,12 @@ class Gitpod(SyncAPIClient):
5454
with_streaming_response: GitpodWithStreamedResponse
5555

5656
# client options
57+
auth_token: str
5758

5859
def __init__(
5960
self,
6061
*,
62+
auth_token: str | None = None,
6163
base_url: str | httpx.URL | None = None,
6264
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
6365
max_retries: int = DEFAULT_MAX_RETRIES,
@@ -77,7 +79,18 @@ def __init__(
7779
# part of our public interface in the future.
7880
_strict_response_validation: bool = False,
7981
) -> None:
80-
"""Construct a new synchronous gitpod client instance."""
82+
"""Construct a new synchronous gitpod client instance.
83+
84+
This automatically infers the `auth_token` argument from the `GITPOD_API_KEY` environment variable if it is not provided.
85+
"""
86+
if auth_token is None:
87+
auth_token = os.environ.get("GITPOD_API_KEY")
88+
if auth_token is None:
89+
raise GitpodError(
90+
"The auth_token client option must be set either by passing auth_token to the client or by setting the GITPOD_API_KEY environment variable"
91+
)
92+
self.auth_token = auth_token
93+
8194
if base_url is None:
8295
base_url = os.environ.get("GITPOD_BASE_URL")
8396
if base_url is None:
@@ -123,6 +136,7 @@ def default_headers(self) -> dict[str, str | Omit]:
123136
def copy(
124137
self,
125138
*,
139+
auth_token: str | None = None,
126140
base_url: str | httpx.URL | None = None,
127141
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
128142
http_client: httpx.Client | None = None,
@@ -156,6 +170,7 @@ def copy(
156170

157171
http_client = http_client or self._client
158172
return self.__class__(
173+
auth_token=auth_token or self.auth_token,
159174
base_url=base_url or self.base_url,
160175
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
161176
http_client=http_client,
@@ -217,10 +232,12 @@ class AsyncGitpod(AsyncAPIClient):
217232
with_streaming_response: AsyncGitpodWithStreamedResponse
218233

219234
# client options
235+
auth_token: str
220236

221237
def __init__(
222238
self,
223239
*,
240+
auth_token: str | None = None,
224241
base_url: str | httpx.URL | None = None,
225242
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
226243
max_retries: int = DEFAULT_MAX_RETRIES,
@@ -240,7 +257,18 @@ def __init__(
240257
# part of our public interface in the future.
241258
_strict_response_validation: bool = False,
242259
) -> None:
243-
"""Construct a new async gitpod client instance."""
260+
"""Construct a new async gitpod client instance.
261+
262+
This automatically infers the `auth_token` argument from the `GITPOD_API_KEY` environment variable if it is not provided.
263+
"""
264+
if auth_token is None:
265+
auth_token = os.environ.get("GITPOD_API_KEY")
266+
if auth_token is None:
267+
raise GitpodError(
268+
"The auth_token client option must be set either by passing auth_token to the client or by setting the GITPOD_API_KEY environment variable"
269+
)
270+
self.auth_token = auth_token
271+
244272
if base_url is None:
245273
base_url = os.environ.get("GITPOD_BASE_URL")
246274
if base_url is None:
@@ -286,6 +314,7 @@ def default_headers(self) -> dict[str, str | Omit]:
286314
def copy(
287315
self,
288316
*,
317+
auth_token: str | None = None,
289318
base_url: str | httpx.URL | None = None,
290319
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
291320
http_client: httpx.AsyncClient | None = None,
@@ -319,6 +348,7 @@ def copy(
319348

320349
http_client = http_client or self._client
321350
return self.__class__(
351+
auth_token=auth_token or self.auth_token,
322352
base_url=base_url or self.base_url,
323353
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
324354
http_client=http_client,

Diff for: tests/conftest.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
2828

2929
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
3030

31+
auth_token = "My Auth Token"
32+
3133

3234
@pytest.fixture(scope="session")
3335
def client(request: FixtureRequest) -> Iterator[Gitpod]:
3436
strict = getattr(request, "param", True)
3537
if not isinstance(strict, bool):
3638
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
3739

38-
with Gitpod(base_url=base_url, _strict_response_validation=strict) as client:
40+
with Gitpod(base_url=base_url, auth_token=auth_token, _strict_response_validation=strict) as client:
3941
yield client
4042

4143

@@ -45,5 +47,5 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncGitpod]:
4547
if not isinstance(strict, bool):
4648
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
4749

48-
async with AsyncGitpod(base_url=base_url, _strict_response_validation=strict) as client:
50+
async with AsyncGitpod(base_url=base_url, auth_token=auth_token, _strict_response_validation=strict) as client:
4951
yield client

0 commit comments

Comments
 (0)