Skip to content

Commit 3c91d8f

Browse files
chore: security config
1 parent d009d64 commit 3c91d8f

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Diff for: README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ pip install git+ssh://[email protected]/stainless-sdks/gitpod-python.git
2727
The full API of this library can be found in [api.md](api.md).
2828

2929
```python
30+
import os
3031
from gitpod import Gitpod
3132

32-
client = Gitpod()
33+
client = Gitpod(
34+
bearer_token=os.environ.get("GITPOD_API_KEY"), # This is the default and can be omitted
35+
)
3336

3437
runner = client.runners.create(
3538
connect_protocol_version=1,
@@ -47,10 +50,13 @@ so that your Bearer Token is not stored in source control.
4750
Simply import `AsyncGitpod` instead of `Gitpod` and use `await` with each API call:
4851

4952
```python
53+
import os
5054
import asyncio
5155
from gitpod import AsyncGitpod
5256

53-
client = AsyncGitpod()
57+
client = AsyncGitpod(
58+
bearer_token=os.environ.get("GITPOD_API_KEY"), # This is the default and can be omitted
59+
)
5460

5561

5662
async def main() -> None:

Diff for: tests/test_client.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from gitpod._types import Omit
2626
from gitpod._models import BaseModel, FinalRequestOptions
2727
from gitpod._constants import RAW_RESPONSE_HEADER
28-
from gitpod._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
28+
from gitpod._exceptions import GitpodError, APIStatusError, APITimeoutError, APIResponseValidationError
2929
from gitpod._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options
3030

3131
from .utils import update_env
@@ -335,6 +335,16 @@ def test_default_headers_option(self) -> None:
335335
assert request.headers.get("x-foo") == "stainless"
336336
assert request.headers.get("x-stainless-lang") == "my-overriding-header"
337337

338+
def test_validate_headers(self) -> None:
339+
client = Gitpod(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True)
340+
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
341+
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
342+
343+
with pytest.raises(GitpodError):
344+
with update_env(**{"GITPOD_API_KEY": Omit()}):
345+
client2 = Gitpod(base_url=base_url, bearer_token=None, _strict_response_validation=True)
346+
_ = client2
347+
338348
def test_default_query_option(self) -> None:
339349
client = Gitpod(
340350
base_url=base_url,
@@ -1121,6 +1131,16 @@ def test_default_headers_option(self) -> None:
11211131
assert request.headers.get("x-foo") == "stainless"
11221132
assert request.headers.get("x-stainless-lang") == "my-overriding-header"
11231133

1134+
def test_validate_headers(self) -> None:
1135+
client = AsyncGitpod(base_url=base_url, bearer_token=bearer_token, _strict_response_validation=True)
1136+
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
1137+
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
1138+
1139+
with pytest.raises(GitpodError):
1140+
with update_env(**{"GITPOD_API_KEY": Omit()}):
1141+
client2 = AsyncGitpod(base_url=base_url, bearer_token=None, _strict_response_validation=True)
1142+
_ = client2
1143+
11241144
def test_default_query_option(self) -> None:
11251145
client = AsyncGitpod(
11261146
base_url=base_url,

0 commit comments

Comments
 (0)