dex-connector-amazon-redshift 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_amazon_redshift-0.1.0/.gitignore +16 -0
- dex_connector_amazon_redshift-0.1.0/LICENSE +21 -0
- dex_connector_amazon_redshift-0.1.0/PKG-INFO +15 -0
- dex_connector_amazon_redshift-0.1.0/README.md +3 -0
- dex_connector_amazon_redshift-0.1.0/examples/statement_results/README.md +3 -0
- dex_connector_amazon_redshift-0.1.0/examples/statement_results/__init__.py +3 -0
- dex_connector_amazon_redshift-0.1.0/examples/statement_results/flow.py +79 -0
- dex_connector_amazon_redshift-0.1.0/examples/statement_results/integration_test.py +80 -0
- dex_connector_amazon_redshift-0.1.0/examples/statement_results/worker.py +52 -0
- dex_connector_amazon_redshift-0.1.0/pyproject.toml +37 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/__init__.py +22 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/__init__.py +2 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/config.py +28 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/connection.py +144 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/definitions.py +40 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/mock.py +74 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/models.py +39 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/steps.py +81 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/client.py +250 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/connection.py +8 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/dex-connector.json +68 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/models.py +8 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/redshiftmock/__init__.py +6 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/sigv4.py +82 -0
- dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/steps.py +5 -0
- dex_connector_amazon_redshift-0.1.0/tests/test_conformance.py +39 -0
- dex_connector_amazon_redshift-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_amazon_redshift-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated keyation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-amazon-redshift
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Amazon Redshift connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Amazon Redshift Python package
|
|
14
|
+
|
|
15
|
+
`Client.get_statement_result()` binds the signed result-page Query. `GetStatementResultInput` holds `statement_id` and `next_token` (blank for the first page). `StatementResultPage` contains `records`, `total_num_rows`, and `next_token`. See the [connector guide](../README.md) for configuration and IAM permissions. The [runnable Flow](examples/statement_results/README.md) exercises a real Dex Worker with a local provider fixture. Live AWS access has not been verified.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Amazon Redshift Python package
|
|
2
|
+
|
|
3
|
+
`Client.get_statement_result()` binds the signed result-page Query. `GetStatementResultInput` holds `statement_id` and `next_token` (blank for the first page). `StatementResultPage` contains `records`, `total_num_rows`, and `next_token`. See the [connector guide](../README.md) for configuration and IAM permissions. The [runnable Flow](examples/statement_results/README.md) exercises a real Dex Worker with a local provider fixture. Live AWS access has not been verified.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Python Redshift statement results example
|
|
2
|
+
|
|
3
|
+
The Worker runs `AmazonRedshiftStatementResultsPython` through the static `amazon-redshift` connection and stores the result page in an Attribute. From `connectors/amazon/redshift/python`, run `uv run python -m examples.statement_results.worker` with the project `DEX_PROJECT_*` environment and a running `dexcli dev` service. Start the Flow with a unique ID and `GetStatementResultInput(statement_id="d9b6c0c9-0747-4bf4-b142-e8883122f766", next_token="")`. Use your actual statement ID. Optional branches are unwired. `integration_test.py` runs the same Flow against real Dex and a local provider fixture. Configure the connection with the [connector guide](../../../README.md).
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable Amazon Redshift statement result Flow using getStatementResult."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.amazon_redshift import (
|
|
9
|
+
Connection,
|
|
10
|
+
GetStatementResultInput,
|
|
11
|
+
StatementResultPage,
|
|
12
|
+
new_get_statement_result_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
FLOW_TYPE = "AmazonRedshiftStatementResultsPython"
|
|
16
|
+
CONNECTION_NAME = "amazon-redshift"
|
|
17
|
+
_CALL_STEP_TYPE = "CallGetStatementResult"
|
|
18
|
+
_RESULT = dex.Attribute("redshift-statement-results", StatementResultPage)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def map_to_operation_input(request: GetStatementResultInput) -> GetStatementResultInput:
|
|
22
|
+
"""Send the request unchanged."""
|
|
23
|
+
return request
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# dex:group group-id:redshift group-label:"Amazon Redshift"
|
|
27
|
+
# dex:explanation text:"Start the Amazon Redshift request."
|
|
28
|
+
class _StartRequest(dex.Step[GetStatementResultInput]):
|
|
29
|
+
def get_step_type(self) -> str:
|
|
30
|
+
return "StartGetStatementResultRequest"
|
|
31
|
+
|
|
32
|
+
def execute(self, context: dex.Context, input: GetStatementResultInput) -> dex.StepDecision:
|
|
33
|
+
return dex.go_to(dex.StepRef("CallGetStatementResult"), input)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# dex:group group-id:redshift group-label:"Amazon Redshift"
|
|
37
|
+
# dex:explanation text:"Record the provider result and complete the Flow."
|
|
38
|
+
class _CompleteRequest(dex.Step[QueryResult[StatementResultPage]]):
|
|
39
|
+
def get_step_type(self) -> str:
|
|
40
|
+
return "CompleteGetStatementResultRequest"
|
|
41
|
+
|
|
42
|
+
def execute(self, context: dex.Context, input: QueryResult[StatementResultPage]) -> dex.StepDecision:
|
|
43
|
+
_RESULT.set(context, input.value)
|
|
44
|
+
return dex.graceful_complete(input.value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class StatementResultsFlow(dex.Flow[GetStatementResultInput]):
|
|
48
|
+
"""Read one statement result page through the static amazon-redshift connection."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, connection: Connection) -> None:
|
|
51
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
52
|
+
raise ValueError("statement result requires the static amazon-redshift connection")
|
|
53
|
+
self._start = _StartRequest()
|
|
54
|
+
self._complete = _CompleteRequest()
|
|
55
|
+
self._call = new_get_statement_result_step(
|
|
56
|
+
step_type=_CALL_STEP_TYPE,
|
|
57
|
+
step_input_type=GetStatementResultInput,
|
|
58
|
+
annotations={
|
|
59
|
+
"groupId": "redshift",
|
|
60
|
+
"groupLabel": "Amazon Redshift",
|
|
61
|
+
"explanation": "Read one statement result page from the connected Amazon Redshift account.",
|
|
62
|
+
},
|
|
63
|
+
connection=connection,
|
|
64
|
+
connection_name=CONNECTION_NAME,
|
|
65
|
+
map_to_operation_input=map_to_operation_input,
|
|
66
|
+
fetched=self._complete,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def get_flow_type(self) -> str:
|
|
70
|
+
"""Return the stable Flow identity used in Dex Web."""
|
|
71
|
+
return "AmazonRedshiftStatementResultsPython"
|
|
72
|
+
|
|
73
|
+
def get_steps(self) -> dex.StepList[GetStatementResultInput]:
|
|
74
|
+
"""Register the start, provider read, and completion Steps."""
|
|
75
|
+
return dex.StepList.start_step(self._start).other_steps(self._call, self._complete)
|
|
76
|
+
|
|
77
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
78
|
+
"""Persist the provider result."""
|
|
79
|
+
return dex.PersistenceSchema.of(_RESULT)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Real Dex Worker and Client verification for the Amazon Redshift Python Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
from datetime import timedelta
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from uuid import uuid4
|
|
10
|
+
|
|
11
|
+
import dex
|
|
12
|
+
import httpx
|
|
13
|
+
import pytest
|
|
14
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
15
|
+
|
|
16
|
+
from dex_connectors.amazon_redshift import (
|
|
17
|
+
Client,
|
|
18
|
+
Config,
|
|
19
|
+
Credentials,
|
|
20
|
+
GetStatementResultInput,
|
|
21
|
+
StatementResultPage,
|
|
22
|
+
new_connection,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from .flow import CONNECTION_NAME, StatementResultsFlow
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.asyncio
|
|
29
|
+
async def test_statement_results_retries_503(tmp_path: Path) -> None:
|
|
30
|
+
"""Run the checked-in Flow across real Dex retry and persistence boundaries."""
|
|
31
|
+
address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
32
|
+
requests: list[httpx.Request] = []
|
|
33
|
+
|
|
34
|
+
def answer(request: httpx.Request) -> httpx.Response:
|
|
35
|
+
requests.append(request)
|
|
36
|
+
assert request.method == "POST"
|
|
37
|
+
assert request.url.path == "/"
|
|
38
|
+
assert request.headers["X-Amz-Target"] == "RedshiftData.GetStatementResult"
|
|
39
|
+
assert "redshift-data/aws4_request" in request.headers["Authorization"]
|
|
40
|
+
if len(requests) == 1:
|
|
41
|
+
return httpx.Response(503)
|
|
42
|
+
return httpx.Response(
|
|
43
|
+
200,
|
|
44
|
+
json={"Records": [[{"stringValue": "example"}]], "TotalNumRows": 1},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
reference = ConnectionRef("amazon-redshift", CONNECTION_NAME)
|
|
48
|
+
credentials = Credentials(
|
|
49
|
+
SecretString("AKIAREDSHIFTCONNECTOR"), SecretString("redshift-test-secret"), SecretString("")
|
|
50
|
+
)
|
|
51
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as http_client:
|
|
52
|
+
provider = Client(
|
|
53
|
+
Config(endpoint="http://127.0.0.1:12345", region="eu-west-1"),
|
|
54
|
+
StaticCredentialProvider({reference: credentials}),
|
|
55
|
+
http_client,
|
|
56
|
+
)
|
|
57
|
+
connection = new_connection(provider, reference)
|
|
58
|
+
flow = StatementResultsFlow(connection)
|
|
59
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
60
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 24))
|
|
61
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=address))
|
|
62
|
+
worker_task = asyncio.create_task(worker.start())
|
|
63
|
+
try:
|
|
64
|
+
await worker.wait_pull_registered(timeout=15)
|
|
65
|
+
async with dex.AsyncClient(registry, cache, dex.ClientOptions(server_address=address)) as client:
|
|
66
|
+
flow_id = f"redshift-python-{uuid4().hex}"
|
|
67
|
+
await client.start_flow(
|
|
68
|
+
flow,
|
|
69
|
+
flow_id,
|
|
70
|
+
GetStatementResultInput(statement_id="d9b6c0c9-0747-4bf4-b142-e8883122f766"),
|
|
71
|
+
)
|
|
72
|
+
result = await asyncio.wait_for(client.wait_for_flow(flow_id, timedelta(seconds=25)), 30)
|
|
73
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
74
|
+
assert result.single_output(StatementResultPage).records == ([{"stringValue": "example"}],)
|
|
75
|
+
assert len(requests) == 2
|
|
76
|
+
finally:
|
|
77
|
+
await worker.stop()
|
|
78
|
+
await worker_task
|
|
79
|
+
cache.close()
|
|
80
|
+
await connection.aclose()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Amazon Redshift statement result Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.amazon_redshift import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, StatementResultsFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and serve Amazon Redshift reads."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([StatementResultsFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR",
|
|
28
|
+
str(Path(tempfile.gettempdir()) / "dex-redshift-statement-results-blobs"),
|
|
29
|
+
)
|
|
30
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
31
|
+
worker = dex.AsyncWorker(
|
|
32
|
+
registry,
|
|
33
|
+
cache,
|
|
34
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
35
|
+
)
|
|
36
|
+
async with worker:
|
|
37
|
+
await worker.start()
|
|
38
|
+
finally:
|
|
39
|
+
if connection is not None:
|
|
40
|
+
await connection.aclose()
|
|
41
|
+
if cache is not None:
|
|
42
|
+
cache.close()
|
|
43
|
+
await project.close()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> None:
|
|
47
|
+
"""Run until the Worker stops or the process receives an interrupt."""
|
|
48
|
+
asyncio.run(run_worker())
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-amazon-redshift"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Amazon Redshift connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
13
|
+
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/dex_connectors"]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
testpaths = ["tests"]
|
|
22
|
+
pythonpath = [".", "src"]
|
|
23
|
+
asyncio_mode = "auto"
|
|
24
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
25
|
+
|
|
26
|
+
[tool.mypy]
|
|
27
|
+
python_version = "3.11"
|
|
28
|
+
strict = true
|
|
29
|
+
mypy_path = "src"
|
|
30
|
+
explicit_package_bases = true
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
line-length = 110
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint]
|
|
37
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Amazon Redshift key Queries for Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials, GetStatementResultOperation
|
|
6
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
7
|
+
from .models import GetStatementResultInput, StatementResultPage
|
|
8
|
+
from .steps import new_get_statement_result_step
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Client",
|
|
12
|
+
"Config",
|
|
13
|
+
"Connection",
|
|
14
|
+
"Credentials",
|
|
15
|
+
"GetStatementResultInput",
|
|
16
|
+
"StatementResultPage",
|
|
17
|
+
"GetStatementResultOperation",
|
|
18
|
+
"new_connection",
|
|
19
|
+
"new_connection_with_operations",
|
|
20
|
+
"new_get_statement_result_step",
|
|
21
|
+
"new_project_connection",
|
|
22
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
endpoint: str
|
|
14
|
+
region: str = "us-east-1"
|
|
15
|
+
timeout_seconds: float = 15
|
|
16
|
+
max_response_bytes: int = 2097152
|
|
17
|
+
|
|
18
|
+
setattr(Config, '__module__', 'dex_connectors.amazon_redshift.client')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True, slots=True)
|
|
22
|
+
class Credentials:
|
|
23
|
+
|
|
24
|
+
access_key_id: SecretString
|
|
25
|
+
secret_access_key: SecretString
|
|
26
|
+
session_token: SecretString
|
|
27
|
+
|
|
28
|
+
setattr(Credentials, '__module__', 'dex_connectors.amazon_redshift.client')
|
dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/connection.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, GET_STATEMENT_RESULT_DEFINITION
|
|
13
|
+
from ..models import GetStatementResultInput, StatementResultPage
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_get_statement_result', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
get_statement_result: Query[GetStatementResultInput, StatementResultPage],
|
|
22
|
+
client: Client | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
reference.validate()
|
|
25
|
+
if reference.provider != CONNECTOR_ID or get_statement_result is None:
|
|
26
|
+
raise ValueError("Amazon Redshift connection provider and operations are required")
|
|
27
|
+
if get_statement_result.definition().operation != GET_STATEMENT_RESULT_DEFINITION.operation:
|
|
28
|
+
raise ValueError("Amazon Redshift connection operation identity differs")
|
|
29
|
+
self.reference = reference
|
|
30
|
+
self._get_statement_result = get_statement_result
|
|
31
|
+
self._client = client
|
|
32
|
+
|
|
33
|
+
def get_statement_result(self) -> Query[GetStatementResultInput, StatementResultPage]:
|
|
34
|
+
return self._get_statement_result
|
|
35
|
+
|
|
36
|
+
async def aclose(self) -> None:
|
|
37
|
+
if self._client is not None:
|
|
38
|
+
await self._client.aclose()
|
|
39
|
+
|
|
40
|
+
def __repr__(self) -> str:
|
|
41
|
+
return "amazon_redshift.Connection([REDACTED])"
|
|
42
|
+
|
|
43
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
44
|
+
raise TypeError("Amazon Redshift connections cannot be serialized")
|
|
45
|
+
|
|
46
|
+
setattr(Connection, '__module__', 'dex_connectors.amazon_redshift.connection')
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
50
|
+
if client is None:
|
|
51
|
+
raise ValueError("Amazon Redshift client is required")
|
|
52
|
+
return Connection(reference, client.get_statement_result(), client)
|
|
53
|
+
|
|
54
|
+
setattr(new_connection, '__module__', 'dex_connectors.amazon_redshift.connection')
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def new_connection_with_operations(
|
|
58
|
+
get_statement_result: Query[GetStatementResultInput, StatementResultPage],
|
|
59
|
+
reference: ConnectionRef,
|
|
60
|
+
) -> Connection:
|
|
61
|
+
return Connection(reference, get_statement_result)
|
|
62
|
+
|
|
63
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.amazon_redshift.connection')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class _ProjectCredentialSource:
|
|
67
|
+
|
|
68
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
69
|
+
self.project = project
|
|
70
|
+
self.key = key
|
|
71
|
+
|
|
72
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
73
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
74
|
+
if not isinstance(material, dict):
|
|
75
|
+
raise ValueError("Amazon Redshift stored credential does not match the connector credential fields")
|
|
76
|
+
if set(material) - set(('access_key_id', 'secret_access_key', 'session_token')):
|
|
77
|
+
raise ValueError("Amazon Redshift stored credential does not match the connector credential fields")
|
|
78
|
+
access_key_id = material.get("access_key_id")
|
|
79
|
+
if access_key_id is not None and not (isinstance(access_key_id, str)):
|
|
80
|
+
raise ValueError("Amazon Redshift credential access_key_id has an invalid type")
|
|
81
|
+
secret_access_key = material.get("secret_access_key")
|
|
82
|
+
if secret_access_key is not None and not (isinstance(secret_access_key, str)):
|
|
83
|
+
raise ValueError("Amazon Redshift credential secret_access_key has an invalid type")
|
|
84
|
+
session_token = material.get("session_token")
|
|
85
|
+
if session_token is not None and not (isinstance(session_token, str)):
|
|
86
|
+
raise ValueError("Amazon Redshift credential session_token has an invalid type")
|
|
87
|
+
if not access_key_id:
|
|
88
|
+
raise ValueError("Amazon Redshift credential access_key_id is required")
|
|
89
|
+
if not secret_access_key:
|
|
90
|
+
raise ValueError("Amazon Redshift credential secret_access_key is required")
|
|
91
|
+
return Credentials(SecretString(access_key_id), SecretString(secret_access_key), SecretString(session_token or ''))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def new_project_connection(
|
|
95
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
96
|
+
) -> Connection:
|
|
97
|
+
if project is None:
|
|
98
|
+
raise ValueError("Amazon Redshift connection requires loaded project configuration")
|
|
99
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
100
|
+
reference.validate()
|
|
101
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
102
|
+
matching = [
|
|
103
|
+
entry
|
|
104
|
+
for entry in project.configuration.connections
|
|
105
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
106
|
+
]
|
|
107
|
+
if len(matching) != 1:
|
|
108
|
+
raise ValueError("Amazon Redshift project connection is missing or duplicated")
|
|
109
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
110
|
+
raise ValueError("Amazon Redshift project connection provider differs")
|
|
111
|
+
config = _decode_config(matching[0].configuration)
|
|
112
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
113
|
+
return new_connection(client, reference)
|
|
114
|
+
|
|
115
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.amazon_redshift.connection')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
119
|
+
if set(value) - {"region", "endpoint", "timeout", "maxResponseBytes"}:
|
|
120
|
+
raise ValueError("Amazon Redshift configuration has unknown fields")
|
|
121
|
+
config_arguments: dict[str, Any] = {}
|
|
122
|
+
if "region" in value and value["region"] != '':
|
|
123
|
+
region = value["region"]
|
|
124
|
+
if not (isinstance(region, str)):
|
|
125
|
+
raise ValueError("Amazon Redshift configuration region has an invalid type")
|
|
126
|
+
config_arguments['region'] = region
|
|
127
|
+
if "endpoint" in value and value["endpoint"] != '':
|
|
128
|
+
endpoint = value["endpoint"]
|
|
129
|
+
if not (isinstance(endpoint, str)):
|
|
130
|
+
raise ValueError("Amazon Redshift configuration endpoint has an invalid type")
|
|
131
|
+
config_arguments['endpoint'] = endpoint
|
|
132
|
+
else:
|
|
133
|
+
config_arguments['endpoint'] = ''
|
|
134
|
+
if "timeout" in value and value["timeout"] != '':
|
|
135
|
+
timeout = value["timeout"]
|
|
136
|
+
if not (type(timeout) is int):
|
|
137
|
+
raise ValueError("Amazon Redshift configuration timeout has an invalid type")
|
|
138
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
139
|
+
if "maxResponseBytes" in value and value["maxResponseBytes"] != '':
|
|
140
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
141
|
+
if not (type(max_response_bytes) is int):
|
|
142
|
+
raise ValueError("Amazon Redshift configuration maxResponseBytes has an invalid type")
|
|
143
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
144
|
+
return Config(**config_arguments)
|
dex_connector_amazon_redshift-0.1.0/src/dex_connectors/amazon_redshift/_generated/definitions.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "amazon-redshift"
|
|
18
|
+
PROVIDER = "amazon-redshift"
|
|
19
|
+
GET_STATEMENT_RESULT_OPERATION_ID = "getStatementResult"
|
|
20
|
+
DEFECT = "defect"
|
|
21
|
+
FETCHED = "fetched"
|
|
22
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
23
|
+
MISSING = "missing"
|
|
24
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
25
|
+
|
|
26
|
+
GET_STATEMENT_RESULT_DEFINITION = QueryDefinition(
|
|
27
|
+
OperationRef(CONNECTOR_ID, GET_STATEMENT_RESULT_OPERATION_ID),
|
|
28
|
+
(
|
|
29
|
+
BranchDefinition(FETCHED, "Redshift returned the statement result page.", False),
|
|
30
|
+
BranchDefinition(MISSING, "Redshift does not retain the specified statement result.", True),
|
|
31
|
+
BranchDefinition(PROVIDER_REJECTED, "Redshift conclusively rejected the lookup or credentials.", True),
|
|
32
|
+
BranchDefinition(INVALID_RESPONSE, "Redshift returned malformed or oversized result JSON.", True),
|
|
33
|
+
BranchDefinition(DEFECT, "The statement ID, endpoint, Region, or credentials are invalid.", True),
|
|
34
|
+
),
|
|
35
|
+
StepDefaults(
|
|
36
|
+
timedelta(seconds=30),
|
|
37
|
+
2,
|
|
38
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import GetStatementResultInput, StatementResultPage
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, FETCHED, GET_STATEMENT_RESULT_DEFINITION, INVALID_RESPONSE, MISSING, PROVIDER_REJECTED
|
|
13
|
+
|
|
14
|
+
def get_statement_result_fetched(value: StatementResultPage, failure: Failure | None = None) -> Case[StatementResultPage]:
|
|
15
|
+
return Case.branch_result(FETCHED, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(get_statement_result_fetched, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
18
|
+
|
|
19
|
+
def get_statement_result_missing(value: StatementResultPage, failure: Failure | None = None) -> Case[StatementResultPage]:
|
|
20
|
+
return Case.branch_result(MISSING, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(get_statement_result_missing, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
23
|
+
|
|
24
|
+
def get_statement_result_provider_rejected(value: StatementResultPage, failure: Failure | None = None) -> Case[StatementResultPage]:
|
|
25
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(get_statement_result_provider_rejected, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
28
|
+
|
|
29
|
+
def get_statement_result_invalid_response(value: StatementResultPage, failure: Failure | None = None) -> Case[StatementResultPage]:
|
|
30
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(get_statement_result_invalid_response, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
33
|
+
|
|
34
|
+
def get_statement_result_defect(value: StatementResultPage, failure: Failure | None = None) -> Case[StatementResultPage]:
|
|
35
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
36
|
+
|
|
37
|
+
setattr(get_statement_result_defect, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
38
|
+
|
|
39
|
+
def get_statement_result_retry(failure: Failure, after_seconds: float = 0) -> Case[StatementResultPage]:
|
|
40
|
+
return Case.retry(failure, after_seconds)
|
|
41
|
+
|
|
42
|
+
setattr(get_statement_result_retry, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
43
|
+
|
|
44
|
+
def get_statement_result_fetched_default() -> Case[StatementResultPage]:
|
|
45
|
+
return Case.branch_result(FETCHED, StatementResultPage(records=([{'stringValue': 'example'}],), next_token='', total_num_rows=1))
|
|
46
|
+
|
|
47
|
+
setattr(get_statement_result_fetched_default, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Mock:
|
|
51
|
+
|
|
52
|
+
def __init__(self, connection_name: str = "amazon-redshift") -> None:
|
|
53
|
+
self.get_statement_result_script: Query[GetStatementResultInput, StatementResultPage] = Query(GET_STATEMENT_RESULT_DEFINITION)
|
|
54
|
+
self.get_statement_result_script.default(get_statement_result_fetched_default())
|
|
55
|
+
self._connection = new_connection_with_operations(
|
|
56
|
+
get_statement_result=self.get_statement_result_script,
|
|
57
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def connection(self) -> Connection:
|
|
61
|
+
return self._connection
|
|
62
|
+
|
|
63
|
+
setattr(Mock, '__module__', "dex_connectors.amazon_redshift.redshiftmock")
|
|
64
|
+
|
|
65
|
+
__all__ = [
|
|
66
|
+
"Mock",
|
|
67
|
+
"get_statement_result_fetched",
|
|
68
|
+
"get_statement_result_missing",
|
|
69
|
+
"get_statement_result_provider_rejected",
|
|
70
|
+
"get_statement_result_invalid_response",
|
|
71
|
+
"get_statement_result_defect",
|
|
72
|
+
"get_statement_result_retry",
|
|
73
|
+
"get_statement_result_fetched_default",
|
|
74
|
+
]
|