Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c81a97

Browse files
authored
Switch to container auth token for pods client (#10)
1 parent296e483 commit2c81a97

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

‎localstack-sdk-python/localstack/clients.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
importos
2-
31
fromlocalstack.sdk.api_clientimportApiClient
42
fromlocalstack.sdk.configurationimportConfiguration
53

@@ -12,7 +10,14 @@ class BaseClient:
1210
auth_token:str|None
1311

1412
def__init__(self,host:str|None=None,auth_token:str|None=None,**kwargs)->None:
13+
"""
14+
Initialize a base client to interact with LocalStack developer endpoint.
15+
:param host: the host, http://localhost.localstack.cloud:4566 by default.
16+
:param auth_token: if provided, this token would be used for authentication against platform. It not, the
17+
LocalStack runtime will use the one used to start the container. The token used determines the Cloud
18+
Pods identity, i.e., which pods are available.
19+
"""
1520
_host=hostor"http://localhost.localstack.cloud:4566"
16-
self.auth_token=auth_tokenoros.getenv("LOCALSTACK_AUTH_TOKEN","").strip("'\" ")
21+
self.auth_token=auth_token
1722
self.configuration=Configuration(host=_host)
1823
self._api_client=ApiClient(configuration=self.configuration)

‎localstack-sdk-python/localstack/sdk/pods/client.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class PodsClient(BaseClient):
2424
def__init__(self,**args)->None:
2525
super().__init__(**args)
2626
self._client=PodsApi(self._api_client)
27-
# https://github.com/localstack/localstack-ext/pull/3469 could be avoided after this
28-
assertself.auth_token
29-
auth_header=get_platform_auth_header(self.auth_token)
30-
self._api_client.set_default_header("Authorization",auth_header["Authorization"])
27+
ifself.auth_token:
28+
# If an auth token is provided, it will be used to authenticate platform calls for Cloud Pods.
29+
# Only the pods tied to this token will be visible. If not provided, the token will be fetched from the
30+
# container. This allows to separate container identity for caller identity, if needed.
31+
auth_header=get_platform_auth_header(self.auth_token)
32+
self._api_client.set_default_header("Authorization",auth_header["Authorization"])
3133

3234
defsave_pod(self,pod_name:str)->None:
3335
"""

‎tests/integration/test_pods.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
importpytest
2+
13
fromlocalstack.sdk.podsimportPodsClient
24

35
POD_NAME="ls-sdk-integration"
@@ -14,3 +16,7 @@ def test_pod_crud(self):
1416
self.client.save_pod(pod_name=POD_NAME)
1517
self.client.load_pod(pod_name=POD_NAME)
1618
self.client.delete_pod(pod_name=POD_NAME)
19+
20+
deftest_not_existing_pod(self):
21+
withpytest.raises(Exception):
22+
self.client.load_pod(pod_name="i-do-not-exists")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp