capo-keyspacesstreams 0.1.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.
Files changed (85) hide show
  1. capo_keyspacesstreams/__init__.py +74 -0
  2. capo_keyspacesstreams/_async.py +25 -0
  3. capo_keyspacesstreams/_auth/_identity.py +16 -0
  4. capo_keyspacesstreams/_auth/_providers.py +886 -0
  5. capo_keyspacesstreams/_auth/_signers.py +88 -0
  6. capo_keyspacesstreams/_auth/_sigv4.py +434 -0
  7. capo_keyspacesstreams/_auth/_zapros_handler.py +80 -0
  8. capo_keyspacesstreams/_iter.py +113 -0
  9. capo_keyspacesstreams/_operations/keyspaces_streams/get_records.py +171 -0
  10. capo_keyspacesstreams/_operations/keyspaces_streams/get_shard_iterator.py +170 -0
  11. capo_keyspacesstreams/_operations/keyspaces_streams/get_stream.py +174 -0
  12. capo_keyspacesstreams/_operations/keyspaces_streams/list_streams.py +170 -0
  13. capo_keyspacesstreams/_pagination.py +21 -0
  14. capo_keyspacesstreams/_protocol/__init__.py +1 -0
  15. capo_keyspacesstreams/_protocol/errors.py +93 -0
  16. capo_keyspacesstreams/_protocol/eventstream.py +238 -0
  17. capo_keyspacesstreams/_protocol/serialize.py +47 -0
  18. capo_keyspacesstreams/_protocol/xml.py +33 -0
  19. capo_keyspacesstreams/_rule_engine/__init__.py +0 -0
  20. capo_keyspacesstreams/_rule_engine/_aws_partition.py +160 -0
  21. capo_keyspacesstreams/_rule_engine/_endpoint_rule_set.py +65 -0
  22. capo_keyspacesstreams/_rule_engine/_endpoint_runtime.py +389 -0
  23. capo_keyspacesstreams/_services/_aws_config.py +156 -0
  24. capo_keyspacesstreams/_services/_pipeline.py +196 -0
  25. capo_keyspacesstreams/_services/async_keyspaces_streams.py +442 -0
  26. capo_keyspacesstreams/_services/keyspaces_streams.py +438 -0
  27. capo_keyspacesstreams/errors/__init__.py +32 -0
  28. capo_keyspacesstreams/errors/_base.py +94 -0
  29. capo_keyspacesstreams/errors/access_denied_exception.py +47 -0
  30. capo_keyspacesstreams/errors/internal_server_exception.py +47 -0
  31. capo_keyspacesstreams/errors/resource_not_found_exception.py +47 -0
  32. capo_keyspacesstreams/errors/throttling_exception.py +47 -0
  33. capo_keyspacesstreams/errors/validation_exception.py +72 -0
  34. capo_keyspacesstreams/py.typed +0 -0
  35. capo_keyspacesstreams/types/_prelude/blob.py +12 -0
  36. capo_keyspacesstreams/types/_prelude/timestamp.py +17 -0
  37. capo_keyspacesstreams/types/date.py +20 -0
  38. capo_keyspacesstreams/types/get_records_input.py +37 -0
  39. capo_keyspacesstreams/types/get_records_output.py +70 -0
  40. capo_keyspacesstreams/types/get_shard_iterator_input.py +70 -0
  41. capo_keyspacesstreams/types/get_shard_iterator_output.py +30 -0
  42. capo_keyspacesstreams/types/get_stream_input.py +63 -0
  43. capo_keyspacesstreams/types/get_stream_output.py +144 -0
  44. capo_keyspacesstreams/types/iterator_description.py +42 -0
  45. capo_keyspacesstreams/types/iterator_position.py +17 -0
  46. capo_keyspacesstreams/types/keyspace_name.py +5 -0
  47. capo_keyspacesstreams/types/keyspaces_cell.py +63 -0
  48. capo_keyspacesstreams/types/keyspaces_cell_list.py +35 -0
  49. capo_keyspacesstreams/types/keyspaces_cell_map.py +39 -0
  50. capo_keyspacesstreams/types/keyspaces_cell_map_definition.py +83 -0
  51. capo_keyspacesstreams/types/keyspaces_cell_value.py +333 -0
  52. capo_keyspacesstreams/types/keyspaces_cells.py +35 -0
  53. capo_keyspacesstreams/types/keyspaces_keys_map.py +39 -0
  54. capo_keyspacesstreams/types/keyspaces_metadata.py +29 -0
  55. capo_keyspacesstreams/types/keyspaces_row.py +83 -0
  56. capo_keyspacesstreams/types/keyspaces_udt_map.py +35 -0
  57. capo_keyspacesstreams/types/list_streams_input.py +50 -0
  58. capo_keyspacesstreams/types/list_streams_output.py +47 -0
  59. capo_keyspacesstreams/types/origin_type.py +18 -0
  60. capo_keyspacesstreams/types/record.py +146 -0
  61. capo_keyspacesstreams/types/record_list.py +29 -0
  62. capo_keyspacesstreams/types/sequence_number.py +5 -0
  63. capo_keyspacesstreams/types/sequence_number_range.py +38 -0
  64. capo_keyspacesstreams/types/shard.py +70 -0
  65. capo_keyspacesstreams/types/shard_description_list.py +29 -0
  66. capo_keyspacesstreams/types/shard_filter.py +47 -0
  67. capo_keyspacesstreams/types/shard_filter_type.py +14 -0
  68. capo_keyspacesstreams/types/shard_id.py +5 -0
  69. capo_keyspacesstreams/types/shard_id_list.py +17 -0
  70. capo_keyspacesstreams/types/shard_id_token.py +5 -0
  71. capo_keyspacesstreams/types/shard_iterator.py +5 -0
  72. capo_keyspacesstreams/types/shard_iterator_type.py +19 -0
  73. capo_keyspacesstreams/types/stream.py +54 -0
  74. capo_keyspacesstreams/types/stream_arn.py +5 -0
  75. capo_keyspacesstreams/types/stream_arn_token.py +5 -0
  76. capo_keyspacesstreams/types/stream_list.py +29 -0
  77. capo_keyspacesstreams/types/stream_status.py +19 -0
  78. capo_keyspacesstreams/types/stream_view_type.py +19 -0
  79. capo_keyspacesstreams/types/table_name.py +5 -0
  80. capo_keyspacesstreams/types/validation_exception_type.py +19 -0
  81. capo_keyspacesstreams-0.1.0.dist-info/METADATA +101 -0
  82. capo_keyspacesstreams-0.1.0.dist-info/RECORD +85 -0
  83. capo_keyspacesstreams-0.1.0.dist-info/WHEEL +5 -0
  84. capo_keyspacesstreams-0.1.0.dist-info/licenses/LICENSE +21 -0
  85. capo_keyspacesstreams-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,113 @@
