26
26
from ._version import __version__
27
27
from .resources import editors , projects , automations_files , environment_classes , personal_access_tokens
28
28
from ._streaming import Stream as Stream , AsyncStream as AsyncStream
29
- from ._exceptions import APIStatusError
29
+ from ._exceptions import GitpodError , APIStatusError
30
30
from ._base_client import (
31
31
DEFAULT_MAX_RETRIES ,
32
32
SyncAPIClient ,
@@ -54,10 +54,12 @@ class Gitpod(SyncAPIClient):
54
54
with_streaming_response : GitpodWithStreamedResponse
55
55
56
56
# client options
57
+ auth_token : str
57
58
58
59
def __init__ (
59
60
self ,
60
61
* ,
62
+ auth_token : str | None = None ,
61
63
base_url : str | httpx .URL | None = None ,
62
64
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
63
65
max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -77,7 +79,18 @@ def __init__(
77
79
# part of our public interface in the future.
78
80
_strict_response_validation : bool = False ,
79
81
) -> 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
+
81
94
if base_url is None :
82
95
base_url = os .environ .get ("GITPOD_BASE_URL" )
83
96
if base_url is None :
@@ -123,6 +136,7 @@ def default_headers(self) -> dict[str, str | Omit]:
123
136
def copy (
124
137
self ,
125
138
* ,
139
+ auth_token : str | None = None ,
126
140
base_url : str | httpx .URL | None = None ,
127
141
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
128
142
http_client : httpx .Client | None = None ,
@@ -156,6 +170,7 @@ def copy(
156
170
157
171
http_client = http_client or self ._client
158
172
return self .__class__ (
173
+ auth_token = auth_token or self .auth_token ,
159
174
base_url = base_url or self .base_url ,
160
175
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
161
176
http_client = http_client ,
@@ -217,10 +232,12 @@ class AsyncGitpod(AsyncAPIClient):
217
232
with_streaming_response : AsyncGitpodWithStreamedResponse
218
233
219
234
# client options
235
+ auth_token : str
220
236
221
237
def __init__ (
222
238
self ,
223
239
* ,
240
+ auth_token : str | None = None ,
224
241
base_url : str | httpx .URL | None = None ,
225
242
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
226
243
max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -240,7 +257,18 @@ def __init__(
240
257
# part of our public interface in the future.
241
258
_strict_response_validation : bool = False ,
242
259
) -> 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
+
244
272
if base_url is None :
245
273
base_url = os .environ .get ("GITPOD_BASE_URL" )
246
274
if base_url is None :
@@ -286,6 +314,7 @@ def default_headers(self) -> dict[str, str | Omit]:
286
314
def copy (
287
315
self ,
288
316
* ,
317
+ auth_token : str | None = None ,
289
318
base_url : str | httpx .URL | None = None ,
290
319
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
291
320
http_client : httpx .AsyncClient | None = None ,
@@ -319,6 +348,7 @@ def copy(
319
348
320
349
http_client = http_client or self ._client
321
350
return self .__class__ (
351
+ auth_token = auth_token or self .auth_token ,
322
352
base_url = base_url or self .base_url ,
323
353
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
324
354
http_client = http_client ,
0 commit comments