localstack-sdk-python 0.0.3__py3-none-any.whl → 4.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- localstack/sdk/aws/client.py +121 -3
- localstack/sdk/chaos/client.py +40 -10
- localstack/sdk/chaos/managers.py +5 -0
- localstack/sdk/clients.py +35 -0
- localstack/sdk/pods/client.py +63 -25
- localstack/sdk/pods/exceptions.py +18 -0
- localstack/sdk/state/client.py +10 -2
- localstack/sdk/testing/__init__.py +3 -0
- localstack/sdk/testing/decorators.py +31 -0
- localstack/sdk/testing/pytest/__init__.py +0 -0
- localstack/sdk/testing/pytest/plugins.py +11 -0
- localstack/sdk/version.py +21 -0
- localstack_sdk_python-4.3.0.dist-info/METADATA +70 -0
- localstack_sdk_python-4.3.0.dist-info/RECORD +22 -0
- {localstack_sdk_python-0.0.3.dist-info → localstack_sdk_python-4.3.0.dist-info}/WHEEL +1 -1
- localstack_sdk_python-4.3.0.dist-info/entry_points.txt +2 -0
- localstack/clients.py +0 -18
- localstack_sdk_python-0.0.3.dist-info/METADATA +0 -39
- localstack_sdk_python-0.0.3.dist-info/RECORD +0 -15
- {localstack_sdk_python-0.0.3.dist-info → localstack_sdk_python-4.3.0.dist-info/licenses}/LICENSE.txt +0 -0
- {localstack_sdk_python-0.0.3.dist-info → localstack_sdk_python-4.3.0.dist-info}/top_level.txt +0 -0
localstack/sdk/aws/client.py
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import json
|
|
2
2
|
|
|
3
|
-
from localstack.clients import BaseClient
|
|
4
3
|
from localstack.sdk.api.aws_api import AwsApi
|
|
5
|
-
from localstack.sdk.
|
|
4
|
+
from localstack.sdk.clients import BaseClient
|
|
5
|
+
from localstack.sdk.models import (
|
|
6
|
+
Message,
|
|
7
|
+
SesSentEmail,
|
|
8
|
+
SNSPlatformEndpointResponse,
|
|
9
|
+
SNSSMSMessagesResponse,
|
|
10
|
+
)
|
|
6
11
|
|
|
7
12
|
|
|
8
13
|
def _from_sqs_query_to_json(xml_dict: dict) -> list[Message]:
|
|
@@ -31,6 +36,12 @@ def _from_sqs_query_to_json(xml_dict: dict) -> list[Message]:
|
|
|
31
36
|
|
|
32
37
|
|
|
33
38
|
class AWSClient(BaseClient):
|
|
39
|
+
"""
|
|
40
|
+
The client to interact with all the LocalStack's AWS endpoints.
|
|
41
|
+
These endpoints offer specific features in addition to the ones offered by the AWS services. For instance,
|
|
42
|
+
access all the messages withing a SQS without the side effect of deleting them.
|
|
43
|
+
"""
|
|
44
|
+
|
|
34
45
|
def __init__(self, **kwargs) -> None:
|
|
35
46
|
super().__init__(**kwargs)
|
|
36
47
|
self._client = AwsApi(self._api_client)
|
|
@@ -40,12 +51,26 @@ class AWSClient(BaseClient):
|
|
|
40
51
|
########
|
|
41
52
|
|
|
42
53
|
def list_sqs_messages(self, account_id: str, region: str, queue_name: str) -> list[Message]:
|
|
54
|
+
"""
|
|
55
|
+
Lists all the SQS messages in a given queue in a specific account id and region, without any side effect.
|
|
56
|
+
|
|
57
|
+
:param account_id: the account id of the queue
|
|
58
|
+
:param region: the region of the queue
|
|
59
|
+
:param queue_name: the name of the queue
|
|
60
|
+
:return: the list of messages in the queue
|
|
61
|
+
"""
|
|
43
62
|
response = self._client.list_sqs_messages_with_http_info(
|
|
44
63
|
account_id=account_id, region=region, queue_name=queue_name
|
|
45
64
|
)
|
|
46
65
|
return _from_sqs_query_to_json(json.loads(response.raw_data))
|
|
47
66
|
|
|
48
|
-
def list_sqs_messages_from_queue_url(self, queue_url) -> list[Message]:
|
|
67
|
+
def list_sqs_messages_from_queue_url(self, queue_url: str) -> list[Message]:
|
|
68
|
+
"""
|
|
69
|
+
Lists all the SQS messages in a given queue, without any side effect.
|
|
70
|
+
|
|
71
|
+
:param queue_url: the URL of the queue
|
|
72
|
+
:return: the list of messages in the queue
|
|
73
|
+
"""
|
|
49
74
|
response = self._client.list_all_sqs_messages_with_http_info(queue_url=queue_url)
|
|
50
75
|
return _from_sqs_query_to_json(json.loads(response.raw_data))
|
|
51
76
|
|
|
@@ -56,12 +81,105 @@ class AWSClient(BaseClient):
|
|
|
56
81
|
def get_ses_messages(
|
|
57
82
|
self, id_filter: str | None = None, email_filter: str | None = None
|
|
58
83
|
) -> list[SesSentEmail]:
|
|
84
|
+
"""
|
|
85
|
+
Returns all the in-memory saved SES messages. They can be filtered by message ID and/or message source.
|
|
86
|
+
|
|
87
|
+
:param id_filter: the message id used as filter for the SES messages
|
|
88
|
+
:param email_filter: the message source filter
|
|
89
|
+
:return: a list of email sent with SES
|
|
90
|
+
"""
|
|
59
91
|
response = self._client.get_ses_messages(id=id_filter, email=email_filter)
|
|
60
92
|
return response.messages
|
|
61
93
|
|
|
62
94
|
def discard_ses_messages(self, id_filter: str | None = None) -> None:
|
|
95
|
+
"""
|
|
96
|
+
Clears all SES messages. An ID filter can be provided to delete only a specific message.
|
|
97
|
+
|
|
98
|
+
:param id_filter: the id filter
|
|
99
|
+
:return: None
|
|
100
|
+
"""
|
|
63
101
|
return self._client.discard_ses_messages(id=id_filter)
|
|
64
102
|
|
|
103
|
+
########
|
|
104
|
+
# SNS
|
|
105
|
+
########
|
|
106
|
+
|
|
107
|
+
def get_sns_sms_messages(
|
|
108
|
+
self,
|
|
109
|
+
phone_number: str | None = None,
|
|
110
|
+
account_id: str = "000000000000",
|
|
111
|
+
region: str = "us-east-1",
|
|
112
|
+
) -> SNSSMSMessagesResponse:
|
|
113
|
+
"""
|
|
114
|
+
Returns all SMS messages published to a phone number.
|
|
115
|
+
|
|
116
|
+
:param phone_number: the phone number to which the messages have been published. If not specified, all messages
|
|
117
|
+
are returned.
|
|
118
|
+
:param account_id: the AWS Account ID from which the messages have been published. '000000000000' by default
|
|
119
|
+
:param region: the AWS region from which the messages have been published. us-east-1 by default
|
|
120
|
+
:return:
|
|
121
|
+
"""
|
|
122
|
+
return self._client.get_sns_sms_messages(
|
|
123
|
+
phone_number=phone_number, account_id=account_id, region=region
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def discard_sns_sms_messages(
|
|
127
|
+
self,
|
|
128
|
+
phone_number: str | None = None,
|
|
129
|
+
account_id: str = "000000000000",
|
|
130
|
+
region: str = "us-east-1",
|
|
131
|
+
) -> None:
|
|
132
|
+
"""
|
|
133
|
+
Discards all SMS messages published to a phone number.
|
|
134
|
+
|
|
135
|
+
:param phone_number: the phone number to which the messages have been published. If not specified, all messages
|
|
136
|
+
are deleted.
|
|
137
|
+
:param account_id: the AWS Account ID from which the messages have been published. '000000000000' by default
|
|
138
|
+
:param region: the AWS region from which the messages have been published. us-east-1 by default
|
|
139
|
+
:return: None
|
|
140
|
+
"""
|
|
141
|
+
return self._client.discard_sns_sms_messages(
|
|
142
|
+
phone_number=phone_number, account_id=account_id, region=region
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
def get_sns_endpoint_messages(
|
|
146
|
+
self,
|
|
147
|
+
endpoint_arn: str | None = None,
|
|
148
|
+
account_id: str = "000000000000",
|
|
149
|
+
region: str = "us-east-1",
|
|
150
|
+
) -> SNSPlatformEndpointResponse:
|
|
151
|
+
"""
|
|
152
|
+
Returns all the messages published to a platform endpoint.
|
|
153
|
+
|
|
154
|
+
:param endpoint_arn: the ARN to which the messages have been published. If not specified, will return all the
|
|
155
|
+
messages.
|
|
156
|
+
:param account_id: the AWS Account ID from which the messages have been published. 000000000000 if not specified
|
|
157
|
+
:param region: the AWS region from which the messages have been published. us-east-1 by default
|
|
158
|
+
:return: a response with the list of messages and the queried region
|
|
159
|
+
"""
|
|
160
|
+
return self._client.get_sns_endpoint_messages(
|
|
161
|
+
endpoint_arn=endpoint_arn, account_id=account_id, region=region
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
def discard_sns_endpoint_messages(
|
|
165
|
+
self,
|
|
166
|
+
endpoint_arn: str | None = None,
|
|
167
|
+
account_id: str = "000000000000",
|
|
168
|
+
region: str = "us-east-1",
|
|
169
|
+
) -> None:
|
|
170
|
+
"""
|
|
171
|
+
Discards all the messaged published to a platform endpoint.
|
|
172
|
+
|
|
173
|
+
:param endpoint_arn: the ARN to which the messages have been published. If not specified, will discard all the
|
|
174
|
+
messages.
|
|
175
|
+
:param account_id: the AWS Account ID from which the messages have been published. 000000000000 if not specified
|
|
176
|
+
:param region: the AWS region from which the messages have been published. us-east-1 by default
|
|
177
|
+
:return: None
|
|
178
|
+
"""
|
|
179
|
+
return self._client.discard_sns_endpoint_messages(
|
|
180
|
+
endpoint_arn=endpoint_arn, account_id=account_id, region=region
|
|
181
|
+
)
|
|
182
|
+
|
|
65
183
|
|
|
66
184
|
def get_default(**args) -> AwsApi:
|
|
67
185
|
"""Return a client with a default configuration"""
|
localstack/sdk/chaos/client.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
from localstack.clients import BaseClient
|
|
2
1
|
from localstack.sdk.api.chaos_api import ChaosApi
|
|
2
|
+
from localstack.sdk.clients import BaseClient
|
|
3
3
|
from localstack.sdk.models import FaultRule, NetworkEffectsConfig
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class ChaosClient(BaseClient):
|
|
7
7
|
"""
|
|
8
|
-
The client
|
|
9
|
-
This is mostly a wrapper of the ChaosApi class, which is automatically generated from the OpenAPI specs.
|
|
8
|
+
The client to interact with the LocalStack's Chaos API.
|
|
10
9
|
"""
|
|
11
10
|
|
|
12
11
|
def __init__(self, **kwargs) -> None:
|
|
@@ -14,26 +13,57 @@ class ChaosClient(BaseClient):
|
|
|
14
13
|
self._client = ChaosApi(self._api_client)
|
|
15
14
|
|
|
16
15
|
def set_fault_rules(self, fault_rules: list[FaultRule]) -> list[FaultRule]:
|
|
17
|
-
|
|
16
|
+
"""
|
|
17
|
+
Creates a new sets of fault rules. It overwrites the previous ones.
|
|
18
|
+
:param fault_rules: the list of FaultRule we want to set
|
|
19
|
+
:return: the list of FaultRule currently in place
|
|
20
|
+
"""
|
|
21
|
+
return self._client.set_fault_rules(fault_rule=fault_rules)
|
|
18
22
|
|
|
19
23
|
def add_fault_rules(self, fault_rules: list[FaultRule]) -> list[FaultRule]:
|
|
20
|
-
|
|
24
|
+
"""
|
|
25
|
+
Adds a new set of rules to the current fault configuration.
|
|
26
|
+
:param fault_rules: the FaultRule rules to add
|
|
27
|
+
:return: the list of FaultRule currently in place
|
|
28
|
+
"""
|
|
29
|
+
return self._client.add_fault_rules(fault_rule=fault_rules)
|
|
21
30
|
|
|
22
31
|
def delete_fault_rules(self, fault_rules: list[FaultRule]) -> list[FaultRule]:
|
|
23
|
-
|
|
32
|
+
"""
|
|
33
|
+
Deletes a set of rules from the fault configuration.
|
|
34
|
+
:param fault_rules: the FaultRule to delete
|
|
35
|
+
:return: the list of FaultRule currently in place
|
|
36
|
+
"""
|
|
37
|
+
return self._client.delete_fault_rules(fault_rule=fault_rules)
|
|
24
38
|
|
|
25
39
|
def get_fault_rules(self) -> list[FaultRule]:
|
|
26
|
-
|
|
40
|
+
"""
|
|
41
|
+
Gets the current fault configuration.
|
|
42
|
+
:return: the list of FaultRule of the current configuration
|
|
43
|
+
"""
|
|
44
|
+
return self._client.get_fault_rules()
|
|
27
45
|
|
|
28
46
|
def get_network_effects(self) -> NetworkEffectsConfig:
|
|
29
|
-
|
|
47
|
+
"""
|
|
48
|
+
Gets the current network effect configuration.
|
|
49
|
+
:return: the current NetworkEffectsConfig
|
|
50
|
+
"""
|
|
51
|
+
return self._client.get_network_effects()
|
|
30
52
|
|
|
31
53
|
def set_network_effects(
|
|
32
54
|
self, network_effects_config: NetworkEffectsConfig
|
|
33
55
|
) -> NetworkEffectsConfig:
|
|
34
|
-
|
|
56
|
+
"""
|
|
57
|
+
Configure a new network effect, e.g, latency.
|
|
58
|
+
:param network_effects_config: the network config to be set
|
|
59
|
+
:return: the current configuration of network effects
|
|
60
|
+
"""
|
|
61
|
+
return self._client.set_network_effects(network_effects_config=network_effects_config)
|
|
35
62
|
|
|
36
63
|
|
|
37
64
|
def get_default(**args) -> ChaosClient:
|
|
38
|
-
"""
|
|
65
|
+
"""
|
|
66
|
+
Return a chaos client with a default configuration. You can pass a host argument to overwrite the fault one
|
|
67
|
+
(http://localhost.localstack.cloud:4566).
|
|
68
|
+
"""
|
|
39
69
|
return ChaosClient(**args)
|
localstack/sdk/chaos/managers.py
CHANGED
|
@@ -6,6 +6,11 @@ from localstack.sdk.models import FaultRule
|
|
|
6
6
|
|
|
7
7
|
@contextmanager
|
|
8
8
|
def fault_configuration(fault_rules: list[FaultRule]):
|
|
9
|
+
"""
|
|
10
|
+
This is a context manager that temporarily applies a given set of fault rules.
|
|
11
|
+
:param fault_rules: a list of FaultRule to be applied.
|
|
12
|
+
:return: None
|
|
13
|
+
"""
|
|
9
14
|
client = get_default()
|
|
10
15
|
try:
|
|
11
16
|
client.set_fault_rules(fault_rules=fault_rules)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from localstack.sdk import version
|
|
2
|
+
from localstack.sdk.api_client import ApiClient
|
|
3
|
+
from localstack.sdk.configuration import Configuration
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseClient:
|
|
7
|
+
"""
|
|
8
|
+
A BaseClient creates a configuration and instantiate a ApiClient, which is a generic OpenAPI client automatically
|
|
9
|
+
generated by the openapitools/openapi-generator tool.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
configuration: Configuration
|
|
13
|
+
"""The configuration for the base client"""
|
|
14
|
+
_api_client: ApiClient
|
|
15
|
+
"""The OpenAPI client"""
|
|
16
|
+
host: str
|
|
17
|
+
"""The LocalStack host (http://localhost.localstack.cloud:4566 by default)"""
|
|
18
|
+
auth_token: str | None
|
|
19
|
+
"""A client can be injected with a LocalStack auth token. If not provided, the one used to start up the
|
|
20
|
+
LocalStack instance will be used (for the features needing it, e.g., Cloud Pods)."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, host: str | None = None, auth_token: str | None = None, **kwargs) -> None:
|
|
23
|
+
"""
|
|
24
|
+
Initializes a base client to interact with LocalStack developer endpoint.
|
|
25
|
+
:param host: the host, http://localhost.localstack.cloud:4566 by default.
|
|
26
|
+
:param auth_token: if provided, this token would be used for authentication against platform. It not, the
|
|
27
|
+
LocalStack runtime will use the one used to start the container. The token used determines the Cloud
|
|
28
|
+
Pods identity, i.e., which pods are available.
|
|
29
|
+
"""
|
|
30
|
+
self.host = host or "http://localhost.localstack.cloud:4566"
|
|
31
|
+
self.auth_token = auth_token
|
|
32
|
+
self.configuration = Configuration(host=self.host)
|
|
33
|
+
self._api_client = ApiClient(configuration=self.configuration)
|
|
34
|
+
# The generated code comes with 1.0.0 hard-coded. We set here the correct version
|
|
35
|
+
self._api_client.user_agent = f"LocalStack SDK/{version.version}/python"
|
localstack/sdk/pods/client.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import json
|
|
3
3
|
|
|
4
|
-
from localstack.clients import BaseClient
|
|
5
4
|
from localstack.sdk.api import PodsApi
|
|
6
|
-
from localstack.sdk.
|
|
5
|
+
from localstack.sdk.clients import BaseClient
|
|
6
|
+
from localstack.sdk.models import PodList, PodSaveRequest, RemoteConfig
|
|
7
|
+
from localstack.sdk.pods.exceptions import PodLoadException, PodSaveException
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def _empty_remote_config() -> RemoteConfig:
|
|
@@ -11,67 +12,104 @@ def _empty_remote_config() -> RemoteConfig:
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
def _read_ndjson(raw_content: bytes) -> list[dict]:
|
|
15
|
+
"""
|
|
16
|
+
Reads the byte content of a ndjson response into a list of dictionaries.
|
|
17
|
+
:param raw_content: the byte content of a ndjson response.
|
|
18
|
+
:return: a list of dicts.
|
|
19
|
+
"""
|
|
14
20
|
ndjson_str = raw_content.decode("utf-8")
|
|
15
21
|
return [json.loads(line) for line in ndjson_str.splitlines()]
|
|
16
22
|
|
|
17
23
|
|
|
18
24
|
def _get_completion_event(streamed_response: list[dict]) -> dict | None:
|
|
25
|
+
"""
|
|
26
|
+
Parses the chucked response returned form the Cloud Pod save and load endpoints and return the completion event,
|
|
27
|
+
i.e., the one summarizing the output (success or error) of the operation.
|
|
28
|
+
:param streamed_response: a list of dictionaries for the chunked response.
|
|
29
|
+
:return: the dictionary of the completion event, if found. None otherwise.
|
|
30
|
+
"""
|
|
19
31
|
completion_events = [line for line in streamed_response if line.get("event") == "completion"]
|
|
20
32
|
return completion_events[0] if completion_events else None
|
|
21
33
|
|
|
22
34
|
|
|
23
35
|
class PodsClient(BaseClient):
|
|
36
|
+
"""
|
|
37
|
+
The client to interact with the Cloud Pod feature.
|
|
38
|
+
"""
|
|
39
|
+
|
|
24
40
|
def __init__(self, **args) -> None:
|
|
41
|
+
"""
|
|
42
|
+
Initializes a Cloud Pods client.
|
|
43
|
+
:param auth_token: if provided, this token will be used for platform authentication. If not, it will be
|
|
44
|
+
fetched from within the container itself.
|
|
45
|
+
"""
|
|
25
46
|
super().__init__(**args)
|
|
26
47
|
self._client = PodsApi(self._api_client)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
if self.auth_token:
|
|
49
|
+
# If an auth token is provided, it will be used to authenticate platform calls for Cloud Pods.
|
|
50
|
+
# Only the pods tied to this token will be visible. If not provided, the token will be fetched from the
|
|
51
|
+
# container. This allows to separate container identity for caller identity, if needed.
|
|
52
|
+
auth_header = get_platform_auth_header(self.auth_token)
|
|
53
|
+
self._api_client.set_default_header("Authorization", auth_header["Authorization"])
|
|
31
54
|
|
|
32
55
|
def save_pod(self, pod_name: str) -> None:
|
|
33
56
|
"""
|
|
34
|
-
|
|
57
|
+
Saves the state in the LocalStack container into a Cloud Pod and uploads it to the LocalStack's platform.
|
|
58
|
+
If a Cloud Pod with the given name already exists, a new version is created.
|
|
59
|
+
:param pod_name: the name of the Cloud Pod to be saved.
|
|
60
|
+
:return: None
|
|
61
|
+
:raises PodSaveException: if the save operation returns an error
|
|
35
62
|
"""
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
except Exception as e:
|
|
41
|
-
raise (e)
|
|
63
|
+
response = self._client.save_pod_with_http_info(
|
|
64
|
+
name=pod_name, pod_save_request=PodSaveRequest()
|
|
65
|
+
)
|
|
42
66
|
if response.status_code != 200:
|
|
43
|
-
|
|
67
|
+
raise PodSaveException(pod_name=pod_name)
|
|
44
68
|
streamed_response = _read_ndjson(response.raw_data)
|
|
45
69
|
completion_event = _get_completion_event(streamed_response)
|
|
46
70
|
if completion_event["status"] == "error":
|
|
47
|
-
|
|
48
|
-
raise Exception(completion_event.get("message"))
|
|
71
|
+
raise PodSaveException(pod_name=pod_name, error=completion_event.get("message"))
|
|
49
72
|
|
|
50
73
|
def load_pod(self, pod_name: str) -> None:
|
|
51
74
|
"""
|
|
52
|
-
|
|
75
|
+
Loads a Cloud Pod into the LocalStack container.
|
|
76
|
+
:param pod_name: the name of the Cloud Pod to load
|
|
77
|
+
:return: None
|
|
78
|
+
:raises PodLoadException: if the load operation returns an error
|
|
53
79
|
"""
|
|
54
|
-
response = self._client.
|
|
80
|
+
response = self._client.load_pod_with_http_info(
|
|
55
81
|
name=pod_name, remote_config=_empty_remote_config()
|
|
56
82
|
)
|
|
57
83
|
if response.status_code != 200:
|
|
58
|
-
|
|
84
|
+
raise PodLoadException(pod_name=pod_name)
|
|
59
85
|
streamed_response = _read_ndjson(response.raw_data)
|
|
60
86
|
completion_event = _get_completion_event(streamed_response)
|
|
61
87
|
if completion_event["status"] == "error":
|
|
62
|
-
|
|
63
|
-
raise Exception(completion_event.get("message"))
|
|
88
|
+
raise PodLoadException(pod_name=pod_name, error=completion_event.get("message"))
|
|
64
89
|
|
|
65
90
|
def delete_pod(self, pod_name: str) -> None:
|
|
66
|
-
|
|
91
|
+
"""
|
|
92
|
+
Deletes a Cloud Pod.
|
|
93
|
+
:param pod_name: the name of the Cloud Pod to be deleted.
|
|
94
|
+
:return: None
|
|
95
|
+
"""
|
|
96
|
+
return self._client.delete_pod(name=pod_name, remote_config=_empty_remote_config())
|
|
67
97
|
|
|
68
|
-
def list_pods(self):
|
|
69
|
-
|
|
70
|
-
|
|
98
|
+
def list_pods(self) -> PodList:
|
|
99
|
+
"""
|
|
100
|
+
Returns the list of the Cloud Pods visible in the organization.
|
|
101
|
+
:return: a PodList object
|
|
102
|
+
"""
|
|
103
|
+
pods = self._client.list_pods(remote_config=_empty_remote_config())
|
|
71
104
|
return pods
|
|
72
105
|
|
|
73
106
|
|
|
74
107
|
def get_platform_auth_header(token: str) -> dict[str, str]:
|
|
108
|
+
"""
|
|
109
|
+
Given the auth token, crafts the authorization header to authenticate platform calls.
|
|
110
|
+
:param token: the localstack auth token
|
|
111
|
+
:return: a dictionary for the authorization header
|
|
112
|
+
"""
|
|
75
113
|
_token = f":{token}"
|
|
76
114
|
auth_encoded = base64.b64encode(_token.encode("utf-8")).decode("utf-8")
|
|
77
115
|
return {"Authorization": f"Basic {auth_encoded}"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class PodSaveException(Exception):
|
|
2
|
+
message = "An error occurred while saving the Cloud Pod"
|
|
3
|
+
|
|
4
|
+
def __init__(self, pod_name: str, error: str | None = None) -> None:
|
|
5
|
+
_message = f"{self.message} '{pod_name}'"
|
|
6
|
+
if error:
|
|
7
|
+
_message += f": {error}"
|
|
8
|
+
super().__init__(_message)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PodLoadException(Exception):
|
|
12
|
+
message = "An error occurred while loading the Cloud Pod"
|
|
13
|
+
|
|
14
|
+
def __init__(self, pod_name: str, error: str | None = None) -> None:
|
|
15
|
+
_message = f"{self.message} '{pod_name}'"
|
|
16
|
+
if error:
|
|
17
|
+
_message += f": {error}"
|
|
18
|
+
super().__init__(_message)
|
localstack/sdk/state/client.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
from localstack.clients import BaseClient
|
|
2
1
|
from localstack.sdk.api import StateApi
|
|
2
|
+
from localstack.sdk.clients import BaseClient
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class StateClient(BaseClient):
|
|
6
|
+
"""
|
|
7
|
+
Initializes a client to handle LocalStack's state.
|
|
8
|
+
"""
|
|
9
|
+
|
|
6
10
|
def __init__(self, **args) -> None:
|
|
7
11
|
super().__init__(**args)
|
|
8
12
|
self._client = StateApi(self._api_client)
|
|
9
13
|
|
|
10
14
|
def reset_state(self) -> None:
|
|
11
|
-
|
|
15
|
+
"""
|
|
16
|
+
Resets the state of LocalStack for all running services.
|
|
17
|
+
:return: None
|
|
18
|
+
"""
|
|
19
|
+
self._client.localstack_state_reset_post()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from functools import wraps
|
|
3
|
+
|
|
4
|
+
from localstack.sdk.pods import PodsClient
|
|
5
|
+
from localstack.sdk.state import StateClient
|
|
6
|
+
|
|
7
|
+
LOG = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def cloudpods(*args, **kwargs):
|
|
11
|
+
"""This is a decorator that loads a cloud pod before a test and resets the state afterward."""
|
|
12
|
+
|
|
13
|
+
def decorator(func):
|
|
14
|
+
@wraps(func)
|
|
15
|
+
def wrapper(*test_args, **test_kwargs):
|
|
16
|
+
if not (pod_name := kwargs.get("name")):
|
|
17
|
+
raise Exception("Specify a Cloud Pod name in the `name` arg")
|
|
18
|
+
pods_client = PodsClient()
|
|
19
|
+
LOG.debug("Loading %s", pod_name)
|
|
20
|
+
pods_client.load_pod(pod_name=pod_name)
|
|
21
|
+
try:
|
|
22
|
+
result = func(*test_args, **test_kwargs)
|
|
23
|
+
finally:
|
|
24
|
+
LOG.debug("Reset state of the container")
|
|
25
|
+
state_client = StateClient()
|
|
26
|
+
state_client.reset_state()
|
|
27
|
+
return result
|
|
28
|
+
|
|
29
|
+
return wrapper
|
|
30
|
+
|
|
31
|
+
return decorator
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from localstack.sdk.state import StateClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.fixture
|
|
7
|
+
def reset_state():
|
|
8
|
+
"""This fixture is used to completely reset the state of LocalStack after a test runs."""
|
|
9
|
+
yield
|
|
10
|
+
state_client = StateClient()
|
|
11
|
+
state_client.reset_state()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '4.3.0'
|
|
21
|
+
__version_tuple__ = version_tuple = (4, 3, 0)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: localstack-sdk-python
|
|
3
|
+
Version: 4.3.0
|
|
4
|
+
Summary: Python SDK for LocalStack
|
|
5
|
+
Author-email: LocalStack Team <info@localstack.cloud>
|
|
6
|
+
Project-URL: Homepage, https://localstack.cloud
|
|
7
|
+
Project-URL: Documentation, https://docs.localstack.cloud
|
|
8
|
+
Project-URL: Repository, https://github.com/localstack/localstack-sdk-python.git
|
|
9
|
+
Project-URL: Issues, https://github.com/localstack/localstack-sdk-python/issues
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE.txt
|
|
12
|
+
Requires-Dist: localstack-sdk-generated
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# LocalStack Python SDK
|
|
16
|
+
[](https://pypi.org/project/localstack-sdk-python/)
|
|
17
|
+
[](https://github.com/localstack/localstack-sdk-python/actions/workflows/test.yml)
|
|
18
|
+
|
|
19
|
+
This is the Python SDK for LocalStack.
|
|
20
|
+
LocalStack offers a number of developer endpoints (see [docs](https://docs.localstack.cloud/references/internal-endpoints/)).
|
|
21
|
+
This SDK provides a programmatic and easy way to interact with them.
|
|
22
|
+
|
|
23
|
+
> [!WARNING]
|
|
24
|
+
> This project is still in a preview phase and will be subject to fast and breaking changes.
|
|
25
|
+
|
|
26
|
+
### Project Structure
|
|
27
|
+
|
|
28
|
+
This project is composed by two Python packages:
|
|
29
|
+
|
|
30
|
+
- `packages/localstack-sdk-generated`: generated from the LocalStack's OpenAPI specs with [openapi-generator](https://github.com/OpenAPITools/openapi-generator).
|
|
31
|
+
The LocalStack's OpenAPI specs are available in [localstack/openapi](https://github.com/localstack/openapi).
|
|
32
|
+
This package is not meant to be manually modified, as it needs to be generated every time from the specs.
|
|
33
|
+
- `localstack-sdk-python`: the user-facing SDK that consumed `localstack-sdk-generated` as its main dependency.
|
|
34
|
+
|
|
35
|
+
### Installation
|
|
36
|
+
|
|
37
|
+
You can install the LocalStack Python SDK with `pip`:
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
pip install localstack-sdk-python
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### From Source
|
|
44
|
+
|
|
45
|
+
This project uses [uv](https://github.com/astral-sh/uv) as a package manager.
|
|
46
|
+
On a Unix system, you can install `uv` with the standalone installer:
|
|
47
|
+
|
|
48
|
+
```shell
|
|
49
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Once `uv` is installed, you can install the project from source with:
|
|
53
|
+
|
|
54
|
+
```shell
|
|
55
|
+
make install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To run the integration test suite:
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
make test
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Note that LocalStack Pro (with the same version as the SDK) should be running in the background to execute the test.
|
|
65
|
+
|
|
66
|
+
### Quickstart
|
|
67
|
+
|
|
68
|
+
To get started with our SDK, check out the [official documentation on https://docs.localstack.cloud](https://docs.localstack.cloud/user-guide/tools/localstack-sdk/python/).
|
|
69
|
+
You'll find comprehensive guides and detailed code samples that demonstrate how to use the various features provided
|
|
70
|
+
by the SDK.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
localstack/sdk/clients.py,sha256=B4-EnawK9IVdwcHsFSRqYqaQ4ofSuNsQx6YeHfIWhFY,1788
|
|
2
|
+
localstack/sdk/version.py,sha256=ec2Z7PaqvzgZRNB7nlF-1rjRQAxFW73ubpJttENKtq0,511
|
|
3
|
+
localstack/sdk/aws/__init__.py,sha256=Das2FPp0t5hl_gxEP8Nw6MigVxBU8HxePF5ZKq_YNkM,73
|
|
4
|
+
localstack/sdk/aws/client.py,sha256=zz8LBLAju-f7g2_8g4zOjlMsdvQfHPuwcO1ZTihvg5o,7072
|
|
5
|
+
localstack/sdk/chaos/__init__.py,sha256=czMV7U_iDgUPBObl6nmWQxl78cF-zVl1c8QPY5tnQg4,79
|
|
6
|
+
localstack/sdk/chaos/client.py,sha256=QYI3uAvgGW7YxCJcXQqxjsmCYdj8nfMtD08a-KxX5oo,2619
|
|
7
|
+
localstack/sdk/chaos/managers.py,sha256=FqiVkOLOuVXs-RN3E2IyI5WVZcHnIdUVqyJxX_TSGrI,562
|
|
8
|
+
localstack/sdk/pods/__init__.py,sha256=49ilbKnbGpIRcv0w71nEp4RvDFtkxfrvrUVdrSLFltI,76
|
|
9
|
+
localstack/sdk/pods/client.py,sha256=VEyCt-1bP0cKjoBaP20PDXkv8ISOiXGjxuaipJTcj-k,4982
|
|
10
|
+
localstack/sdk/pods/exceptions.py,sha256=qYk9Yb_UtqJw1G8DTeysdQhE90meGgEAsxh75sEsERQ,623
|
|
11
|
+
localstack/sdk/state/__init__.py,sha256=gHCAz6H0FLwsg72361MbVpdL-YsuTH8GdaTmhKUgkL4,79
|
|
12
|
+
localstack/sdk/state/client.py,sha256=K0xK9sAbd7pwE0pSLpoGu12KZYCrEiMu3Ha8j2DHT-Q,512
|
|
13
|
+
localstack/sdk/testing/__init__.py,sha256=ywPtBMD5jTd3VgVQ8Ym8JctuBoIEgiTNLu5XPJmZVAA,81
|
|
14
|
+
localstack/sdk/testing/decorators.py,sha256=apIrL1Mm8rgsqEEykdKPdQQtYbw-tB0iOaDDo-sMCqM,976
|
|
15
|
+
localstack/sdk/testing/pytest/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
localstack/sdk/testing/pytest/plugins.py,sha256=Q5SD-TgaV-nBVvBT6koEs4FQRtMb_6l4rbjJerTejhw,265
|
|
17
|
+
localstack_sdk_python-4.3.0.dist-info/licenses/LICENSE.txt,sha256=3PC-9Z69UsNARuQ980gNR_JsLx8uvMjdG6C7cc4LBYs,606
|
|
18
|
+
localstack_sdk_python-4.3.0.dist-info/METADATA,sha256=hE1OPGEC1mR6LUnvJFc8Dprn2L4r-RyYIif6P6YhHcg,2738
|
|
19
|
+
localstack_sdk_python-4.3.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
20
|
+
localstack_sdk_python-4.3.0.dist-info/entry_points.txt,sha256=UuFkdg7bQ1BXfsrs3LCrWexP1Sm-C-wD26XEoSmibLc,62
|
|
21
|
+
localstack_sdk_python-4.3.0.dist-info/top_level.txt,sha256=3sqmK2lGac8nCy8nwsbS5SpIY_izmtWtgaTFKHYVHbI,11
|
|
22
|
+
localstack_sdk_python-4.3.0.dist-info/RECORD,,
|
localstack/clients.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from localstack.sdk.api_client import ApiClient
|
|
4
|
-
from localstack.sdk.configuration import Configuration
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class BaseClient:
|
|
8
|
-
"""A BaseClient creates a configuration and instantiate a ApiClient"""
|
|
9
|
-
|
|
10
|
-
configuration: Configuration
|
|
11
|
-
_api_client: ApiClient
|
|
12
|
-
auth_token: str | None
|
|
13
|
-
|
|
14
|
-
def __init__(self, host: str | None = None, auth_token: str | None = None, **kwargs) -> None:
|
|
15
|
-
_host = host or "http://localhost.localstack.cloud:4566"
|
|
16
|
-
self.auth_token = auth_token or os.getenv("LOCALSTACK_AUTH_TOKEN", "").strip("'\" ")
|
|
17
|
-
self.configuration = Configuration(host=_host)
|
|
18
|
-
self._api_client = ApiClient(configuration=self.configuration)
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: localstack-sdk-python
|
|
3
|
-
Version: 0.0.3
|
|
4
|
-
Summary: Python SDK for LocalStack
|
|
5
|
-
Author-email: LocalStack Team <info@localstack.cloud>
|
|
6
|
-
Project-URL: Homepage, https://localstack.cloud
|
|
7
|
-
Project-URL: Documentation, https://docs.localstack.cloud
|
|
8
|
-
Project-URL: Repository, https://github.com/localstack/localstack-sdk-python.git
|
|
9
|
-
Project-URL: Issues, https://github.com/localstack/localstack-sdk-python/issues
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE.txt
|
|
12
|
-
Requires-Dist: localstack-sdk-generated
|
|
13
|
-
|
|
14
|
-
# LocalStack Python SDK
|
|
15
|
-
|
|
16
|
-
This is the Python SDK for LocalStack.
|
|
17
|
-
LocalStack offers a number of developer endpoints (see [docs](https://docs.localstack.cloud/references/internal-endpoints/)).
|
|
18
|
-
This SDK provides a programmatic and easy way to interact with them.
|
|
19
|
-
|
|
20
|
-
> [!WARNING]
|
|
21
|
-
> This project is still in a preview phase, and will be subject to fast and breaking changes.
|
|
22
|
-
|
|
23
|
-
### Project Structure
|
|
24
|
-
|
|
25
|
-
This project follows the following structure:
|
|
26
|
-
|
|
27
|
-
- `packages/localstack-sdk-generated` is a python project generated from the OpenAPI specs with [openapi-generator](https://github.com/OpenAPITools/openapi-generator).
|
|
28
|
-
- `localstack-sdk-python` is the main project that has `localstack-sdk-generated` has the main dependency.
|
|
29
|
-
|
|
30
|
-
Developers are not supposed to modify at all `localstack-sdk-generated`.
|
|
31
|
-
The code needs to be every time re-generated from specs using the `generate.sh` script in the `bin` folder.
|
|
32
|
-
|
|
33
|
-
This project uses [uv](https://github.com/astral-sh/uv) as package/project manager.
|
|
34
|
-
|
|
35
|
-
### Install & Run
|
|
36
|
-
|
|
37
|
-
You can simply run `make install-dev` to install the two packages and the needed dependencies.
|
|
38
|
-
`make test` runs the test suite.
|
|
39
|
-
Note that LocalStack (pro) should be running in the background to execute the test.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
localstack/clients.py,sha256=UFBz23vDc48uGl1ton1-ejjQb-nnHnj0YEGVBelz57E,680
|
|
2
|
-
localstack/sdk/aws/__init__.py,sha256=Das2FPp0t5hl_gxEP8Nw6MigVxBU8HxePF5ZKq_YNkM,73
|
|
3
|
-
localstack/sdk/aws/client.py,sha256=TGemZuxjbojlq-kWEJNoVBGGg3a3Jshk2XF-PXd97RE,2333
|
|
4
|
-
localstack/sdk/chaos/__init__.py,sha256=czMV7U_iDgUPBObl6nmWQxl78cF-zVl1c8QPY5tnQg4,79
|
|
5
|
-
localstack/sdk/chaos/client.py,sha256=l5hJ8NNLNv2FaSp8lol8fOXZCcAL7DRDV2X_wFGYwxc,1506
|
|
6
|
-
localstack/sdk/chaos/managers.py,sha256=v9oKvotSmz3npEadYtrYBumCuISdxPeol_YGYYQQlGw,386
|
|
7
|
-
localstack/sdk/pods/__init__.py,sha256=49ilbKnbGpIRcv0w71nEp4RvDFtkxfrvrUVdrSLFltI,76
|
|
8
|
-
localstack/sdk/pods/client.py,sha256=YzHQBLbEaDb-veNS2NwDZrND12kFSAVoy5cm-hmS4-M,2909
|
|
9
|
-
localstack/sdk/state/__init__.py,sha256=gHCAz6H0FLwsg72361MbVpdL-YsuTH8GdaTmhKUgkL4,79
|
|
10
|
-
localstack/sdk/state/client.py,sha256=BISI3O-lM0hRIKJVGOPstlPcO6G9uFfYHp5vPOE6ztw,327
|
|
11
|
-
localstack_sdk_python-0.0.3.dist-info/LICENSE.txt,sha256=3PC-9Z69UsNARuQ980gNR_JsLx8uvMjdG6C7cc4LBYs,606
|
|
12
|
-
localstack_sdk_python-0.0.3.dist-info/METADATA,sha256=cZSAkz6TRLGu1R0_IdrtNI-SdXxkDxPfhUA9WXcFZMA,1740
|
|
13
|
-
localstack_sdk_python-0.0.3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
14
|
-
localstack_sdk_python-0.0.3.dist-info/top_level.txt,sha256=3sqmK2lGac8nCy8nwsbS5SpIY_izmtWtgaTFKHYVHbI,11
|
|
15
|
-
localstack_sdk_python-0.0.3.dist-info/RECORD,,
|
{localstack_sdk_python-0.0.3.dist-info → localstack_sdk_python-4.3.0.dist-info/licenses}/LICENSE.txt
RENAMED
|
File without changes
|
{localstack_sdk_python-0.0.3.dist-info → localstack_sdk_python-4.3.0.dist-info}/top_level.txt
RENAMED
|
File without changes
|