1
+ """Iterator helpers used by generated streaming operations.
2
+
3
+ Hand-written, not regenerated.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from collections.abc import AsyncIterable, AsyncIterator, Callable, Iterable, Iterator
9
+ from typing import Generic, TypeVar, cast
10
+
11
+ T = TypeVar("T")
12
+ U = TypeVar("U")
13
+
14
+
15
+ class AnyIterator(AsyncIterator[T], Iterator[T], Generic[T]):
16
+ """A type that is both a synchronous and asynchronous iterator.
17
+
18
+ Streaming output fields use this so the same TypedDict type works for
19
+ both sync and async operation variants.
20
+ """
21
+
22
+ ...
23
+
24
+
25
+ class StaticAnyIterator(AnyIterator[T], Generic[T]):
26
+ """An :class:`AnyIterator` backed by static, in-memory content.
27
+
28
+ Used when streaming output is produced from already-materialized bytes
29
+ rather than a live stream. The ``content`` is yielded once and remains
30
+ accessible as a public attribute.
31
+ """
32
+
33
+ def __init__(self, content: T) -> None:
34
+ self.content = content
35
+ self._consumed = False
36
+
37
+ def __next__(self) -> T:
38
+ if self._consumed:
39
+ raise StopIteration
40
+ self._consumed = True
41
+ return self.content
42
+
43
+ async def __anext__(self) -> T:
44
+ if self._consumed:
45
+ raise StopAsyncIteration
46
+ self._consumed = True
47
+ return self.content
48
+
49
+
50
+ def map_sync_iterator(iterable: Iterable[T], fn: Callable[[T], U]) -> Iterator[U]:
51
+ """Map ``fn`` over a synchronous iterable, yielding results lazily."""
52
+ for item in iterable:
53
+ yield fn(item)
54
+
55
+
56
+ async def map_async_iterator(
57
+ async_iterable: AsyncIterable[T], fn: Callable[[T], U]
58
+ ) -> AsyncIterator[U]:
59
+ """Map ``fn`` over an asynchronous iterable, yielding results lazily."""
60
+ async for item in async_iterable:
61
+ yield fn(item)
62
+
63
+
64
+ def chain_sync_iterator(*iterables: Iterable[T]) -> Iterator[T]:
65
+ """Yield items from each iterable in order."""
66
+ for iterable in iterables:
67
+ yield from iterable
68
+
69
+
70
+ async def chain_async_iterator(
71
+ prefix: Iterable[T], rest: AsyncIterable[T]
72
+ ) -> AsyncIterator[T]:
73
+ """Yield the synchronous ``prefix`` items, then the async ``rest`` items."""
74
+ for item in prefix:
75
+ yield item
76
+ async for item in rest:
77
+ yield item
78
+
79
+
80
+ def ensure_async_iterator(value: AsyncIterator[T] | T) -> AnyIterator[T]:
81
+ """Return ``value`` as an :class:`AnyIterator`.
82
+
83
+ An async iterator is returned unchanged; a single value is wrapped in a
84
+ fresh single-item async iterator.
85
+ """
86
+ if isinstance(value, AsyncIterator):
87
+ return cast(AnyIterator[T], value)
88
+
89
+ return StaticAnyIterator(value)
90
+
91
+
92
+ def ensure_sync_iterator(value: Iterator[T] | T) -> AnyIterator[T]:
93
+ """Return ``value`` as an :class:`AnyIterator`.
94
+
95
+ A sync iterator is returned unchanged; a single value is wrapped in a
96
+ fresh single-item sync iterator.
97
+ """
98
+ if isinstance(value, Iterator):
99
+ return cast(AnyIterator[T], value)
100
+
101
+ return StaticAnyIterator(value)
102
+
103
+
104
+ __all__ = [
105
+ "AnyIterator",
106
+ "StaticAnyIterator",
107
+ "chain_async_iterator",
108
+ "chain_sync_iterator",
109
+ "ensure_async_iterator",
110
+ "ensure_sync_iterator",
111
+ "map_async_iterator",
112
+ "map_sync_iterator",
113
+ ]
@@ -0,0 +1,171 @@
1
+ """Generated from Smithy shape ``com.amazonaws.keyspacesstreams#GetRecords``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+ import zapros
9
+ from typing_extensions import Never
10
+
11
+ import capo_keyspacesstreams._auth._signers
12
+ import capo_keyspacesstreams._auth._sigv4
13
+ import capo_keyspacesstreams._protocol.eventstream
14
+ import capo_keyspacesstreams.errors.access_denied_exception
15
+ import capo_keyspacesstreams.errors.internal_server_exception
16
+ import capo_keyspacesstreams.errors.resource_not_found_exception
17
+ import capo_keyspacesstreams.errors.throttling_exception
18
+ import capo_keyspacesstreams.errors.validation_exception
19
+ import capo_keyspacesstreams.types.get_records_input
20
+ import capo_keyspacesstreams.types.get_records_output
21
+ import capo_keyspacesstreams.types.iterator_description
22
+ import capo_keyspacesstreams.types.record_list
23
+ from capo_keyspacesstreams._protocol.errors import parse_error_metadata_json
24
+ from capo_keyspacesstreams._rule_engine._endpoint_rule_set import (
25
+ EndpointParams,
26
+ resolve,
27
+ )
28
+ from capo_keyspacesstreams._services._pipeline import (
29
+ AsyncOperationOptions,
30
+ OperationOptions,
31
+ )
32
+ from capo_keyspacesstreams.errors import UnknownServiceError
33
+
34
+
35
+ def handle_error(response: zapros.Response) -> Never:
36
+ data = json.loads(response.read())
37
+ code, message = parse_error_metadata_json(response, data)
38
+ match code:
39
+ case "AccessDeniedException":
40
+ raise capo_keyspacesstreams.errors.access_denied_exception.AccessDeniedException.from_aws_json_1_0(
41
+ data, message
42
+ )
43
+ case "InternalServerException":
44
+ raise capo_keyspacesstreams.errors.internal_server_exception.InternalServerException.from_aws_json_1_0(
45
+ data, message
46
+ )
47
+ case "ResourceNotFoundException":
48
+ raise capo_keyspacesstreams.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_0(
49
+ data, message
50
+ )
51
+ case "ThrottlingException":
52
+ raise capo_keyspacesstreams.errors.throttling_exception.ThrottlingException.from_aws_json_1_0(
53
+ data, message
54
+ )
55
+ case "ValidationException":
56
+ raise capo_keyspacesstreams.errors.validation_exception.ValidationException.from_aws_json_1_0(
57
+ data, message
58
+ )
59
+ case _:
60
+ raise UnknownServiceError(code=code, message=message, response=response)
61
+
62
+
63
+ def handle_response(
64
+ response: zapros.Response,
65
+ ) -> capo_keyspacesstreams.types.get_records_output.GetRecordsOutput:
66
+ out: capo_keyspacesstreams.types.get_records_output.GetRecordsOutput = (
67
+ capo_keyspacesstreams.types.get_records_output.deserialize_aws_json_1_0(
68
+ json.loads(response.read())
69
+ )
70
+ )
71
+ return out
72
+
73
+
74
+ async def async_handle_response(
75
+ response: zapros.Response,
76
+ ) -> capo_keyspacesstreams.types.get_records_output.GetRecordsOutput:
77
+ out: capo_keyspacesstreams.types.get_records_output.GetRecordsOutput = (
78
+ capo_keyspacesstreams.types.get_records_output.deserialize_aws_json_1_0(
79
+ json.loads(await response.aread())
80
+ )
81
+ )
82
+ return out
83
+
84
+
85
+ def get_signer(
86
+ options: AsyncOperationOptions | OperationOptions,
87
+ auth_schemes: list[dict[str, Any]] | None = None,
88
+ ) -> capo_keyspacesstreams._auth._signers.Signer | None:
89
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
90
+ if (
91
+ options.credentials_provider is not None
92
+ and name_to_schema
93
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
94
+ ):
95
+ raise RuntimeError(
96
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
97
+ )
98
+ if options.credentials_provider is not None:
99
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
100
+ "sigv4-s3express"
101
+ )
102
+ if endpoint_scheme is not None or not name_to_schema:
103
+ sigv4_config = capo_keyspacesstreams._auth._sigv4.build_sigv4_auth_scheme(
104
+ "cassandra", options.region, endpoint_scheme
105
+ )
106
+ if sigv4_config is not None:
107
+ return capo_keyspacesstreams._auth._signers.SigV4Signer(
108
+ options.credentials_provider, auth_scheme=sigv4_config
109
+ )
110
+ raise RuntimeError("Auth was not resolved")
111
+
112
+
113
+ def build_request(
114
+ options: OperationOptions | AsyncOperationOptions,
115
+ input_: capo_keyspacesstreams.types.get_records_input.GetRecordsInput,
116
+ ) -> zapros.Request:
117
+ endpoint = resolve(
118
+ EndpointParams(
119
+ UseFIPS=options.use_fips, Endpoint=options.endpoint, Region=options.region
120
+ )
121
+ ) # noqa: F841
122
+ url = endpoint.url.rstrip("/") + ""
123
+ params: list[tuple[str, str]] = []
124
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
125
+ headers["X-Amz-Target"] = "KeyspacesStreams.GetRecords"
126
+ body: bytes | None = json.dumps(
127
+ capo_keyspacesstreams.types.get_records_input.serialize_aws_json_1_0(input_),
128
+ allow_nan=False,
129
+ ).encode()
130
+ headers["content-type"] = "application/x-amz-json-1.0"
131
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
132
+ normalized_url = zapros.URL(url)
133
+ for k, v in params:
134
+ normalized_url.search_params.append(k, v)
135
+ return zapros.Request(
136
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
137
+ )
138
+
139
+
140
+ def get_records(
141
+ options: OperationOptions,
142
+ input_: capo_keyspacesstreams.types.get_records_input.GetRecordsInput,
143
+ ) -> tuple[
144
+ capo_keyspacesstreams.types.get_records_output.GetRecordsOutput, zapros.Response
145
+ ]:
146
+ response = options.client.handler.handle(build_request(options, input_))
147
+ try:
148
+ if response.status >= 300:
149
+ response.read()
150
+ handle_error(response)
151
+ return handle_response(response), response
152
+ except BaseException:
153
+ response.close()
154
+ raise
155
+
156
+
157
+ async def async_get_records(
158
+ options: AsyncOperationOptions,
159
+ input_: capo_keyspacesstreams.types.get_records_input.GetRecordsInput,
160
+ ) -> tuple[
161
+ capo_keyspacesstreams.types.get_records_output.GetRecordsOutput, zapros.Response
162
+ ]:
163
+ response = await options.client.handler.ahandle(build_request(options, input_))
164
+ try:
165
+ if response.status >= 300:
166
+ await response.aread()
167
+ handle_error(response)
168
+ return await async_handle_response(response), response
169
+ except BaseException:
170
+ await response.aclose()
171
+ raise
@@ -0,0 +1,170 @@
1
+ """Generated from Smithy shape ``com.amazonaws.keyspacesstreams#GetShardIterator``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+ import zapros
9
+ from typing_extensions import Never
10
+
11
+ import capo_keyspacesstreams._auth._signers
12
+ import capo_keyspacesstreams._auth._sigv4
13
+ import capo_keyspacesstreams._protocol.eventstream
14
+ import capo_keyspacesstreams.errors.access_denied_exception
15
+ import capo_keyspacesstreams.errors.internal_server_exception
16
+ import capo_keyspacesstreams.errors.resource_not_found_exception
17
+ import capo_keyspacesstreams.errors.throttling_exception
18
+ import capo_keyspacesstreams.errors.validation_exception
19
+ import capo_keyspacesstreams.types.get_shard_iterator_input
20
+ import capo_keyspacesstreams.types.get_shard_iterator_output
21
+ import capo_keyspacesstreams.types.shard_iterator_type
22
+ from capo_keyspacesstreams._protocol.errors import parse_error_metadata_json
23
+ from capo_keyspacesstreams._rule_engine._endpoint_rule_set import (
24
+ EndpointParams,
25
+ resolve,
26
+ )
27
+ from capo_keyspacesstreams._services._pipeline import (
28
+ AsyncOperationOptions,
29
+ OperationOptions,
30
+ )
31
+ from capo_keyspacesstreams.errors import UnknownServiceError
32
+
33
+
34
+ def handle_error(response: zapros.Response) -> Never:
35
+ data = json.loads(response.read())
36
+ code, message = parse_error_metadata_json(response, data)
37
+ match code:
38
+ case "AccessDeniedException":
39
+ raise capo_keyspacesstreams.errors.access_denied_exception.AccessDeniedException.from_aws_json_1_0(
40
+ data, message
41
+ )
42
+ case "InternalServerException":
43
+ raise capo_keyspacesstreams.errors.internal_server_exception.InternalServerException.from_aws_json_1_0(
44
+ data, message
45
+ )
46
+ case "ResourceNotFoundException":
47
+ raise capo_keyspacesstreams.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_0(
48
+ data, message
49
+ )
50
+ case "ThrottlingException":
51
+ raise capo_keyspacesstreams.errors.throttling_exception.ThrottlingException.from_aws_json_1_0(
52
+ data, message
53
+ )
54
+ case "ValidationException":
55
+ raise capo_keyspacesstreams.errors.validation_exception.ValidationException.from_aws_json_1_0(
56
+ data, message
57
+ )
58
+ case _:
59
+ raise UnknownServiceError(code=code, message=message, response=response)
60
+
61
+
62
+ def handle_response(
63
+ response: zapros.Response,
64
+ ) -> capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput:
65
+ out: capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput = capo_keyspacesstreams.types.get_shard_iterator_output.deserialize_aws_json_1_0(
66
+ json.loads(response.read())
67
+ )
68
+ return out
69
+
70
+
71
+ async def async_handle_response(
72
+ response: zapros.Response,
73
+ ) -> capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput:
74
+ out: capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput = capo_keyspacesstreams.types.get_shard_iterator_output.deserialize_aws_json_1_0(
75
+ json.loads(await response.aread())
76
+ )
77
+ return out
78
+
79
+
80
+ def get_signer(
81
+ options: AsyncOperationOptions | OperationOptions,
82
+ auth_schemes: list[dict[str, Any]] | None = None,
83
+ ) -> capo_keyspacesstreams._auth._signers.Signer | None:
84
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
85
+ if (
86
+ options.credentials_provider is not None
87
+ and name_to_schema
88
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
89
+ ):
90
+ raise RuntimeError(
91
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
92
+ )
93
+ if options.credentials_provider is not None:
94
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
95
+ "sigv4-s3express"
96
+ )
97
+ if endpoint_scheme is not None or not name_to_schema:
98
+ sigv4_config = capo_keyspacesstreams._auth._sigv4.build_sigv4_auth_scheme(
99
+ "cassandra", options.region, endpoint_scheme
100
+ )
101
+ if sigv4_config is not None:
102
+ return capo_keyspacesstreams._auth._signers.SigV4Signer(
103
+ options.credentials_provider, auth_scheme=sigv4_config
104
+ )
105
+ raise RuntimeError("Auth was not resolved")
106
+
107
+
108
+ def build_request(
109
+ options: OperationOptions | AsyncOperationOptions,
110
+ input_: capo_keyspacesstreams.types.get_shard_iterator_input.GetShardIteratorInput,
111
+ ) -> zapros.Request:
112
+ endpoint = resolve(
113
+ EndpointParams(
114
+ UseFIPS=options.use_fips, Endpoint=options.endpoint, Region=options.region
115
+ )
116
+ ) # noqa: F841
117
+ url = endpoint.url.rstrip("/") + ""
118
+ params: list[tuple[str, str]] = []
119
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
120
+ headers["X-Amz-Target"] = "KeyspacesStreams.GetShardIterator"
121
+ body: bytes | None = json.dumps(
122
+ capo_keyspacesstreams.types.get_shard_iterator_input.serialize_aws_json_1_0(
123
+ input_
124
+ ),
125
+ allow_nan=False,
126
+ ).encode()
127
+ headers["content-type"] = "application/x-amz-json-1.0"
128
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
129
+ normalized_url = zapros.URL(url)
130
+ for k, v in params:
131
+ normalized_url.search_params.append(k, v)
132
+ return zapros.Request(
133
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
134
+ )
135
+
136
+
137
+ def get_shard_iterator(
138
+ options: OperationOptions,
139
+ input_: capo_keyspacesstreams.types.get_shard_iterator_input.GetShardIteratorInput,
140
+ ) -> tuple[
141
+ capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput,
142
+ zapros.Response,
143
+ ]:
144
+ response = options.client.handler.handle(build_request(options, input_))
145
+ try:
146
+ if response.status >= 300:
147
+ response.read()
148
+ handle_error(response)
149
+ return handle_response(response), response
150
+ except BaseException:
151
+ response.close()
152
+ raise
153
+
154
+
155
+ async def async_get_shard_iterator(
156
+ options: AsyncOperationOptions,
157
+ input_: capo_keyspacesstreams.types.get_shard_iterator_input.GetShardIteratorInput,
158
+ ) -> tuple[
159
+ capo_keyspacesstreams.types.get_shard_iterator_output.GetShardIteratorOutput,
160
+ zapros.Response,
161
+ ]:
162
+ response = await options.client.handler.ahandle(build_request(options, input_))
163
+ try:
164
+ if response.status >= 300:
165
+ await response.aread()
166
+ handle_error(response)
167
+ return await async_handle_response(response), response
168
+ except BaseException:
169
+ await response.aclose()
170
+ raise
@@ -0,0 +1,174 @@
1
+ """Generated from Smithy shape ``com.amazonaws.keyspacesstreams#GetStream``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+ import zapros
9
+ from typing_extensions import Never
10
+
11
+ import capo_keyspacesstreams._auth._signers
12
+ import capo_keyspacesstreams._auth._sigv4
13
+ import capo_keyspacesstreams._protocol.eventstream
14
+ import capo_keyspacesstreams.errors.access_denied_exception
15
+ import capo_keyspacesstreams.errors.internal_server_exception
16
+ import capo_keyspacesstreams.errors.resource_not_found_exception
17
+ import capo_keyspacesstreams.errors.throttling_exception
18
+ import capo_keyspacesstreams.errors.validation_exception
19
+ import capo_keyspacesstreams.types.date
20
+ import capo_keyspacesstreams.types.get_stream_input
21
+ import capo_keyspacesstreams.types.get_stream_output
22
+ import capo_keyspacesstreams.types.shard_description_list
23
+ import capo_keyspacesstreams.types.shard_filter
24
+ import capo_keyspacesstreams.types.stream_status
25
+ import capo_keyspacesstreams.types.stream_view_type
26
+ from capo_keyspacesstreams._protocol.errors import parse_error_metadata_json
27
+ from capo_keyspacesstreams._rule_engine._endpoint_rule_set import (
28
+ EndpointParams,
29
+ resolve,
30
+ )
31
+ from capo_keyspacesstreams._services._pipeline import (
32
+ AsyncOperationOptions,
33
+ OperationOptions,
34
+ )
35
+ from capo_keyspacesstreams.errors import UnknownServiceError
36
+
37
+
38
+ def handle_error(response: zapros.Response) -> Never:
39
+ data = json.loads(response.read())
40
+ code, message = parse_error_metadata_json(response, data)
41
+ match code:
42
+ case "AccessDeniedException":
43
+ raise capo_keyspacesstreams.errors.access_denied_exception.AccessDeniedException.from_aws_json_1_0(
44
+ data, message
45
+ )
46
+ case "InternalServerException":
47
+ raise capo_keyspacesstreams.errors.internal_server_exception.InternalServerException.from_aws_json_1_0(
48
+ data, message
49
+ )
50
+ case "ResourceNotFoundException":
51
+ raise capo_keyspacesstreams.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_0(
52
+ data, message
53
+ )
54
+ case "ThrottlingException":
55
+ raise capo_keyspacesstreams.errors.throttling_exception.ThrottlingException.from_aws_json_1_0(
56
+ data, message
57
+ )
58
+ case "ValidationException":
59
+ raise capo_keyspacesstreams.errors.validation_exception.ValidationException.from_aws_json_1_0(
60
+ data, message
61
+ )
62
+ case _:
63
+ raise UnknownServiceError(code=code, message=message, response=response)
64
+
65
+
66
+ def handle_response(
67
+ response: zapros.Response,
68
+ ) -> capo_keyspacesstreams.types.get_stream_output.GetStreamOutput:
69
+ out: capo_keyspacesstreams.types.get_stream_output.GetStreamOutput = (
70
+ capo_keyspacesstreams.types.get_stream_output.deserialize_aws_json_1_0(
71
+ json.loads(response.read())
72
+ )
73
+ )
74
+ return out
75
+
76
+
77
+ async def async_handle_response(
78
+ response: zapros.Response,
79
+ ) -> capo_keyspacesstreams.types.get_stream_output.GetStreamOutput:
80
+ out: capo_keyspacesstreams.types.get_stream_output.GetStreamOutput = (
81
+ capo_keyspacesstreams.types.get_stream_output.deserialize_aws_json_1_0(
82
+ json.loads(await response.aread())
83
+ )
84
+ )
85
+ return out
86
+
87
+
88
+ def get_signer(
89
+ options: AsyncOperationOptions | OperationOptions,
90
+ auth_schemes: list[dict[str, Any]] | None = None,
91
+ ) -> capo_keyspacesstreams._auth._signers.Signer | None:
92
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
93
+ if (
94
+ options.credentials_provider is not None
95
+ and name_to_schema
96
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
97
+ ):
98
+ raise RuntimeError(
99
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
100
+ )
101
+ if options.credentials_provider is not None:
102
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
103
+ "sigv4-s3express"
104
+ )
105
+ if endpoint_scheme is not None or not name_to_schema:
106
+ sigv4_config = capo_keyspacesstreams._auth._sigv4.build_sigv4_auth_scheme(
107
+ "cassandra", options.region, endpoint_scheme
108
+ )
109
+ if sigv4_config is not None:
110
+ return capo_keyspacesstreams._auth._signers.SigV4Signer(
111
+ options.credentials_provider, auth_scheme=sigv4_config
112
+ )
113
+ raise RuntimeError("Auth was not resolved")
114
+
115
+
116
+ def build_request(
117
+ options: OperationOptions | AsyncOperationOptions,
118
+ input_: capo_keyspacesstreams.types.get_stream_input.GetStreamInput,
119
+ ) -> zapros.Request:
120
+ endpoint = resolve(
121
+ EndpointParams(
122
+ UseFIPS=options.use_fips, Endpoint=options.endpoint, Region=options.region
123
+ )
124
+ ) # noqa: F841
125
+ url = endpoint.url.rstrip("/") + ""
126
+ params: list[tuple[str, str]] = []
127
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
128
+ headers["X-Amz-Target"] = "KeyspacesStreams.GetStream"
129
+ body: bytes | None = json.dumps(
130
+ capo_keyspacesstreams.types.get_stream_input.serialize_aws_json_1_0(input_),
131
+ allow_nan=False,
132
+ ).encode()
133
+ headers["content-type"] = "application/x-amz-json-1.0"
134
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
135
+ normalized_url = zapros.URL(url)
136
+ for k, v in params:
137
+ normalized_url.search_params.append(k, v)
138
+ return zapros.Request(
139
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
140
+ )
141
+
142
+
143
+ def get_stream(
144
+ options: OperationOptions,
145
+ input_: capo_keyspacesstreams.types.get_stream_input.GetStreamInput,
146
+ ) -> tuple[
147
+ capo_keyspacesstreams.types.get_stream_output.GetStreamOutput, zapros.Response
148
+ ]:
149
+ response = options.client.handler.handle(build_request(options, input_))
150
+ try:
151
+ if response.status >= 300:
152
+ response.read()
153
+ handle_error(response)
154
+ return handle_response(response), response
155
+ except BaseException:
156
+ response.close()
157
+ raise
158
+
159
+
160
+ async def async_get_stream(
161
+ options: AsyncOperationOptions,
162
+ input_: capo_keyspacesstreams.types.get_stream_input.GetStreamInput,
163
+ ) -> tuple[
164
+ capo_keyspacesstreams.types.get_stream_output.GetStreamOutput, zapros.Response
165
+ ]:
166
+ response = await options.client.handler.ahandle(build_request(options, input_))
167
+ try:
168
+ if response.status >= 300:
169
+ await response.aread()
170
+ handle_error(response)
171
+ return await async_handle_response(response), response
172
+ except BaseException:
173
+ await response.aclose()
174
+ raise