capo-redshift-data 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 (118) hide show
  1. capo_redshift_data/__init__.py +72 -0
  2. capo_redshift_data/_async.py +25 -0
  3. capo_redshift_data/_auth/_identity.py +16 -0
  4. capo_redshift_data/_auth/_providers.py +886 -0
  5. capo_redshift_data/_auth/_signers.py +88 -0
  6. capo_redshift_data/_auth/_sigv4.py +434 -0
  7. capo_redshift_data/_auth/_zapros_handler.py +80 -0
  8. capo_redshift_data/_iter.py +113 -0
  9. capo_redshift_data/_operations/redshift_data/batch_execute_statement.py +181 -0
  10. capo_redshift_data/_operations/redshift_data/cancel_statement.py +173 -0
  11. capo_redshift_data/_operations/redshift_data/describe_statement.py +161 -0
  12. capo_redshift_data/_operations/redshift_data/describe_table.py +172 -0
  13. capo_redshift_data/_operations/redshift_data/execute_statement.py +178 -0
  14. capo_redshift_data/_operations/redshift_data/get_statement_result.py +161 -0
  15. capo_redshift_data/_operations/redshift_data/get_statement_result_v2.py +161 -0
  16. capo_redshift_data/_operations/redshift_data/list_databases.py +172 -0
  17. capo_redshift_data/_operations/redshift_data/list_schemas.py +170 -0
  18. capo_redshift_data/_operations/redshift_data/list_statements.py +162 -0
  19. capo_redshift_data/_operations/redshift_data/list_tables.py +170 -0
  20. capo_redshift_data/_pagination.py +21 -0
  21. capo_redshift_data/_protocol/__init__.py +1 -0
  22. capo_redshift_data/_protocol/errors.py +93 -0
  23. capo_redshift_data/_protocol/eventstream.py +238 -0
  24. capo_redshift_data/_protocol/serialize.py +47 -0
  25. capo_redshift_data/_protocol/xml.py +33 -0
  26. capo_redshift_data/_rule_engine/__init__.py +0 -0
  27. capo_redshift_data/_rule_engine/_aws_partition.py +160 -0
  28. capo_redshift_data/_rule_engine/_endpoint_rule_set.py +138 -0
  29. capo_redshift_data/_rule_engine/_endpoint_runtime.py +389 -0
  30. capo_redshift_data/_services/_aws_config.py +160 -0
  31. capo_redshift_data/_services/_pipeline.py +198 -0
  32. capo_redshift_data/_services/async_redshift_data.py +1251 -0
  33. capo_redshift_data/_services/redshift_data.py +1240 -0
  34. capo_redshift_data/errors/__init__.py +46 -0
  35. capo_redshift_data/errors/_base.py +94 -0
  36. capo_redshift_data/errors/active_sessions_exceeded_exception.py +53 -0
  37. capo_redshift_data/errors/active_statements_exceeded_exception.py +53 -0
  38. capo_redshift_data/errors/batch_execute_statement_exception.py +63 -0
  39. capo_redshift_data/errors/database_connection_exception.py +52 -0
  40. capo_redshift_data/errors/execute_statement_exception.py +60 -0
  41. capo_redshift_data/errors/internal_server_exception.py +53 -0
  42. capo_redshift_data/errors/query_timeout_exception.py +51 -0
  43. capo_redshift_data/errors/resource_not_found_exception.py +60 -0
  44. capo_redshift_data/errors/validation_exception.py +52 -0
  45. capo_redshift_data/py.typed +0 -0
  46. capo_redshift_data/types/_prelude/blob.py +12 -0
  47. capo_redshift_data/types/_prelude/timestamp.py +17 -0
  48. capo_redshift_data/types/batch_execute_statement_input.py +145 -0
  49. capo_redshift_data/types/batch_execute_statement_output.py +109 -0
  50. capo_redshift_data/types/blob.py +15 -0
  51. capo_redshift_data/types/bool.py +5 -0
  52. capo_redshift_data/types/boxed_boolean.py +5 -0
  53. capo_redshift_data/types/boxed_double.py +5 -0
  54. capo_redshift_data/types/boxed_long.py +5 -0
  55. capo_redshift_data/types/cancel_statement_request.py +31 -0
  56. capo_redshift_data/types/cancel_statement_response.py +23 -0
  57. capo_redshift_data/types/client_token.py +5 -0
  58. capo_redshift_data/types/cluster_identifier_string.py +5 -0
  59. capo_redshift_data/types/column_list.py +33 -0
  60. capo_redshift_data/types/column_metadata.py +109 -0
  61. capo_redshift_data/types/column_metadata_list.py +35 -0
  62. capo_redshift_data/types/database_list.py +17 -0
  63. capo_redshift_data/types/db_group_list.py +17 -0
  64. capo_redshift_data/types/describe_statement_request.py +31 -0
  65. capo_redshift_data/types/describe_statement_response.py +225 -0
  66. capo_redshift_data/types/describe_table_request.py +94 -0
  67. capo_redshift_data/types/describe_table_response.py +51 -0
  68. capo_redshift_data/types/execute_statement_input.py +137 -0
  69. capo_redshift_data/types/execute_statement_output.py +109 -0
  70. capo_redshift_data/types/field.py +105 -0
  71. capo_redshift_data/types/field_list.py +29 -0
  72. capo_redshift_data/types/formatted_sql_records.py +33 -0
  73. capo_redshift_data/types/get_statement_result_request.py +38 -0
  74. capo_redshift_data/types/get_statement_result_response.py +75 -0
  75. capo_redshift_data/types/get_statement_result_v2_request.py +38 -0
  76. capo_redshift_data/types/get_statement_result_v2_response.py +88 -0
  77. capo_redshift_data/types/integer.py +5 -0
  78. capo_redshift_data/types/list_databases_request.py +76 -0
  79. capo_redshift_data/types/list_databases_response.py +47 -0
  80. capo_redshift_data/types/list_schemas_request.py +88 -0
  81. capo_redshift_data/types/list_schemas_response.py +43 -0
  82. capo_redshift_data/types/list_statements_limit.py +5 -0
  83. capo_redshift_data/types/list_statements_request.py +82 -0
  84. capo_redshift_data/types/list_statements_response.py +48 -0
  85. capo_redshift_data/types/list_tables_request.py +94 -0
  86. capo_redshift_data/types/list_tables_response.py +43 -0
  87. capo_redshift_data/types/long.py +5 -0
  88. capo_redshift_data/types/page_size.py +5 -0
  89. capo_redshift_data/types/parameter_name.py +5 -0
  90. capo_redshift_data/types/parameter_value.py +5 -0
  91. capo_redshift_data/types/query_records.py +32 -0
  92. capo_redshift_data/types/result_format_string.py +5 -0
  93. capo_redshift_data/types/schema_list.py +17 -0
  94. capo_redshift_data/types/secret_arn.py +5 -0
  95. capo_redshift_data/types/session_alive_seconds.py +5 -0
  96. capo_redshift_data/types/sql_list.py +17 -0
  97. capo_redshift_data/types/sql_parameter.py +39 -0
  98. capo_redshift_data/types/sql_parameters_list.py +33 -0
  99. capo_redshift_data/types/sql_records.py +29 -0
  100. capo_redshift_data/types/statement_data.py +164 -0
  101. capo_redshift_data/types/statement_list.py +31 -0
  102. capo_redshift_data/types/statement_name_string.py +5 -0
  103. capo_redshift_data/types/statement_status_string.py +5 -0
  104. capo_redshift_data/types/statement_string.py +5 -0
  105. capo_redshift_data/types/statement_string_list.py +19 -0
  106. capo_redshift_data/types/status_string.py +5 -0
  107. capo_redshift_data/types/string.py +5 -0
  108. capo_redshift_data/types/sub_statement_data.py +129 -0
  109. capo_redshift_data/types/sub_statement_list.py +35 -0
  110. capo_redshift_data/types/table_list.py +29 -0
  111. capo_redshift_data/types/table_member.py +40 -0
  112. capo_redshift_data/types/uuid.py +5 -0
  113. capo_redshift_data/types/workgroup_name_string.py +5 -0
  114. capo_redshift_data-0.1.0.dist-info/METADATA +101 -0
  115. capo_redshift_data-0.1.0.dist-info/RECORD +118 -0
  116. capo_redshift_data-0.1.0.dist-info/WHEEL +5 -0
  117. capo_redshift_data-0.1.0.dist-info/licenses/LICENSE +21 -0
  118. capo_redshift_data-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,181 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#BatchExecuteStatement``."""
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_redshift_data._auth._signers
12
+ import capo_redshift_data._auth._sigv4
13
+ import capo_redshift_data._protocol.eventstream
14
+ import capo_redshift_data.errors.active_sessions_exceeded_exception
15
+ import capo_redshift_data.errors.active_statements_exceeded_exception
16
+ import capo_redshift_data.errors.batch_execute_statement_exception
17
+ import capo_redshift_data.errors.internal_server_exception
18
+ import capo_redshift_data.errors.resource_not_found_exception
19
+ import capo_redshift_data.errors.validation_exception
20
+ import capo_redshift_data.types.batch_execute_statement_input
21
+ import capo_redshift_data.types.batch_execute_statement_output
22
+ import capo_redshift_data.types.db_group_list
23
+ import capo_redshift_data.types.sql_list
24
+ import capo_redshift_data.types.sql_parameters_list
25
+ from capo_redshift_data._protocol.errors import parse_error_metadata_json
26
+ from capo_redshift_data._rule_engine._endpoint_rule_set import EndpointParams, resolve
27
+ from capo_redshift_data._services._pipeline import (
28
+ AsyncOperationOptions,
29
+ OperationOptions,
30
+ )
31
+ from capo_redshift_data.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 "ActiveSessionsExceededException":
39
+ raise capo_redshift_data.errors.active_sessions_exceeded_exception.ActiveSessionsExceededException.from_aws_json_1_1(
40
+ data, message
41
+ )
42
+ case "ActiveStatementsExceededException":
43
+ raise capo_redshift_data.errors.active_statements_exceeded_exception.ActiveStatementsExceededException.from_aws_json_1_1(
44
+ data, message
45
+ )
46
+ case "BatchExecuteStatementException":
47
+ raise capo_redshift_data.errors.batch_execute_statement_exception.BatchExecuteStatementException.from_aws_json_1_1(
48
+ data, message
49
+ )
50
+ case "InternalServerException":
51
+ raise capo_redshift_data.errors.internal_server_exception.InternalServerException.from_aws_json_1_1(
52
+ data, message
53
+ )
54
+ case "ResourceNotFoundException":
55
+ raise capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_1(
56
+ data, message
57
+ )
58
+ case "ValidationException":
59
+ raise capo_redshift_data.errors.validation_exception.ValidationException.from_aws_json_1_1(
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
+ ) -> (
69
+ capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput
70
+ ):
71
+ out: capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput = capo_redshift_data.types.batch_execute_statement_output.deserialize_aws_json_1_1(
72
+ json.loads(response.read())
73
+ )
74
+ return out
75
+
76
+
77
+ async def async_handle_response(
78
+ response: zapros.Response,
79
+ ) -> (
80
+ capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput
81
+ ):
82
+ out: capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput = capo_redshift_data.types.batch_execute_statement_output.deserialize_aws_json_1_1(
83
+ json.loads(await response.aread())
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_redshift_data._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_redshift_data._auth._sigv4.build_sigv4_auth_scheme(
107
+ "redshift-data", options.region, endpoint_scheme
108
+ )
109
+ if sigv4_config is not None:
110
+ return capo_redshift_data._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_redshift_data.types.batch_execute_statement_input.BatchExecuteStatementInput,
119
+ ) -> zapros.Request:
120
+ endpoint = resolve(
121
+ EndpointParams(
122
+ Region=options.region,
123
+ UseDualStack=options.use_dual_stack,
124
+ UseFIPS=options.use_fips,
125
+ Endpoint=options.endpoint,
126
+ )
127
+ ) # noqa: F841
128
+ url = endpoint.url.rstrip("/") + ""
129
+ params: list[tuple[str, str]] = []
130
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
131
+ headers["X-Amz-Target"] = "RedshiftData.BatchExecuteStatement"
132
+ body: bytes | None = json.dumps(
133
+ capo_redshift_data.types.batch_execute_statement_input.serialize_aws_json_1_1(
134
+ input_
135
+ ),
136
+ allow_nan=False,
137
+ ).encode()
138
+ headers["content-type"] = "application/x-amz-json-1.1"
139
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
140
+ normalized_url = zapros.URL(url)
141
+ for k, v in params:
142
+ normalized_url.search_params.append(k, v)
143
+ return zapros.Request(
144
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
145
+ )
146
+
147
+
148
+ def batch_execute_statement(
149
+ options: OperationOptions,
150
+ input_: capo_redshift_data.types.batch_execute_statement_input.BatchExecuteStatementInput,
151
+ ) -> tuple[
152
+ capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput,
153
+ zapros.Response,
154
+ ]:
155
+ response = options.client.handler.handle(build_request(options, input_))
156
+ try:
157
+ if response.status >= 300:
158
+ response.read()
159
+ handle_error(response)
160
+ return handle_response(response), response
161
+ except BaseException:
162
+ response.close()
163
+ raise
164
+
165
+
166
+ async def async_batch_execute_statement(
167
+ options: AsyncOperationOptions,
168
+ input_: capo_redshift_data.types.batch_execute_statement_input.BatchExecuteStatementInput,
169
+ ) -> tuple[
170
+ capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput,
171
+ zapros.Response,
172
+ ]:
173
+ response = await options.client.handler.ahandle(build_request(options, input_))
174
+ try:
175
+ if response.status >= 300:
176
+ await response.aread()
177
+ handle_error(response)
178
+ return await async_handle_response(response), response
179
+ except BaseException:
180
+ await response.aclose()
181
+ raise
@@ -0,0 +1,173 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#CancelStatement``."""
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_redshift_data._auth._signers
12
+ import capo_redshift_data._auth._sigv4
13
+ import capo_redshift_data._protocol.eventstream
14
+ import capo_redshift_data.errors.database_connection_exception
15
+ import capo_redshift_data.errors.internal_server_exception
16
+ import capo_redshift_data.errors.query_timeout_exception
17
+ import capo_redshift_data.errors.resource_not_found_exception
18
+ import capo_redshift_data.errors.validation_exception
19
+ import capo_redshift_data.types.cancel_statement_request
20
+ import capo_redshift_data.types.cancel_statement_response
21
+ from capo_redshift_data._protocol.errors import parse_error_metadata_json
22
+ from capo_redshift_data._rule_engine._endpoint_rule_set import EndpointParams, resolve
23
+ from capo_redshift_data._services._pipeline import (
24
+ AsyncOperationOptions,
25
+ OperationOptions,
26
+ )
27
+ from capo_redshift_data.errors import UnknownServiceError
28
+
29
+
30
+ def handle_error(response: zapros.Response) -> Never:
31
+ data = json.loads(response.read())
32
+ code, message = parse_error_metadata_json(response, data)
33
+ match code:
34
+ case "DatabaseConnectionException":
35
+ raise capo_redshift_data.errors.database_connection_exception.DatabaseConnectionException.from_aws_json_1_1(
36
+ data, message
37
+ )
38
+ case "InternalServerException":
39
+ raise capo_redshift_data.errors.internal_server_exception.InternalServerException.from_aws_json_1_1(
40
+ data, message
41
+ )
42
+ case "QueryTimeoutException":
43
+ raise capo_redshift_data.errors.query_timeout_exception.QueryTimeoutException.from_aws_json_1_1(
44
+ data, message
45
+ )
46
+ case "ResourceNotFoundException":
47
+ raise capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_1(
48
+ data, message
49
+ )
50
+ case "ValidationException":
51
+ raise capo_redshift_data.errors.validation_exception.ValidationException.from_aws_json_1_1(
52
+ data, message
53
+ )
54
+ case _:
55
+ raise UnknownServiceError(code=code, message=message, response=response)
56
+
57
+
58
+ def handle_response(
59
+ response: zapros.Response,
60
+ ) -> capo_redshift_data.types.cancel_statement_response.CancelStatementResponse:
61
+ out: capo_redshift_data.types.cancel_statement_response.CancelStatementResponse = (
62
+ capo_redshift_data.types.cancel_statement_response.deserialize_aws_json_1_1(
63
+ json.loads(response.read())
64
+ )
65
+ )
66
+ return out
67
+
68
+
69
+ async def async_handle_response(
70
+ response: zapros.Response,
71
+ ) -> capo_redshift_data.types.cancel_statement_response.CancelStatementResponse:
72
+ out: capo_redshift_data.types.cancel_statement_response.CancelStatementResponse = (
73
+ capo_redshift_data.types.cancel_statement_response.deserialize_aws_json_1_1(
74
+ json.loads(await response.aread())
75
+ )
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_redshift_data._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_redshift_data._auth._sigv4.build_sigv4_auth_scheme(
99
+ "redshift-data", options.region, endpoint_scheme
100
+ )
101
+ if sigv4_config is not None:
102
+ return capo_redshift_data._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_redshift_data.types.cancel_statement_request.CancelStatementRequest,
111
+ ) -> zapros.Request:
112
+ endpoint = resolve(
113
+ EndpointParams(
114
+ Region=options.region,
115
+ UseDualStack=options.use_dual_stack,
116
+ UseFIPS=options.use_fips,
117
+ Endpoint=options.endpoint,
118
+ )
119
+ ) # noqa: F841
120
+ url = endpoint.url.rstrip("/") + ""
121
+ params: list[tuple[str, str]] = []
122
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
123
+ headers["X-Amz-Target"] = "RedshiftData.CancelStatement"
124
+ body: bytes | None = json.dumps(
125
+ capo_redshift_data.types.cancel_statement_request.serialize_aws_json_1_1(
126
+ input_
127
+ ),
128
+ allow_nan=False,
129
+ ).encode()
130
+ headers["content-type"] = "application/x-amz-json-1.1"
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 cancel_statement(
141
+ options: OperationOptions,
142
+ input_: capo_redshift_data.types.cancel_statement_request.CancelStatementRequest,
143
+ ) -> tuple[
144
+ capo_redshift_data.types.cancel_statement_response.CancelStatementResponse,
145
+ zapros.Response,
146
+ ]:
147
+ response = options.client.handler.handle(build_request(options, input_))
148
+ try:
149
+ if response.status >= 300:
150
+ response.read()
151
+ handle_error(response)
152
+ return handle_response(response), response
153
+ except BaseException:
154
+ response.close()
155
+ raise
156
+
157
+
158
+ async def async_cancel_statement(
159
+ options: AsyncOperationOptions,
160
+ input_: capo_redshift_data.types.cancel_statement_request.CancelStatementRequest,
161
+ ) -> tuple[
162
+ capo_redshift_data.types.cancel_statement_response.CancelStatementResponse,
163
+ zapros.Response,
164
+ ]:
165
+ response = await options.client.handler.ahandle(build_request(options, input_))
166
+ try:
167
+ if response.status >= 300:
168
+ await response.aread()
169
+ handle_error(response)
170
+ return await async_handle_response(response), response
171
+ except BaseException:
172
+ await response.aclose()
173
+ raise
@@ -0,0 +1,161 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#DescribeStatement``."""
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_redshift_data._auth._signers
12
+ import capo_redshift_data._auth._sigv4
13
+ import capo_redshift_data._protocol.eventstream
14
+ import capo_redshift_data.errors.internal_server_exception
15
+ import capo_redshift_data.errors.resource_not_found_exception
16
+ import capo_redshift_data.errors.validation_exception
17
+ import capo_redshift_data.types.describe_statement_request
18
+ import capo_redshift_data.types.describe_statement_response
19
+ import capo_redshift_data.types.sql_parameters_list
20
+ import capo_redshift_data.types.sub_statement_list
21
+ from capo_redshift_data._protocol.errors import parse_error_metadata_json
22
+ from capo_redshift_data._rule_engine._endpoint_rule_set import EndpointParams, resolve
23
+ from capo_redshift_data._services._pipeline import (
24
+ AsyncOperationOptions,
25
+ OperationOptions,
26
+ )
27
+ from capo_redshift_data.errors import UnknownServiceError
28
+
29
+
30
+ def handle_error(response: zapros.Response) -> Never:
31
+ data = json.loads(response.read())
32
+ code, message = parse_error_metadata_json(response, data)
33
+ match code:
34
+ case "InternalServerException":
35
+ raise capo_redshift_data.errors.internal_server_exception.InternalServerException.from_aws_json_1_1(
36
+ data, message
37
+ )
38
+ case "ResourceNotFoundException":
39
+ raise capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_1(
40
+ data, message
41
+ )
42
+ case "ValidationException":
43
+ raise capo_redshift_data.errors.validation_exception.ValidationException.from_aws_json_1_1(
44
+ data, message
45
+ )
46
+ case _:
47
+ raise UnknownServiceError(code=code, message=message, response=response)
48
+
49
+
50
+ def handle_response(
51
+ response: zapros.Response,
52
+ ) -> capo_redshift_data.types.describe_statement_response.DescribeStatementResponse:
53
+ out: capo_redshift_data.types.describe_statement_response.DescribeStatementResponse = capo_redshift_data.types.describe_statement_response.deserialize_aws_json_1_1(
54
+ json.loads(response.read())
55
+ )
56
+ return out
57
+
58
+
59
+ async def async_handle_response(
60
+ response: zapros.Response,
61
+ ) -> capo_redshift_data.types.describe_statement_response.DescribeStatementResponse:
62
+ out: capo_redshift_data.types.describe_statement_response.DescribeStatementResponse = capo_redshift_data.types.describe_statement_response.deserialize_aws_json_1_1(
63
+ json.loads(await response.aread())
64
+ )
65
+ return out
66
+
67
+
68
+ def get_signer(
69
+ options: AsyncOperationOptions | OperationOptions,
70
+ auth_schemes: list[dict[str, Any]] | None = None,
71
+ ) -> capo_redshift_data._auth._signers.Signer | None:
72
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
73
+ if (
74
+ options.credentials_provider is not None
75
+ and name_to_schema
76
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
77
+ ):
78
+ raise RuntimeError(
79
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
80
+ )
81
+ if options.credentials_provider is not None:
82
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
83
+ "sigv4-s3express"
84
+ )
85
+ if endpoint_scheme is not None or not name_to_schema:
86
+ sigv4_config = capo_redshift_data._auth._sigv4.build_sigv4_auth_scheme(
87
+ "redshift-data", options.region, endpoint_scheme
88
+ )
89
+ if sigv4_config is not None:
90
+ return capo_redshift_data._auth._signers.SigV4Signer(
91
+ options.credentials_provider, auth_scheme=sigv4_config
92
+ )
93
+ raise RuntimeError("Auth was not resolved")
94
+
95
+
96
+ def build_request(
97
+ options: OperationOptions | AsyncOperationOptions,
98
+ input_: capo_redshift_data.types.describe_statement_request.DescribeStatementRequest,
99
+ ) -> zapros.Request:
100
+ endpoint = resolve(
101
+ EndpointParams(
102
+ Region=options.region,
103
+ UseDualStack=options.use_dual_stack,
104
+ UseFIPS=options.use_fips,
105
+ Endpoint=options.endpoint,
106
+ )
107
+ ) # noqa: F841
108
+ url = endpoint.url.rstrip("/") + ""
109
+ params: list[tuple[str, str]] = []
110
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
111
+ headers["X-Amz-Target"] = "RedshiftData.DescribeStatement"
112
+ body: bytes | None = json.dumps(
113
+ capo_redshift_data.types.describe_statement_request.serialize_aws_json_1_1(
114
+ input_
115
+ ),
116
+ allow_nan=False,
117
+ ).encode()
118
+ headers["content-type"] = "application/x-amz-json-1.1"
119
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
120
+ normalized_url = zapros.URL(url)
121
+ for k, v in params:
122
+ normalized_url.search_params.append(k, v)
123
+ return zapros.Request(
124
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
125
+ )
126
+
127
+
128
+ def describe_statement(
129
+ options: OperationOptions,
130
+ input_: capo_redshift_data.types.describe_statement_request.DescribeStatementRequest,
131
+ ) -> tuple[
132
+ capo_redshift_data.types.describe_statement_response.DescribeStatementResponse,
133
+ zapros.Response,
134
+ ]:
135
+ response = options.client.handler.handle(build_request(options, input_))
136
+ try:
137
+ if response.status >= 300:
138
+ response.read()
139
+ handle_error(response)
140
+ return handle_response(response), response
141
+ except BaseException:
142
+ response.close()
143
+ raise
144
+
145
+
146
+ async def async_describe_statement(
147
+ options: AsyncOperationOptions,
148
+ input_: capo_redshift_data.types.describe_statement_request.DescribeStatementRequest,
149
+ ) -> tuple[
150
+ capo_redshift_data.types.describe_statement_response.DescribeStatementResponse,
151
+ zapros.Response,
152
+ ]:
153
+ response = await options.client.handler.ahandle(build_request(options, input_))
154
+ try:
155
+ if response.status >= 300:
156
+ await response.aread()
157
+ handle_error(response)
158
+ return await async_handle_response(response), response
159
+ except BaseException:
160
+ await response.aclose()
161
+ raise