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

Switch to container auth token for pods client#10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
giograno merged 1 commit intomainfromnot-existing-pods
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletionslocalstack-sdk-python/localstack/clients.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
import os

from localstack.sdk.api_client import ApiClient
from localstack.sdk.configuration import Configuration

Expand All@@ -12,7 +10,14 @@ class BaseClient:
auth_token: str | None

def __init__(self, host: str | None = None, auth_token: str | None = None, **kwargs) -> None:
"""
Initialize a base client to interact with LocalStack developer endpoint.
:param host: the host, http://localhost.localstack.cloud:4566 by default.
:param auth_token: if provided, this token would be used for authentication against platform. It not, the
LocalStack runtime will use the one used to start the container. The token used determines the Cloud
Pods identity, i.e., which pods are available.
"""
_host = host or "http://localhost.localstack.cloud:4566"
self.auth_token = auth_token or os.getenv("LOCALSTACK_AUTH_TOKEN", "").strip("'\" ")
self.auth_token = auth_token
self.configuration = Configuration(host=_host)
self._api_client = ApiClient(configuration=self.configuration)
10 changes: 6 additions & 4 deletionslocalstack-sdk-python/localstack/sdk/pods/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,10 +24,12 @@ class PodsClient(BaseClient):
def __init__(self, **args) -> None:
super().__init__(**args)
self._client = PodsApi(self._api_client)
# https://github.com/localstack/localstack-ext/pull/3469 could be avoided after this
assert self.auth_token
auth_header = get_platform_auth_header(self.auth_token)
self._api_client.set_default_header("Authorization", auth_header["Authorization"])
if self.auth_token:
# If an auth token is provided, it will be used to authenticate platform calls for Cloud Pods.
# Only the pods tied to this token will be visible. If not provided, the token will be fetched from the
# container. This allows to separate container identity for caller identity, if needed.
auth_header = get_platform_auth_header(self.auth_token)
self._api_client.set_default_header("Authorization", auth_header["Authorization"])

def save_pod(self, pod_name: str) -> None:
"""
Expand Down
6 changes: 6 additions & 0 deletionstests/integration/test_pods.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
import pytest

from localstack.sdk.pods import PodsClient

POD_NAME = "ls-sdk-integration"
Expand All@@ -14,3 +16,7 @@ def test_pod_crud(self):
self.client.save_pod(pod_name=POD_NAME)
self.client.load_pod(pod_name=POD_NAME)
self.client.delete_pod(pod_name=POD_NAME)

def test_not_existing_pod(self):
with pytest.raises(Exception):
self.client.load_pod(pod_name="i-do-not-exists")

[8]ページ先頭

©2009-2025 Movatter.jp