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,172 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#DescribeTable``."""
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.column_list
20
+ import capo_redshift_data.types.describe_table_request
21
+ import capo_redshift_data.types.describe_table_response
22
+ from capo_redshift_data._protocol.errors import parse_error_metadata_json
23
+ from capo_redshift_data._rule_engine._endpoint_rule_set import EndpointParams, resolve
24
+ from capo_redshift_data._services._pipeline import (
25
+ AsyncOperationOptions,
26
+ OperationOptions,
27
+ )
28
+ from capo_redshift_data.errors import UnknownServiceError
29
+
30
+
31
+ def handle_error(response: zapros.Response) -> Never:
32
+ data = json.loads(response.read())
33
+ code, message = parse_error_metadata_json(response, data)
34
+ match code:
35
+ case "DatabaseConnectionException":
36
+ raise capo_redshift_data.errors.database_connection_exception.DatabaseConnectionException.from_aws_json_1_1(
37
+ data, message
38
+ )
39
+ case "InternalServerException":
40
+ raise capo_redshift_data.errors.internal_server_exception.InternalServerException.from_aws_json_1_1(
41
+ data, message
42
+ )
43
+ case "QueryTimeoutException":
44
+ raise capo_redshift_data.errors.query_timeout_exception.QueryTimeoutException.from_aws_json_1_1(
45
+ data, message
46
+ )
47
+ case "ResourceNotFoundException":
48
+ raise capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_1(
49
+ data, message
50
+ )
51
+ case "ValidationException":
52
+ raise capo_redshift_data.errors.validation_exception.ValidationException.from_aws_json_1_1(
53
+ data, message
54
+ )
55
+ case _:
56
+ raise UnknownServiceError(code=code, message=message, response=response)
57
+
58
+
59
+ def handle_response(
60
+ response: zapros.Response,
61
+ ) -> capo_redshift_data.types.describe_table_response.DescribeTableResponse:
62
+ out: capo_redshift_data.types.describe_table_response.DescribeTableResponse = (
63
+ capo_redshift_data.types.describe_table_response.deserialize_aws_json_1_1(
64
+ json.loads(response.read())
65
+ )
66
+ )
67
+ return out
68
+
69
+
70
+ async def async_handle_response(
71
+ response: zapros.Response,
72
+ ) -> capo_redshift_data.types.describe_table_response.DescribeTableResponse:
73
+ out: capo_redshift_data.types.describe_table_response.DescribeTableResponse = (
74
+ capo_redshift_data.types.describe_table_response.deserialize_aws_json_1_1(
75
+ json.loads(await response.aread())
76
+ )
77
+ )
78
+ return out
79
+
80
+
81
+ def get_signer(
82
+ options: AsyncOperationOptions | OperationOptions,
83
+ auth_schemes: list[dict[str, Any]] | None = None,
84
+ ) -> capo_redshift_data._auth._signers.Signer | None:
85
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
86
+ if (
87
+ options.credentials_provider is not None
88
+ and name_to_schema
89
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
90
+ ):
91
+ raise RuntimeError(
92
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
93
+ )
94
+ if options.credentials_provider is not None:
95
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
96
+ "sigv4-s3express"
97
+ )
98
+ if endpoint_scheme is not None or not name_to_schema:
99
+ sigv4_config = capo_redshift_data._auth._sigv4.build_sigv4_auth_scheme(
100
+ "redshift-data", options.region, endpoint_scheme
101
+ )
102
+ if sigv4_config is not None:
103
+ return capo_redshift_data._auth._signers.SigV4Signer(
104
+ options.credentials_provider, auth_scheme=sigv4_config
105
+ )
106
+ raise RuntimeError("Auth was not resolved")
107
+
108
+
109
+ def build_request(
110
+ options: OperationOptions | AsyncOperationOptions,
111
+ input_: capo_redshift_data.types.describe_table_request.DescribeTableRequest,
112
+ ) -> zapros.Request:
113
+ endpoint = resolve(
114
+ EndpointParams(
115
+ Region=options.region,
116
+ UseDualStack=options.use_dual_stack,
117
+ UseFIPS=options.use_fips,
118
+ Endpoint=options.endpoint,
119
+ )
120
+ ) # noqa: F841
121
+ url = endpoint.url.rstrip("/") + ""
122
+ params: list[tuple[str, str]] = []
123
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
124
+ headers["X-Amz-Target"] = "RedshiftData.DescribeTable"
125
+ body: bytes | None = json.dumps(
126
+ capo_redshift_data.types.describe_table_request.serialize_aws_json_1_1(input_),
127
+ allow_nan=False,
128
+ ).encode()
129
+ headers["content-type"] = "application/x-amz-json-1.1"
130
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
131
+ normalized_url = zapros.URL(url)
132
+ for k, v in params:
133
+ normalized_url.search_params.append(k, v)
134
+ return zapros.Request(
135
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
136
+ )
137
+
138
+
139
+ def describe_table(
140
+ options: OperationOptions,
141
+ input_: capo_redshift_data.types.describe_table_request.DescribeTableRequest,
142
+ ) -> tuple[
143
+ capo_redshift_data.types.describe_table_response.DescribeTableResponse,
144
+ 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_describe_table(
158
+ options: AsyncOperationOptions,
159
+ input_: capo_redshift_data.types.describe_table_request.DescribeTableRequest,
160
+ ) -> tuple[
161
+ capo_redshift_data.types.describe_table_response.DescribeTableResponse,
162
+ zapros.Response,
163
+ ]:
164
+ response = await options.client.handler.ahandle(build_request(options, input_))
165
+ try:
166
+ if response.status >= 300:
167
+ await response.aread()
168
+ handle_error(response)
169
+ return await async_handle_response(response), response
170
+ except BaseException:
171
+ await response.aclose()
172
+ raise
@@ -0,0 +1,178 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#ExecuteStatement``."""
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.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.db_group_list
21
+ import capo_redshift_data.types.execute_statement_input
22
+ import capo_redshift_data.types.execute_statement_output
23
+ import capo_redshift_data.types.sql_parameters_list
24
+ from capo_redshift_data._protocol.errors import parse_error_metadata_json
25
+ from capo_redshift_data._rule_engine._endpoint_rule_set import EndpointParams, resolve
26
+ from capo_redshift_data._services._pipeline import (
27
+ AsyncOperationOptions,
28
+ OperationOptions,
29
+ )
30
+ from capo_redshift_data.errors import UnknownServiceError
31
+
32
+
33
+ def handle_error(response: zapros.Response) -> Never:
34
+ data = json.loads(response.read())
35
+ code, message = parse_error_metadata_json(response, data)
36
+ match code:
37
+ case "ActiveSessionsExceededException":
38
+ raise capo_redshift_data.errors.active_sessions_exceeded_exception.ActiveSessionsExceededException.from_aws_json_1_1(
39
+ data, message
40
+ )
41
+ case "ActiveStatementsExceededException":
42
+ raise capo_redshift_data.errors.active_statements_exceeded_exception.ActiveStatementsExceededException.from_aws_json_1_1(
43
+ data, message
44
+ )
45
+ case "ExecuteStatementException":
46
+ raise capo_redshift_data.errors.execute_statement_exception.ExecuteStatementException.from_aws_json_1_1(
47
+ data, message
48
+ )
49
+ case "InternalServerException":
50
+ raise capo_redshift_data.errors.internal_server_exception.InternalServerException.from_aws_json_1_1(
51
+ data, message
52
+ )
53
+ case "ResourceNotFoundException":
54
+ raise capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException.from_aws_json_1_1(
55
+ data, message
56
+ )
57
+ case "ValidationException":
58
+ raise capo_redshift_data.errors.validation_exception.ValidationException.from_aws_json_1_1(
59
+ data, message
60
+ )
61
+ case _:
62
+ raise UnknownServiceError(code=code, message=message, response=response)
63
+
64
+
65
+ def handle_response(
66
+ response: zapros.Response,
67
+ ) -> capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput:
68
+ out: capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput = (
69
+ capo_redshift_data.types.execute_statement_output.deserialize_aws_json_1_1(
70
+ json.loads(response.read())
71
+ )
72
+ )
73
+ return out
74
+
75
+
76
+ async def async_handle_response(
77
+ response: zapros.Response,
78
+ ) -> capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput:
79
+ out: capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput = (
80
+ capo_redshift_data.types.execute_statement_output.deserialize_aws_json_1_1(
81
+ json.loads(await response.aread())
82
+ )
83
+ )
84
+ return out
85
+
86
+
87
+ def get_signer(
88
+ options: AsyncOperationOptions | OperationOptions,
89
+ auth_schemes: list[dict[str, Any]] | None = None,
90
+ ) -> capo_redshift_data._auth._signers.Signer | None:
91
+ name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
92
+ if (
93
+ options.credentials_provider is not None
94
+ and name_to_schema
95
+ and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
96
+ ):
97
+ raise RuntimeError(
98
+ "Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
99
+ )
100
+ if options.credentials_provider is not None:
101
+ endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
102
+ "sigv4-s3express"
103
+ )
104
+ if endpoint_scheme is not None or not name_to_schema:
105
+ sigv4_config = capo_redshift_data._auth._sigv4.build_sigv4_auth_scheme(
106
+ "redshift-data", options.region, endpoint_scheme
107
+ )
108
+ if sigv4_config is not None:
109
+ return capo_redshift_data._auth._signers.SigV4Signer(
110
+ options.credentials_provider, auth_scheme=sigv4_config
111
+ )
112
+ raise RuntimeError("Auth was not resolved")
113
+
114
+
115
+ def build_request(
116
+ options: OperationOptions | AsyncOperationOptions,
117
+ input_: capo_redshift_data.types.execute_statement_input.ExecuteStatementInput,
118
+ ) -> zapros.Request:
119
+ endpoint = resolve(
120
+ EndpointParams(
121
+ Region=options.region,
122
+ UseDualStack=options.use_dual_stack,
123
+ UseFIPS=options.use_fips,
124
+ Endpoint=options.endpoint,
125
+ )
126
+ ) # noqa: F841
127
+ url = endpoint.url.rstrip("/") + ""
128
+ params: list[tuple[str, str]] = []
129
+ headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
130
+ headers["X-Amz-Target"] = "RedshiftData.ExecuteStatement"
131
+ body: bytes | None = json.dumps(
132
+ capo_redshift_data.types.execute_statement_input.serialize_aws_json_1_1(input_),
133
+ allow_nan=False,
134
+ ).encode()
135
+ headers["content-type"] = "application/x-amz-json-1.1"
136
+ signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
137
+ normalized_url = zapros.URL(url)
138
+ for k, v in params:
139
+ normalized_url.search_params.append(k, v)
140
+ return zapros.Request(
141
+ normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
142
+ )
143
+
144
+
145
+ def execute_statement(
146
+ options: OperationOptions,
147
+ input_: capo_redshift_data.types.execute_statement_input.ExecuteStatementInput,
148
+ ) -> tuple[
149
+ capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput,
150
+ zapros.Response,
151
+ ]:
152
+ response = options.client.handler.handle(build_request(options, input_))
153
+ try:
154
+ if response.status >= 300:
155
+ response.read()
156
+ handle_error(response)
157
+ return handle_response(response), response
158
+ except BaseException:
159
+ response.close()
160
+ raise
161
+
162
+
163
+ async def async_execute_statement(
164
+ options: AsyncOperationOptions,
165
+ input_: capo_redshift_data.types.execute_statement_input.ExecuteStatementInput,
166
+ ) -> tuple[
167
+ capo_redshift_data.types.execute_statement_output.ExecuteStatementOutput,
168
+ zapros.Response,
169
+ ]:
170
+ response = await options.client.handler.ahandle(build_request(options, input_))
171
+ try:
172
+ if response.status >= 300:
173
+ await response.aread()
174
+ handle_error(response)
175
+ return await async_handle_response(response), response
176
+ except BaseException:
177
+ await response.aclose()
178
+ raise
@@ -0,0 +1,161 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#GetStatementResult``."""
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.column_metadata_list
18
+ import capo_redshift_data.types.get_statement_result_request
19
+ import capo_redshift_data.types.get_statement_result_response
20
+ import capo_redshift_data.types.sql_records
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.get_statement_result_response.GetStatementResultResponse:
53
+ out: capo_redshift_data.types.get_statement_result_response.GetStatementResultResponse = capo_redshift_data.types.get_statement_result_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.get_statement_result_response.GetStatementResultResponse:
62
+ out: capo_redshift_data.types.get_statement_result_response.GetStatementResultResponse = capo_redshift_data.types.get_statement_result_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.get_statement_result_request.GetStatementResultRequest,
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.GetStatementResult"
112
+ body: bytes | None = json.dumps(
113
+ capo_redshift_data.types.get_statement_result_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 get_statement_result(
129
+ options: OperationOptions,
130
+ input_: capo_redshift_data.types.get_statement_result_request.GetStatementResultRequest,
131
+ ) -> tuple[
132
+ capo_redshift_data.types.get_statement_result_response.GetStatementResultResponse,
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_get_statement_result(
147
+ options: AsyncOperationOptions,
148
+ input_: capo_redshift_data.types.get_statement_result_request.GetStatementResultRequest,
149
+ ) -> tuple[
150
+ capo_redshift_data.types.get_statement_result_response.GetStatementResultResponse,
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
@@ -0,0 +1,161 @@
1
+ """Generated from Smithy shape ``com.amazonaws.redshiftdata#GetStatementResultV2``."""
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.column_metadata_list
18
+ import capo_redshift_data.types.formatted_sql_records
19
+ import capo_redshift_data.types.get_statement_result_v2_request
20
+ import capo_redshift_data.types.get_statement_result_v2_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 "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.get_statement_result_v2_response.GetStatementResultV2Response:
53
+ out: capo_redshift_data.types.get_statement_result_v2_response.GetStatementResultV2Response = capo_redshift_data.types.get_statement_result_v2_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.get_statement_result_v2_response.GetStatementResultV2Response:
62
+ out: capo_redshift_data.types.get_statement_result_v2_response.GetStatementResultV2Response = capo_redshift_data.types.get_statement_result_v2_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.get_statement_result_v2_request.GetStatementResultV2Request,
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.GetStatementResultV2"
112
+ body: bytes | None = json.dumps(
113
+ capo_redshift_data.types.get_statement_result_v2_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 get_statement_result_v2(
129
+ options: OperationOptions,
130
+ input_: capo_redshift_data.types.get_statement_result_v2_request.GetStatementResultV2Request,
131
+ ) -> tuple[
132
+ capo_redshift_data.types.get_statement_result_v2_response.GetStatementResultV2Response,
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_get_statement_result_v2(
147
+ options: AsyncOperationOptions,
148
+ input_: capo_redshift_data.types.get_statement_result_v2_request.GetStatementResultV2Request,
149
+ ) -> tuple[
150
+ capo_redshift_data.types.get_statement_result_v2_response.GetStatementResultV2Response,
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