capo-cloudcontrol 0.2.0__tar.gz → 0.4.0__tar.gz
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.
- {capo_cloudcontrol-0.2.0/src/capo_cloudcontrol.egg-info → capo_cloudcontrol-0.4.0}/PKG-INFO +2 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/pyproject.toml +2 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_auth/_signers.py +54 -17
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_auth/_sigv4.py +164 -19
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/cancel_resource_request.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/create_resource.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/delete_resource.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/get_resource.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/get_resource_request_status.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/list_resource_requests.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/list_resources.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_operations/cloud_api_service/update_resource.py +3 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/eventstream.py +15 -13
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_services/_pipeline.py +17 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0/src/capo_cloudcontrol.egg-info}/PKG-INFO +2 -2
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/tests/test_sigv4.py +217 -16
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/LICENSE +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/README.md +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/setup.cfg +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/__init__.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_async.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_auth/_identity.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_auth/_providers.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_auth/_zapros_handler.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_body.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_iter.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_pagination.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/__init__.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/errors.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/serialize.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/xml.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_rule_engine/__init__.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_rule_engine/_aws_partition.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_rule_engine/_endpoint_rule_set.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_rule_engine/_endpoint_runtime.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_services/_aws_config.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_services/async_cloud_control.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_services/cloud_control.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/__init__.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/_base.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/already_exists_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/client_token_conflict_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/concurrent_modification_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/concurrent_operation_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/general_service_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/handler_failure_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/handler_internal_failure_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/invalid_credentials_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/invalid_request_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/network_failure_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/not_stabilized_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/not_updatable_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/private_type_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/request_token_not_found_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/resource_conflict_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/resource_not_found_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/service_internal_error_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/service_limit_exceeded_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/throttling_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/type_not_found_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/errors/unsupported_action_exception.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/py.typed +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/_prelude/blob.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/_prelude/timestamp.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/cancel_resource_request_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/cancel_resource_request_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/client_token.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/create_resource_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/create_resource_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/delete_resource_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/delete_resource_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/error_message.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/get_resource_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/get_resource_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/get_resource_request_status_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/get_resource_request_status_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/handler_error_code.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/handler_next_token.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hook_failure_mode.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hook_invocation_point.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hook_progress_event.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hook_status.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hook_type_arn.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/hooks_progress_event.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/identifier.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/list_resource_requests_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/list_resource_requests_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/list_resources_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/list_resources_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/max_results.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/next_token.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/operation.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/operation_status.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/operation_statuses.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/operations.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/patch_document.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/progress_event.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/properties.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/request_token.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/resource_description.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/resource_descriptions.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/resource_request_status_filter.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/resource_request_status_summaries.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/role_arn.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/status_message.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/timestamp.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/type_name.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/type_version_id.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/update_resource_input.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/types/update_resource_output.py +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol.egg-info/SOURCES.txt +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol.egg-info/dependency_links.txt +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol.egg-info/requires.txt +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol.egg-info/top_level.txt +0 -0
- {capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/tests/test_body.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: capo-cloudcontrol
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Python SDK for Cloudcontrol.
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Python SDK for AWS Cloudcontrol.
|
|
5
5
|
Classifier: Development Status :: 4 - Beta
|
|
6
6
|
Classifier: Intended Audience :: Developers
|
|
7
7
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -7,7 +7,11 @@ from zapros import Request
|
|
|
7
7
|
|
|
8
8
|
from capo_cloudcontrol._auth._identity import Credentials, Identity
|
|
9
9
|
from capo_cloudcontrol._auth._providers import IdentityProvider
|
|
10
|
-
from capo_cloudcontrol._auth._sigv4 import
|
|
10
|
+
from capo_cloudcontrol._auth._sigv4 import (
|
|
11
|
+
S3_SIGNING_NAMES,
|
|
12
|
+
SigV4AuthContext,
|
|
13
|
+
sign_sigv4,
|
|
14
|
+
)
|
|
11
15
|
|
|
12
16
|
IdentityT = TypeVar("IdentityT", bound="Identity")
|
|
13
17
|
|
|
@@ -30,14 +34,25 @@ class SigV4Signer(Signer[Credentials]):
|
|
|
30
34
|
The full auth scheme (``name`` variant, ``signingName``, ``signingRegion``,
|
|
31
35
|
encoding/normalization flags) is provided by the caller — either from the
|
|
32
36
|
endpoint rule-set's ``authSchemes`` property or built by the generated
|
|
33
|
-
``get_signer`` from operation defaults.
|
|
37
|
+
``get_signer`` from operation defaults. ``unsigned_payload`` mirrors the
|
|
38
|
+
operation's ``aws.auth#unsignedPayload`` trait: the body is sent but left
|
|
39
|
+
out of the signature. ``event_stream`` marks a request event stream: the
|
|
40
|
+
request is signed with the ``STREAMING-AWS4-HMAC-SHA256-EVENTS`` payload
|
|
41
|
+
marker and every event with a signature chained from it.
|
|
34
42
|
"""
|
|
35
43
|
|
|
36
44
|
def __init__(
|
|
37
|
-
self,
|
|
45
|
+
self,
|
|
46
|
+
provider: IdentityProvider[Credentials],
|
|
47
|
+
*,
|
|
48
|
+
auth_scheme: dict[str, Any],
|
|
49
|
+
unsigned_payload: bool = False,
|
|
50
|
+
event_stream: bool = False,
|
|
38
51
|
) -> None:
|
|
39
52
|
super().__init__(provider)
|
|
40
53
|
self._auth_scheme = auth_scheme
|
|
54
|
+
self._unsigned_payload = unsigned_payload
|
|
55
|
+
self._event_stream = event_stream
|
|
41
56
|
|
|
42
57
|
async def asign(self, req: Request) -> Request:
|
|
43
58
|
creds = await self.provider.aresolve_identity()
|
|
@@ -55,13 +70,24 @@ class SigV4Signer(Signer[Credentials]):
|
|
|
55
70
|
"disableNormalizePath", False
|
|
56
71
|
),
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
body
|
|
64
|
-
|
|
73
|
+
unsigned_payload = self._unsigned_payload
|
|
74
|
+
if (
|
|
75
|
+
not unsigned_payload
|
|
76
|
+
and not self._event_stream
|
|
77
|
+
and req.body is not None
|
|
78
|
+
and not isinstance(req.body, bytes)
|
|
79
|
+
):
|
|
80
|
+
if self._auth_scheme["signingName"] in S3_SIGNING_NAMES:
|
|
81
|
+
# S3 accepts UNSIGNED-PAYLOAD for any operation; streamed bodies rely on it.
|
|
82
|
+
unsigned_payload = True
|
|
83
|
+
else:
|
|
84
|
+
raise NotImplementedError(
|
|
85
|
+
"Currently we don't support signed chunked payloads, so buffer the body and "
|
|
86
|
+
"pass bytes as a workaround; chunked signed implementation coming soon"
|
|
87
|
+
)
|
|
88
|
+
return sign_sigv4(
|
|
89
|
+
req, ctx, unsigned_payload=unsigned_payload, event_stream=self._event_stream
|
|
90
|
+
)
|
|
65
91
|
|
|
66
92
|
def sign(self, req: Request) -> Request:
|
|
67
93
|
creds = self.provider.resolve_identity()
|
|
@@ -79,10 +105,21 @@ class SigV4Signer(Signer[Credentials]):
|
|
|
79
105
|
"disableNormalizePath", False
|
|
80
106
|
),
|
|
81
107
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
body
|
|
88
|
-
|
|
108
|
+
unsigned_payload = self._unsigned_payload
|
|
109
|
+
if (
|
|
110
|
+
not unsigned_payload
|
|
111
|
+
and not self._event_stream
|
|
112
|
+
and req.body is not None
|
|
113
|
+
and not isinstance(req.body, bytes)
|
|
114
|
+
):
|
|
115
|
+
if self._auth_scheme["signingName"] in S3_SIGNING_NAMES:
|
|
116
|
+
# S3 accepts UNSIGNED-PAYLOAD for any operation; streamed bodies rely on it.
|
|
117
|
+
unsigned_payload = True
|
|
118
|
+
else:
|
|
119
|
+
raise NotImplementedError(
|
|
120
|
+
"Currently we don't support signed chunked payloads, so buffer the body and "
|
|
121
|
+
"pass bytes as a workaround; chunked signed implementation coming soon"
|
|
122
|
+
)
|
|
123
|
+
return sign_sigv4(
|
|
124
|
+
req, ctx, unsigned_payload=unsigned_payload, event_stream=self._event_stream
|
|
125
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""AWS Signature Version 4 — single-chunk signing.
|
|
1
|
+
"""AWS Signature Version 4 — single-chunk and event-stream signing.
|
|
2
2
|
|
|
3
3
|
Reference:
|
|
4
4
|
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-create-signed-request.html
|
|
@@ -15,7 +15,8 @@ import functools
|
|
|
15
15
|
import hashlib
|
|
16
16
|
import hmac
|
|
17
17
|
import re
|
|
18
|
-
from
|
|
18
|
+
from collections.abc import AsyncIterator, Iterator
|
|
19
|
+
from typing import Any, Literal, TypedDict, cast
|
|
19
20
|
from urllib.parse import quote, unquote
|
|
20
21
|
|
|
21
22
|
import zapros
|
|
@@ -23,6 +24,9 @@ from pywhatwgurl import URLSearchParams
|
|
|
23
24
|
from zapros import Headers, Request
|
|
24
25
|
from zapros._utils import get_host_header_value
|
|
25
26
|
|
|
27
|
+
from .._iter import AnyIterator
|
|
28
|
+
from .._protocol.eventstream import HeaderValue, Message, encode_headers
|
|
29
|
+
|
|
26
30
|
|
|
27
31
|
def build_sigv4_auth_scheme(
|
|
28
32
|
signing_name: str, region: str | None, endpoint_scheme: dict[str, Any] | None = None
|
|
@@ -65,6 +69,10 @@ class SigV4AuthContext(TypedDict):
|
|
|
65
69
|
|
|
66
70
|
|
|
67
71
|
_SIGV4_ALGORITHM = "AWS4-HMAC-SHA256"
|
|
72
|
+
# Per-event algorithm and request payload marker of a signed event stream.
|
|
73
|
+
_EVENT_ALGORITHM = "AWS4-HMAC-SHA256-PAYLOAD"
|
|
74
|
+
_EVENT_STREAM_PAYLOAD = "STREAMING-AWS4-HMAC-SHA256-EVENTS"
|
|
75
|
+
_AMZ_DATE_FORMAT = "%Y%m%dT%H%M%SZ"
|
|
68
76
|
_EMPTY_PAYLOAD_SHA256 = hashlib.sha256(b"").hexdigest()
|
|
69
77
|
|
|
70
78
|
# Headers excluded from the signed-headers set. Mirrors botocore's denylist:
|
|
@@ -95,9 +103,11 @@ _UNSIGNED_HEADERS = frozenset(
|
|
|
95
103
|
|
|
96
104
|
_MULTI_SPACE = re.compile(r" +")
|
|
97
105
|
|
|
98
|
-
# Services that require the payload hash to travel in ``x-amz-content-sha256
|
|
99
|
-
#
|
|
100
|
-
|
|
106
|
+
# Services that require the payload hash to travel in ``x-amz-content-sha256``
|
|
107
|
+
# on every request, and that accept ``UNSIGNED-PAYLOAD`` for any operation.
|
|
108
|
+
# Other services sign the hash into the canonical request without sending it,
|
|
109
|
+
# and only see the header when the payload is left unsigned.
|
|
110
|
+
S3_SIGNING_NAMES = frozenset({"s3", "s3express", "s3-outposts", "s3-object-lambda"})
|
|
101
111
|
|
|
102
112
|
|
|
103
113
|
def _uri_encode(value: str) -> str:
|
|
@@ -231,12 +241,20 @@ def _canonical_query_from_pairs(pairs: list[tuple[str, str]]) -> str:
|
|
|
231
241
|
def sign_sigv4(
|
|
232
242
|
request: Request,
|
|
233
243
|
ctx: SigV4AuthContext,
|
|
234
|
-
|
|
244
|
+
*,
|
|
245
|
+
unsigned_payload: bool = False,
|
|
246
|
+
event_stream: bool = False,
|
|
235
247
|
) -> Request:
|
|
236
248
|
"""Return a new ``Request`` carrying SigV4 single-chunk auth headers.
|
|
237
249
|
|
|
238
|
-
|
|
239
|
-
|
|
250
|
+
The payload hash covers ``request.body``, which must be ``bytes`` or
|
|
251
|
+
``None``. ``unsigned_payload`` signs ``UNSIGNED-PAYLOAD`` instead and
|
|
252
|
+
forwards any body unchanged (streaming S3 requests and operations carrying
|
|
253
|
+
``aws.auth#unsignedPayload``). ``event_stream`` signs a request event
|
|
254
|
+
stream: the ``STREAMING-AWS4-HMAC-SHA256-EVENTS`` marker stands in for the
|
|
255
|
+
payload hash and the body — an iterator of encoded event messages — is
|
|
256
|
+
wrapped in an :class:`EventStreamIterator` that signs every event with a
|
|
257
|
+
signature chained from this request's.
|
|
240
258
|
"""
|
|
241
259
|
service = ctx["signing_name"]
|
|
242
260
|
region = ctx["signing_region"]
|
|
@@ -250,21 +268,31 @@ def sign_sigv4(
|
|
|
250
268
|
date_stamp = amz_date[:8]
|
|
251
269
|
else:
|
|
252
270
|
now = _amz_now()
|
|
253
|
-
amz_date = now.strftime(
|
|
271
|
+
amz_date = now.strftime(_AMZ_DATE_FORMAT)
|
|
254
272
|
date_stamp = now.strftime("%Y%m%d")
|
|
255
273
|
headers["X-Amz-Date"] = amz_date
|
|
256
274
|
|
|
257
|
-
# Payload hash. For S3-family services, x-amz-content-sha256 is mandatory
|
|
258
|
-
#
|
|
275
|
+
# Payload hash. For S3-family services, x-amz-content-sha256 is mandatory;
|
|
276
|
+
# for every service it is the only way to announce an unsigned payload or
|
|
277
|
+
# an event stream.
|
|
278
|
+
# Either way it must be set BEFORE computing the canonical request (it
|
|
279
|
+
# gets signed).
|
|
259
280
|
payload_hash = headers.get("X-Amz-Content-SHA256")
|
|
260
281
|
if payload_hash is None:
|
|
261
|
-
if
|
|
282
|
+
if event_stream:
|
|
283
|
+
payload_hash = _EVENT_STREAM_PAYLOAD
|
|
284
|
+
elif unsigned_payload:
|
|
262
285
|
payload_hash = "UNSIGNED-PAYLOAD"
|
|
286
|
+
elif request.body is None:
|
|
287
|
+
payload_hash = _EMPTY_PAYLOAD_SHA256
|
|
288
|
+
elif isinstance(request.body, bytes):
|
|
289
|
+
payload_hash = hashlib.sha256(request.body).hexdigest()
|
|
263
290
|
else:
|
|
264
|
-
|
|
265
|
-
|
|
291
|
+
raise TypeError(
|
|
292
|
+
"sign_sigv4 hashes a bytes body only; pass unsigned_payload=True "
|
|
293
|
+
"to send a streamed body without a payload hash"
|
|
266
294
|
)
|
|
267
|
-
if service in
|
|
295
|
+
if service in S3_SIGNING_NAMES or unsigned_payload or event_stream:
|
|
268
296
|
headers["X-Amz-Content-SHA256"] = payload_hash
|
|
269
297
|
|
|
270
298
|
# Session token (STS / assumed-role credentials).
|
|
@@ -308,18 +336,135 @@ def sign_sigv4(
|
|
|
308
336
|
f"Signature={signature}"
|
|
309
337
|
)
|
|
310
338
|
|
|
311
|
-
|
|
312
|
-
if
|
|
339
|
+
body = request.body
|
|
340
|
+
if event_stream:
|
|
341
|
+
if not isinstance(body, (Iterator, AsyncIterator)):
|
|
342
|
+
raise TypeError(
|
|
343
|
+
"event_stream requires an iterator of encoded events as the body"
|
|
344
|
+
)
|
|
345
|
+
body = EventStreamIterator(
|
|
346
|
+
cast("Iterator[bytes] | AsyncIterator[bytes]", body), ctx, signature
|
|
347
|
+
)
|
|
348
|
+
if body is not None:
|
|
313
349
|
return Request(
|
|
314
350
|
request.url,
|
|
315
351
|
request.method,
|
|
316
352
|
headers,
|
|
317
|
-
body=
|
|
353
|
+
body=body,
|
|
318
354
|
context=request.context,
|
|
319
355
|
)
|
|
320
356
|
return Request(request.url, request.method, headers, context=request.context)
|
|
321
357
|
|
|
322
358
|
|
|
359
|
+
def _sign_event(
|
|
360
|
+
ctx: SigV4AuthContext, prior_signature: str, payload: bytes
|
|
361
|
+
) -> tuple[bytes, str]:
|
|
362
|
+
"""Wrap one encoded event in a signed outer message.
|
|
363
|
+
|
|
364
|
+
Returns ``(frame, signature)``; the hex signature seeds the next event.
|
|
365
|
+
The string to sign chains every frame to its predecessor — the first one
|
|
366
|
+
to the request's ``Authorization`` signature — so the service can verify
|
|
367
|
+
the stream incrementally::
|
|
368
|
+
|
|
369
|
+
AWS4-HMAC-SHA256-PAYLOAD
|
|
370
|
+
<date, YYYYMMDDTHHMMSSZ>
|
|
371
|
+
<credential scope>
|
|
372
|
+
<prior signature, hex>
|
|
373
|
+
<hex sha256 of the encoded ``:date`` header>
|
|
374
|
+
<hex sha256 of the payload>
|
|
375
|
+
|
|
376
|
+
The AWS SDKs (and the service) use the ``-PAYLOAD`` algorithm name; the
|
|
377
|
+
Transcribe developer guide's pseudocode omits the suffix.
|
|
378
|
+
"""
|
|
379
|
+
service = ctx["signing_name"]
|
|
380
|
+
region = ctx["signing_region"]
|
|
381
|
+
now = _amz_now()
|
|
382
|
+
amz_date = now.strftime(_AMZ_DATE_FORMAT)
|
|
383
|
+
date_stamp = amz_date[:8]
|
|
384
|
+
credential_scope = f"{date_stamp}/{region}/{service}/aws4_request"
|
|
385
|
+
date_header: dict[str, HeaderValue] = {":date": now}
|
|
386
|
+
string_to_sign = "\n".join(
|
|
387
|
+
(
|
|
388
|
+
_EVENT_ALGORITHM,
|
|
389
|
+
amz_date,
|
|
390
|
+
credential_scope,
|
|
391
|
+
prior_signature,
|
|
392
|
+
hashlib.sha256(encode_headers(date_header)).hexdigest(),
|
|
393
|
+
hashlib.sha256(payload).hexdigest(),
|
|
394
|
+
)
|
|
395
|
+
)
|
|
396
|
+
signing_key = _derive_signing_key(
|
|
397
|
+
ctx["secret_access_key"], date_stamp, region, service
|
|
398
|
+
)
|
|
399
|
+
signature = hmac.new(
|
|
400
|
+
signing_key, string_to_sign.encode("utf-8"), hashlib.sha256
|
|
401
|
+
).hexdigest()
|
|
402
|
+
frame = Message(
|
|
403
|
+
{**date_header, ":chunk-signature": bytes.fromhex(signature)}, payload
|
|
404
|
+
).encode()
|
|
405
|
+
return frame, signature
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class EventStreamIterator(AnyIterator[bytes]):
|
|
409
|
+
"""Sign a request event stream, one frame per event.
|
|
410
|
+
|
|
411
|
+
Wraps an iterator of encoded event messages (as produced by the generated
|
|
412
|
+
``serialize_event_*`` functions). Each event becomes the payload of an
|
|
413
|
+
outer message carrying ``:date`` and ``:chunk-signature`` headers, the
|
|
414
|
+
signature chained from the previous frame's and seeded by the request's
|
|
415
|
+
``Authorization`` signature. Once the events are exhausted, one empty
|
|
416
|
+
signed frame is yielded to mark the end of the stream.
|
|
417
|
+
|
|
418
|
+
Like :class:`~capo._body.Body`, it is both a sync and an async iterator:
|
|
419
|
+
iterate it the way the wrapped source is iterable (``next`` over a sync
|
|
420
|
+
source, ``async for`` over an async one).
|
|
421
|
+
|
|
422
|
+
Reference:
|
|
423
|
+
https://docs.aws.amazon.com/transcribe/latest/dg/streaming-setting-up.html
|
|
424
|
+
"""
|
|
425
|
+
|
|
426
|
+
def __init__(
|
|
427
|
+
self,
|
|
428
|
+
events: Iterator[bytes] | AsyncIterator[bytes],
|
|
429
|
+
ctx: SigV4AuthContext,
|
|
430
|
+
seed_signature: str,
|
|
431
|
+
) -> None:
|
|
432
|
+
self._events = events
|
|
433
|
+
self._ctx = ctx
|
|
434
|
+
self._prior_signature = seed_signature
|
|
435
|
+
self._ended = False
|
|
436
|
+
|
|
437
|
+
def _frame(self, payload: bytes) -> bytes:
|
|
438
|
+
frame, self._prior_signature = _sign_event(
|
|
439
|
+
self._ctx, self._prior_signature, payload
|
|
440
|
+
)
|
|
441
|
+
return frame
|
|
442
|
+
|
|
443
|
+
def __next__(self) -> bytes:
|
|
444
|
+
if self._ended:
|
|
445
|
+
raise StopIteration
|
|
446
|
+
if not isinstance(self._events, Iterator):
|
|
447
|
+
raise TypeError("this event stream wraps an async source; use `async for`")
|
|
448
|
+
try:
|
|
449
|
+
payload = next(cast(Iterator[bytes], self._events))
|
|
450
|
+
except StopIteration:
|
|
451
|
+
self._ended = True
|
|
452
|
+
payload = b""
|
|
453
|
+
return self._frame(payload)
|
|
454
|
+
|
|
455
|
+
async def __anext__(self) -> bytes:
|
|
456
|
+
if self._ended:
|
|
457
|
+
raise StopAsyncIteration
|
|
458
|
+
if not isinstance(self._events, AsyncIterator):
|
|
459
|
+
raise TypeError("this event stream wraps a sync source; use `for`")
|
|
460
|
+
try:
|
|
461
|
+
payload = await cast(AsyncIterator[bytes], self._events).__anext__()
|
|
462
|
+
except StopAsyncIteration:
|
|
463
|
+
self._ended = True
|
|
464
|
+
payload = b""
|
|
465
|
+
return self._frame(payload)
|
|
466
|
+
|
|
467
|
+
|
|
323
468
|
def presign_sigv4(
|
|
324
469
|
request: Request,
|
|
325
470
|
ctx: SigV4AuthContext,
|
|
@@ -346,7 +491,7 @@ def presign_sigv4(
|
|
|
346
491
|
service = ctx["signing_name"]
|
|
347
492
|
region = ctx["signing_region"]
|
|
348
493
|
|
|
349
|
-
amz_date = sign_time.strftime(
|
|
494
|
+
amz_date = sign_time.strftime(_AMZ_DATE_FORMAT)
|
|
350
495
|
date_stamp = sign_time.strftime("%Y%m%d")
|
|
351
496
|
credential_scope = f"{date_stamp}/{region}/{service}/aws4_request"
|
|
352
497
|
|
|
@@ -21,6 +21,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
21
21
|
from capo_cloudcontrol._services._pipeline import (
|
|
22
22
|
AsyncOperationOptions,
|
|
23
23
|
OperationOptions,
|
|
24
|
+
raise_error,
|
|
24
25
|
)
|
|
25
26
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
26
27
|
|
|
@@ -130,7 +131,7 @@ def cancel_resource_request(
|
|
|
130
131
|
try:
|
|
131
132
|
if response.status >= 300:
|
|
132
133
|
response.read()
|
|
133
|
-
|
|
134
|
+
raise_error(response, handle_error)
|
|
134
135
|
return handle_response(response), response
|
|
135
136
|
except BaseException:
|
|
136
137
|
response.close()
|
|
@@ -148,7 +149,7 @@ async def async_cancel_resource_request(
|
|
|
148
149
|
try:
|
|
149
150
|
if response.status >= 300:
|
|
150
151
|
await response.aread()
|
|
151
|
-
|
|
152
|
+
raise_error(response, handle_error)
|
|
152
153
|
return await async_handle_response(response), response
|
|
153
154
|
except BaseException:
|
|
154
155
|
await response.aclose()
|
|
@@ -38,6 +38,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
38
38
|
from capo_cloudcontrol._services._pipeline import (
|
|
39
39
|
AsyncOperationOptions,
|
|
40
40
|
OperationOptions,
|
|
41
|
+
raise_error,
|
|
41
42
|
)
|
|
42
43
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
43
44
|
|
|
@@ -216,7 +217,7 @@ def create_resource(
|
|
|
216
217
|
try:
|
|
217
218
|
if response.status >= 300:
|
|
218
219
|
response.read()
|
|
219
|
-
|
|
220
|
+
raise_error(response, handle_error)
|
|
220
221
|
return handle_response(response), response
|
|
221
222
|
except BaseException:
|
|
222
223
|
response.close()
|
|
@@ -233,7 +234,7 @@ async def async_create_resource(
|
|
|
233
234
|
try:
|
|
234
235
|
if response.status >= 300:
|
|
235
236
|
await response.aread()
|
|
236
|
-
|
|
237
|
+
raise_error(response, handle_error)
|
|
237
238
|
return await async_handle_response(response), response
|
|
238
239
|
except BaseException:
|
|
239
240
|
await response.aclose()
|
|
@@ -38,6 +38,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
38
38
|
from capo_cloudcontrol._services._pipeline import (
|
|
39
39
|
AsyncOperationOptions,
|
|
40
40
|
OperationOptions,
|
|
41
|
+
raise_error,
|
|
41
42
|
)
|
|
42
43
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
43
44
|
|
|
@@ -216,7 +217,7 @@ def delete_resource(
|
|
|
216
217
|
try:
|
|
217
218
|
if response.status >= 300:
|
|
218
219
|
response.read()
|
|
219
|
-
|
|
220
|
+
raise_error(response, handle_error)
|
|
220
221
|
return handle_response(response), response
|
|
221
222
|
except BaseException:
|
|
222
223
|
response.close()
|
|
@@ -233,7 +234,7 @@ async def async_delete_resource(
|
|
|
233
234
|
try:
|
|
234
235
|
if response.status >= 300:
|
|
235
236
|
await response.aread()
|
|
236
|
-
|
|
237
|
+
raise_error(response, handle_error)
|
|
237
238
|
return await async_handle_response(response), response
|
|
238
239
|
except BaseException:
|
|
239
240
|
await response.aclose()
|
|
@@ -36,6 +36,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
36
36
|
from capo_cloudcontrol._services._pipeline import (
|
|
37
37
|
AsyncOperationOptions,
|
|
38
38
|
OperationOptions,
|
|
39
|
+
raise_error,
|
|
39
40
|
)
|
|
40
41
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
41
42
|
|
|
@@ -206,7 +207,7 @@ def get_resource(
|
|
|
206
207
|
try:
|
|
207
208
|
if response.status >= 300:
|
|
208
209
|
response.read()
|
|
209
|
-
|
|
210
|
+
raise_error(response, handle_error)
|
|
210
211
|
return handle_response(response), response
|
|
211
212
|
except BaseException:
|
|
212
213
|
response.close()
|
|
@@ -223,7 +224,7 @@ async def async_get_resource(
|
|
|
223
224
|
try:
|
|
224
225
|
if response.status >= 300:
|
|
225
226
|
await response.aread()
|
|
226
|
-
|
|
227
|
+
raise_error(response, handle_error)
|
|
227
228
|
return await async_handle_response(response), response
|
|
228
229
|
except BaseException:
|
|
229
230
|
await response.aclose()
|
|
@@ -21,6 +21,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
21
21
|
from capo_cloudcontrol._services._pipeline import (
|
|
22
22
|
AsyncOperationOptions,
|
|
23
23
|
OperationOptions,
|
|
24
|
+
raise_error,
|
|
24
25
|
)
|
|
25
26
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
26
27
|
|
|
@@ -126,7 +127,7 @@ def get_resource_request_status(
|
|
|
126
127
|
try:
|
|
127
128
|
if response.status >= 300:
|
|
128
129
|
response.read()
|
|
129
|
-
|
|
130
|
+
raise_error(response, handle_error)
|
|
130
131
|
return handle_response(response), response
|
|
131
132
|
except BaseException:
|
|
132
133
|
response.close()
|
|
@@ -144,7 +145,7 @@ async def async_get_resource_request_status(
|
|
|
144
145
|
try:
|
|
145
146
|
if response.status >= 300:
|
|
146
147
|
await response.aread()
|
|
147
|
-
|
|
148
|
+
raise_error(response, handle_error)
|
|
148
149
|
return await async_handle_response(response), response
|
|
149
150
|
except BaseException:
|
|
150
151
|
await response.aclose()
|
|
@@ -20,6 +20,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
20
20
|
from capo_cloudcontrol._services._pipeline import (
|
|
21
21
|
AsyncOperationOptions,
|
|
22
22
|
OperationOptions,
|
|
23
|
+
raise_error,
|
|
23
24
|
)
|
|
24
25
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
25
26
|
|
|
@@ -121,7 +122,7 @@ def list_resource_requests(
|
|
|
121
122
|
try:
|
|
122
123
|
if response.status >= 300:
|
|
123
124
|
response.read()
|
|
124
|
-
|
|
125
|
+
raise_error(response, handle_error)
|
|
125
126
|
return handle_response(response), response
|
|
126
127
|
except BaseException:
|
|
127
128
|
response.close()
|
|
@@ -139,7 +140,7 @@ async def async_list_resource_requests(
|
|
|
139
140
|
try:
|
|
140
141
|
if response.status >= 300:
|
|
141
142
|
await response.aread()
|
|
142
|
-
|
|
143
|
+
raise_error(response, handle_error)
|
|
143
144
|
return await async_handle_response(response), response
|
|
144
145
|
except BaseException:
|
|
145
146
|
await response.aclose()
|
|
@@ -36,6 +36,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
36
36
|
from capo_cloudcontrol._services._pipeline import (
|
|
37
37
|
AsyncOperationOptions,
|
|
38
38
|
OperationOptions,
|
|
39
|
+
raise_error,
|
|
39
40
|
)
|
|
40
41
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
41
42
|
|
|
@@ -206,7 +207,7 @@ def list_resources(
|
|
|
206
207
|
try:
|
|
207
208
|
if response.status >= 300:
|
|
208
209
|
response.read()
|
|
209
|
-
|
|
210
|
+
raise_error(response, handle_error)
|
|
210
211
|
return handle_response(response), response
|
|
211
212
|
except BaseException:
|
|
212
213
|
response.close()
|
|
@@ -223,7 +224,7 @@ async def async_list_resources(
|
|
|
223
224
|
try:
|
|
224
225
|
if response.status >= 300:
|
|
225
226
|
await response.aread()
|
|
226
|
-
|
|
227
|
+
raise_error(response, handle_error)
|
|
227
228
|
return await async_handle_response(response), response
|
|
228
229
|
except BaseException:
|
|
229
230
|
await response.aclose()
|
|
@@ -38,6 +38,7 @@ from capo_cloudcontrol._rule_engine._endpoint_rule_set import EndpointParams, re
|
|
|
38
38
|
from capo_cloudcontrol._services._pipeline import (
|
|
39
39
|
AsyncOperationOptions,
|
|
40
40
|
OperationOptions,
|
|
41
|
+
raise_error,
|
|
41
42
|
)
|
|
42
43
|
from capo_cloudcontrol.errors import UnknownServiceError
|
|
43
44
|
|
|
@@ -216,7 +217,7 @@ def update_resource(
|
|
|
216
217
|
try:
|
|
217
218
|
if response.status >= 300:
|
|
218
219
|
response.read()
|
|
219
|
-
|
|
220
|
+
raise_error(response, handle_error)
|
|
220
221
|
return handle_response(response), response
|
|
221
222
|
except BaseException:
|
|
222
223
|
response.close()
|
|
@@ -233,7 +234,7 @@ async def async_update_resource(
|
|
|
233
234
|
try:
|
|
234
235
|
if response.status >= 300:
|
|
235
236
|
await response.aread()
|
|
236
|
-
|
|
237
|
+
raise_error(response, handle_error)
|
|
237
238
|
return await async_handle_response(response), response
|
|
238
239
|
except BaseException:
|
|
239
240
|
await response.aclose()
|
{capo_cloudcontrol-0.2.0 → capo_cloudcontrol-0.4.0}/src/capo_cloudcontrol/_protocol/eventstream.py
RENAMED
|
@@ -89,7 +89,7 @@ def _decode_header_value(
|
|
|
89
89
|
raise ValueError(f"unsupported eventstream header type: {type_byte:#x}")
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def
|
|
92
|
+
def encode_headers(headers: dict[str, HeaderValue]) -> bytes:
|
|
93
93
|
parts: list[bytes] = []
|
|
94
94
|
for name, value in headers.items():
|
|
95
95
|
name_bytes = name.encode("utf-8")
|
|
@@ -124,10 +124,11 @@ class Message:
|
|
|
124
124
|
|
|
125
125
|
def encode(self) -> bytes:
|
|
126
126
|
"""Serialize this message into eventstream framing bytes."""
|
|
127
|
-
headers_bytes =
|
|
127
|
+
headers_bytes = encode_headers(self.headers)
|
|
128
128
|
headers_length = len(headers_bytes)
|
|
129
129
|
payload = self.payload
|
|
130
|
-
total_length
|
|
130
|
+
# total_length covers the whole frame, trailing message CRC included.
|
|
131
|
+
total_length = 12 + headers_length + len(payload) + 4
|
|
131
132
|
|
|
132
133
|
prelude = total_length.to_bytes(4, "big") + headers_length.to_bytes(4, "big")
|
|
133
134
|
prelude_crc = zlib.crc32(prelude).to_bytes(4, "big")
|
|
@@ -158,31 +159,31 @@ class MessageDecoder:
|
|
|
158
159
|
prelude = bytes(self._buffer[:8])
|
|
159
160
|
prelude_crc = int.from_bytes(self._buffer[8:12], "big")
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
# total_length covers the whole frame: 12-byte prelude, headers,
|
|
163
|
+
# payload, and the trailing 4-byte message CRC.
|
|
164
|
+
if total_length < 16 + headers_length:
|
|
162
165
|
raise ValueError(
|
|
163
166
|
f"invalid eventstream message: total_length={total_length} "
|
|
164
|
-
f"is smaller than minimum {
|
|
167
|
+
f"is smaller than minimum {16 + headers_length}"
|
|
165
168
|
)
|
|
166
169
|
|
|
167
|
-
|
|
168
|
-
if len(self._buffer) < message_end:
|
|
170
|
+
if len(self._buffer) < total_length:
|
|
169
171
|
return
|
|
170
172
|
|
|
171
173
|
computed_prelude_crc = zlib.crc32(prelude) & 0xFFFFFFFF
|
|
172
174
|
if computed_prelude_crc != prelude_crc:
|
|
173
175
|
raise ValueError("eventstream prelude checksum mismatch")
|
|
174
176
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
177
|
+
payload_end = total_length - 4
|
|
178
|
+
message_bytes = bytes(self._buffer[:payload_end])
|
|
179
|
+
message_crc = int.from_bytes(self._buffer[payload_end:total_length], "big")
|
|
179
180
|
computed_message_crc = zlib.crc32(message_bytes) & 0xFFFFFFFF
|
|
180
181
|
if computed_message_crc != message_crc:
|
|
181
182
|
raise ValueError("eventstream message checksum mismatch")
|
|
182
183
|
|
|
183
184
|
headers = _decode_headers(self._buffer[12 : 12 + headers_length])
|
|
184
|
-
payload = bytes(self._buffer[12 + headers_length :
|
|
185
|
-
del self._buffer[:
|
|
185
|
+
payload = bytes(self._buffer[12 + headers_length : payload_end])
|
|
186
|
+
del self._buffer[:total_length]
|
|
186
187
|
yield Message(headers=headers, payload=payload)
|
|
187
188
|
|
|
188
189
|
|
|
@@ -233,6 +234,7 @@ __all__ = [
|
|
|
233
234
|
"MessageDecoder",
|
|
234
235
|
"async_raw_stream_to_events",
|
|
235
236
|
"async_read_messages",
|
|
237
|
+
"encode_headers",
|
|
236
238
|
"raw_stream_to_events",
|
|
237
239
|
"read_messages",
|
|
238
240
|
]
|