dex-python-sdk 1.9.0__tar.gz → 1.10.1__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_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/PKG-INFO +100 -1
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/README.md +99 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/__init__.py +5 -1
- dex_python_sdk-1.10.1/dex/_credential_transport.py +142 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_grpc_errors.py +1 -0
- dex_python_sdk-1.10.1/dex/_pull_worker.py +598 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_worker_dispatcher.py +1 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/async_client.py +5 -2
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/async_worker.py +90 -32
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/client.py +7 -2
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/client_options.py +7 -0
- dex_python_sdk-1.10.1/dex/credential.py +138 -0
- dex_python_sdk-1.10.1/dex/dexpb/dex_pb2.py +545 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/dexpb/dex_pb2.pyi +220 -137
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/dexpb/dex_pb2_grpc.py +108 -78
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/worker.py +111 -35
- dex_python_sdk-1.10.1/dex/worker_options.py +164 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/pyproject.toml +1 -1
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/Cargo.lock +12 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/Cargo.toml +1 -0
- dex_python_sdk-1.9.0/dex/dexpb/dex_pb2.py +0 -545
- dex_python_sdk-1.9.0/dex/worker_options.py +0 -52
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/LEGACY_NOTICES.md +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/LICENSE +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_async_value_hydrator.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_async_worker_dispatcher.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_async_worker_service.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_invocation_context.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_native.pyi +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_server_protocol.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_utils.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_value_hydrator.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_value_mapper.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/_worker_service.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/attribute.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/attribute_match.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/blob_cache.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/channel.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/codec.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/condition.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/context.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/dexpb/__init__.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/flow.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/flow_config.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/flow_info.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/flow_options.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/flow_result.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/py.typed +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/rpc_invoke_options.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/runtime_errors.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/step.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/step_execution.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/stream.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/subflow.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/timer.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/wait.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/dex/wait_options.py +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
- {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.1}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dex-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.1
|
|
4
4
|
Requires-Dist: grpcio>=1.83.0
|
|
5
5
|
Requires-Dist: grpcio-status>=1.83.0
|
|
6
6
|
Requires-Dist: protobuf>=7.35.1
|
|
@@ -17,6 +17,102 @@ Project-URL: Repository, https://github.com/superdurable/dex
|
|
|
17
17
|
|
|
18
18
|
# Dex SDK for Python
|
|
19
19
|
|
|
20
|
+
## Authentication
|
|
21
|
+
|
|
22
|
+
When Dex authentication is enabled, pass a bearer credential to each Client and
|
|
23
|
+
Worker that connects to the server. FileCredential reads the token at construction,
|
|
24
|
+
checks its mtime and size at most once per second, and reloads it after rotation.
|
|
25
|
+
Whitespace around the token is removed. An unreadable or empty file fails calls
|
|
26
|
+
until it is restored; the SDK does not send an old token.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from dex import Client, ClientOptions, FileCredential, Worker, WorkerOptions
|
|
30
|
+
|
|
31
|
+
credential = FileCredential("/var/run/secrets/dex/token")
|
|
32
|
+
client = Client(registry, cache, ClientOptions(credential=credential))
|
|
33
|
+
worker = Worker(registry, cache, WorkerOptions(credential=credential))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The same option works with AsyncClient and AsyncWorker. Worker credentials cover
|
|
37
|
+
startup synchronization, blob hydration, and pull WorkerTaskService streams. A
|
|
38
|
+
pull stream reads the token when it opens and again on every reconnect. For a
|
|
39
|
+
custom credential, implement Credential.token() to return the current token;
|
|
40
|
+
the method may be called concurrently, and an exception fails the call before
|
|
41
|
+
it contacts Dex. AsyncClient and AsyncWorker also accept an awaitable token.
|
|
42
|
+
Synchronous tokens run in an executor for async calls and on the calling thread
|
|
43
|
+
for sync calls. Async calls bound token lookup by the RPC deadline when set;
|
|
44
|
+
pull stream opens use a 30-second lookup budget. Sync token lookup must return
|
|
45
|
+
promptly. By default, no authorization metadata is sent. Dex uses plaintext
|
|
46
|
+
gRPC, so protect the network path that carries the token.
|
|
47
|
+
|
|
48
|
+
## Pull mode
|
|
49
|
+
|
|
50
|
+
Set `WorkerOptions.pull` to run a `Worker` or `AsyncWorker` with outbound task
|
|
51
|
+
streams. The Worker connects to the Dex server through `server_address` and
|
|
52
|
+
does not open a listener. Advertise `worker.worker_target` through
|
|
53
|
+
`ClientOptions.worker_target`. A single Flow can override the Client default
|
|
54
|
+
with `StartFlowOptions(config_override=FlowConfig(worker_target=...))`; a
|
|
55
|
+
SubFlow can use `SubFlowOptions` with the same `FlowConfig` override.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import threading
|
|
59
|
+
from dex import Client, ClientOptions, PullWorkerOptions, Worker, WorkerOptions
|
|
60
|
+
|
|
61
|
+
worker = Worker(
|
|
62
|
+
registry,
|
|
63
|
+
cache,
|
|
64
|
+
WorkerOptions(
|
|
65
|
+
server_address="dex.example:8801",
|
|
66
|
+
pull=PullWorkerOptions(max_concurrent_tasks=8, idle_streams_per_queue=1),
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
worker_thread = threading.Thread(target=worker.start)
|
|
70
|
+
worker_thread.start()
|
|
71
|
+
client = Client(
|
|
72
|
+
registry,
|
|
73
|
+
cache,
|
|
74
|
+
ClientOptions(server_address="dex.example:8801", worker_target=worker.worker_target),
|
|
75
|
+
)
|
|
76
|
+
try:
|
|
77
|
+
client.start_flow(flow, flow_id, input_value)
|
|
78
|
+
finally:
|
|
79
|
+
client.close()
|
|
80
|
+
worker.stop()
|
|
81
|
+
worker_thread.join()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The Worker polls its sticky queue and every registered Flow type queue. Flow
|
|
85
|
+
type names must be unique within a Dex server. `max_concurrent_tasks` defaults
|
|
86
|
+
to the CPU count, and `idle_streams_per_queue` defaults to one. At capacity,
|
|
87
|
+
the Worker rejects an assignment so Dex can reassign it. Each stream runs one
|
|
88
|
+
task at a time; Step heartbeat and stream writes use the same stream. A Worker
|
|
89
|
+
may hold up to `(1 + number of Flow types) * (idle_streams_per_queue +
|
|
90
|
+
max_concurrent_tasks)` streams because busy streams are replaced with idle
|
|
91
|
+
streams and retained after tasks finish. Size these options for the server's
|
|
92
|
+
per-Worker stream cap (256 by default).
|
|
93
|
+
|
|
94
|
+
The generated `app_worker_id` uses the first nonempty `DEX_WORKER_INSTANCE`,
|
|
95
|
+
`POD_NAME`, `HOSTNAME`, or system hostname, plus eight random base32 characters.
|
|
96
|
+
An override must uniquely identify one Worker process and change after restart.
|
|
97
|
+
It must contain 1-63 ASCII letters, digits, dots, underscores, or hyphens and
|
|
98
|
+
must not equal a registered Flow type. Pull mode cannot configure a bind address
|
|
99
|
+
or an advertised address or headless target. Use `WorkerTarget(pull=True)` for
|
|
100
|
+
Client defaults or Flow overrides when the Worker target is not directly in
|
|
101
|
+
scope.
|
|
102
|
+
|
|
103
|
+
Pull streams reconnect after failures. A server-directed reconnect waits for
|
|
104
|
+
an active task to finish, then waits up to `stop_drain_timeout` for the server
|
|
105
|
+
to close the stream after the final frame. An idle stream reconnects
|
|
106
|
+
immediately. An older server without pull support produces one explicit error
|
|
107
|
+
log and is retried after one minute. `start()` reports startup
|
|
108
|
+
synchronization errors, while later stream errors are logged and retried.
|
|
109
|
+
`stop()` drains for at most
|
|
110
|
+
`stop_drain_timeout`, which defaults to 30 seconds. Afterward it requests
|
|
111
|
+
cancellation and waits for handlers to return. Synchronous handlers should
|
|
112
|
+
check `Context.is_cancellation_requested()` during long operations. Streams
|
|
113
|
+
that sent a final frame wait for server EOF until the remaining Stop drain
|
|
114
|
+
deadline before the channel closes.
|
|
115
|
+
|
|
20
116
|
## Flow state I/O
|
|
21
117
|
|
|
22
118
|
Applications read and write Flow state through typed RPCs. Client and AsyncClient
|
|
@@ -532,6 +628,9 @@ environment:
|
|
|
532
628
|
./run-integration-tests.sh
|
|
533
629
|
```
|
|
534
630
|
|
|
631
|
+
Set `DEX_INTEG_WORKER_MODE=pull` to run the suite with pull Workers instead of
|
|
632
|
+
listening Workers. The default is `push`.
|
|
633
|
+
|
|
535
634
|
### Measure integration coverage
|
|
536
635
|
|
|
537
636
|
Run the same integration suite with Python source coverage:
|
|
@@ -1,6 +1,102 @@
|
|
|
1
1
|
|
|
2
2
|
# Dex SDK for Python
|
|
3
3
|
|
|
4
|
+
## Authentication
|
|
5
|
+
|
|
6
|
+
When Dex authentication is enabled, pass a bearer credential to each Client and
|
|
7
|
+
Worker that connects to the server. FileCredential reads the token at construction,
|
|
8
|
+
checks its mtime and size at most once per second, and reloads it after rotation.
|
|
9
|
+
Whitespace around the token is removed. An unreadable or empty file fails calls
|
|
10
|
+
until it is restored; the SDK does not send an old token.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from dex import Client, ClientOptions, FileCredential, Worker, WorkerOptions
|
|
14
|
+
|
|
15
|
+
credential = FileCredential("/var/run/secrets/dex/token")
|
|
16
|
+
client = Client(registry, cache, ClientOptions(credential=credential))
|
|
17
|
+
worker = Worker(registry, cache, WorkerOptions(credential=credential))
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The same option works with AsyncClient and AsyncWorker. Worker credentials cover
|
|
21
|
+
startup synchronization, blob hydration, and pull WorkerTaskService streams. A
|
|
22
|
+
pull stream reads the token when it opens and again on every reconnect. For a
|
|
23
|
+
custom credential, implement Credential.token() to return the current token;
|
|
24
|
+
the method may be called concurrently, and an exception fails the call before
|
|
25
|
+
it contacts Dex. AsyncClient and AsyncWorker also accept an awaitable token.
|
|
26
|
+
Synchronous tokens run in an executor for async calls and on the calling thread
|
|
27
|
+
for sync calls. Async calls bound token lookup by the RPC deadline when set;
|
|
28
|
+
pull stream opens use a 30-second lookup budget. Sync token lookup must return
|
|
29
|
+
promptly. By default, no authorization metadata is sent. Dex uses plaintext
|
|
30
|
+
gRPC, so protect the network path that carries the token.
|
|
31
|
+
|
|
32
|
+
## Pull mode
|
|
33
|
+
|
|
34
|
+
Set `WorkerOptions.pull` to run a `Worker` or `AsyncWorker` with outbound task
|
|
35
|
+
streams. The Worker connects to the Dex server through `server_address` and
|
|
36
|
+
does not open a listener. Advertise `worker.worker_target` through
|
|
37
|
+
`ClientOptions.worker_target`. A single Flow can override the Client default
|
|
38
|
+
with `StartFlowOptions(config_override=FlowConfig(worker_target=...))`; a
|
|
39
|
+
SubFlow can use `SubFlowOptions` with the same `FlowConfig` override.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import threading
|
|
43
|
+
from dex import Client, ClientOptions, PullWorkerOptions, Worker, WorkerOptions
|
|
44
|
+
|
|
45
|
+
worker = Worker(
|
|
46
|
+
registry,
|
|
47
|
+
cache,
|
|
48
|
+
WorkerOptions(
|
|
49
|
+
server_address="dex.example:8801",
|
|
50
|
+
pull=PullWorkerOptions(max_concurrent_tasks=8, idle_streams_per_queue=1),
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
worker_thread = threading.Thread(target=worker.start)
|
|
54
|
+
worker_thread.start()
|
|
55
|
+
client = Client(
|
|
56
|
+
registry,
|
|
57
|
+
cache,
|
|
58
|
+
ClientOptions(server_address="dex.example:8801", worker_target=worker.worker_target),
|
|
59
|
+
)
|
|
60
|
+
try:
|
|
61
|
+
client.start_flow(flow, flow_id, input_value)
|
|
62
|
+
finally:
|
|
63
|
+
client.close()
|
|
64
|
+
worker.stop()
|
|
65
|
+
worker_thread.join()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The Worker polls its sticky queue and every registered Flow type queue. Flow
|
|
69
|
+
type names must be unique within a Dex server. `max_concurrent_tasks` defaults
|
|
70
|
+
to the CPU count, and `idle_streams_per_queue` defaults to one. At capacity,
|
|
71
|
+
the Worker rejects an assignment so Dex can reassign it. Each stream runs one
|
|
72
|
+
task at a time; Step heartbeat and stream writes use the same stream. A Worker
|
|
73
|
+
may hold up to `(1 + number of Flow types) * (idle_streams_per_queue +
|
|
74
|
+
max_concurrent_tasks)` streams because busy streams are replaced with idle
|
|
75
|
+
streams and retained after tasks finish. Size these options for the server's
|
|
76
|
+
per-Worker stream cap (256 by default).
|
|
77
|
+
|
|
78
|
+
The generated `app_worker_id` uses the first nonempty `DEX_WORKER_INSTANCE`,
|
|
79
|
+
`POD_NAME`, `HOSTNAME`, or system hostname, plus eight random base32 characters.
|
|
80
|
+
An override must uniquely identify one Worker process and change after restart.
|
|
81
|
+
It must contain 1-63 ASCII letters, digits, dots, underscores, or hyphens and
|
|
82
|
+
must not equal a registered Flow type. Pull mode cannot configure a bind address
|
|
83
|
+
or an advertised address or headless target. Use `WorkerTarget(pull=True)` for
|
|
84
|
+
Client defaults or Flow overrides when the Worker target is not directly in
|
|
85
|
+
scope.
|
|
86
|
+
|
|
87
|
+
Pull streams reconnect after failures. A server-directed reconnect waits for
|
|
88
|
+
an active task to finish, then waits up to `stop_drain_timeout` for the server
|
|
89
|
+
to close the stream after the final frame. An idle stream reconnects
|
|
90
|
+
immediately. An older server without pull support produces one explicit error
|
|
91
|
+
log and is retried after one minute. `start()` reports startup
|
|
92
|
+
synchronization errors, while later stream errors are logged and retried.
|
|
93
|
+
`stop()` drains for at most
|
|
94
|
+
`stop_drain_timeout`, which defaults to 30 seconds. Afterward it requests
|
|
95
|
+
cancellation and waits for handlers to return. Synchronous handlers should
|
|
96
|
+
check `Context.is_cancellation_requested()` during long operations. Streams
|
|
97
|
+
that sent a final frame wait for server EOF until the remaining Stop drain
|
|
98
|
+
deadline before the channel closes.
|
|
99
|
+
|
|
4
100
|
## Flow state I/O
|
|
5
101
|
|
|
6
102
|
Applications read and write Flow state through typed RPCs. Client and AsyncClient
|
|
@@ -516,6 +612,9 @@ environment:
|
|
|
516
612
|
./run-integration-tests.sh
|
|
517
613
|
```
|
|
518
614
|
|
|
615
|
+
Set `DEX_INTEG_WORKER_MODE=pull` to run the suite with pull Workers instead of
|
|
616
|
+
listening Workers. The default is `push`.
|
|
617
|
+
|
|
519
618
|
### Measure integration coverage
|
|
520
619
|
|
|
521
620
|
Run the same integration suite with Python source coverage:
|
|
@@ -24,6 +24,7 @@ from dex.blob_cache import BlobCache, BlobCacheConfig, open_blob_cache
|
|
|
24
24
|
from dex.channel import Channel, ChannelMap, ChannelMapLoad, ChannelMessage
|
|
25
25
|
from dex.client import Client
|
|
26
26
|
from dex.client_options import ClientOptions
|
|
27
|
+
from dex.credential import Credential, FileCredential
|
|
27
28
|
from dex.codec import (
|
|
28
29
|
BOOL,
|
|
29
30
|
BYTES,
|
|
@@ -112,7 +113,7 @@ from dex.timer import Timer
|
|
|
112
113
|
from dex.wait import Wait
|
|
113
114
|
from dex.wait_options import WaitForAttributeOptions, WaitForStepCompletionOptions
|
|
114
115
|
from dex.worker import Worker
|
|
115
|
-
from dex.worker_options import WorkerOptions, WorkerTarget
|
|
116
|
+
from dex.worker_options import PullWorkerOptions, WorkerOptions, WorkerTarget
|
|
116
117
|
|
|
117
118
|
__all__ = [
|
|
118
119
|
"BOOL",
|
|
@@ -143,6 +144,7 @@ __all__ = [
|
|
|
143
144
|
"ChannelMessagesNotLoadedError",
|
|
144
145
|
"Client",
|
|
145
146
|
"ClientOptions",
|
|
147
|
+
"Credential",
|
|
146
148
|
"Codec",
|
|
147
149
|
"CodecRegistry",
|
|
148
150
|
"ConditionCombination",
|
|
@@ -150,6 +152,7 @@ __all__ = [
|
|
|
150
152
|
"DexServiceError",
|
|
151
153
|
"ErrorSubStatus",
|
|
152
154
|
"Flow",
|
|
155
|
+
"FileCredential",
|
|
153
156
|
"FlowAlreadyStartedError",
|
|
154
157
|
"FlowConfig",
|
|
155
158
|
"FlowDefinitionError",
|
|
@@ -210,6 +213,7 @@ __all__ = [
|
|
|
210
213
|
"WorkerInvocationError",
|
|
211
214
|
"WorkerOptions",
|
|
212
215
|
"WorkerTarget",
|
|
216
|
+
"PullWorkerOptions",
|
|
213
217
|
"WaitForAttributeOptions",
|
|
214
218
|
"WaitForStepCompletionOptions",
|
|
215
219
|
"dead_end",
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
# You may not use this file except in compliance with the License.
|
|
5
|
+
# See the LICENSE file in the repository root.
|
|
6
|
+
#
|
|
7
|
+
# SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
|
|
9
|
+
"""Attach bearer metadata to outbound gRPC calls."""
|
|
10
|
+
|
|
11
|
+
# mypy: disable-error-code=type-arg
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
import inspect
|
|
17
|
+
from collections.abc import Callable
|
|
18
|
+
from typing import Any, NamedTuple, cast
|
|
19
|
+
|
|
20
|
+
import grpc
|
|
21
|
+
|
|
22
|
+
from dex.credential import Credential
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _SyncCallDetails(NamedTuple):
|
|
26
|
+
method: str
|
|
27
|
+
timeout: float | None
|
|
28
|
+
metadata: Any
|
|
29
|
+
credentials: grpc.CallCredentials | None
|
|
30
|
+
wait_for_ready: bool | None
|
|
31
|
+
compression: grpc.Compression | None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def credential_metadata(credential: Credential | None, metadata: Any = None) -> Any:
|
|
35
|
+
if credential is None:
|
|
36
|
+
return metadata
|
|
37
|
+
token = credential.token()
|
|
38
|
+
if inspect.isawaitable(token):
|
|
39
|
+
if inspect.iscoroutine(token):
|
|
40
|
+
token.close()
|
|
41
|
+
raise TypeError("synchronous calls require a synchronous credential")
|
|
42
|
+
return tuple(metadata or ()) + (("authorization", "Bearer " + token),)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def async_credential_metadata(
|
|
46
|
+
credential: Credential, metadata: Any = None, timeout: float | None = None
|
|
47
|
+
) -> Any:
|
|
48
|
+
try:
|
|
49
|
+
token = await asyncio.wait_for(
|
|
50
|
+
_resolve_async_token(credential), timeout=timeout
|
|
51
|
+
)
|
|
52
|
+
except TimeoutError as error:
|
|
53
|
+
raise credential_deadline_error() from error
|
|
54
|
+
return tuple(metadata or ()) + (("authorization", "Bearer " + token),)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async def _resolve_async_token(credential: Credential) -> str:
|
|
58
|
+
token = await asyncio.to_thread(credential.token)
|
|
59
|
+
if inspect.isawaitable(token):
|
|
60
|
+
return await token
|
|
61
|
+
return token
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def credential_deadline_error() -> grpc.aio.AioRpcError:
|
|
65
|
+
return grpc.aio.AioRpcError(
|
|
66
|
+
grpc.StatusCode.DEADLINE_EXCEEDED,
|
|
67
|
+
grpc.aio.Metadata(),
|
|
68
|
+
grpc.aio.Metadata(),
|
|
69
|
+
"credential lookup exceeded RPC deadline",
|
|
70
|
+
None,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _SyncCredentialInterceptor(grpc.UnaryUnaryClientInterceptor):
|
|
75
|
+
def __init__(self, credential: Credential) -> None:
|
|
76
|
+
self._credential = credential
|
|
77
|
+
|
|
78
|
+
def intercept_unary_unary(
|
|
79
|
+
self,
|
|
80
|
+
continuation: Callable[..., Any],
|
|
81
|
+
client_call_details: grpc.ClientCallDetails,
|
|
82
|
+
request: Any,
|
|
83
|
+
) -> Any:
|
|
84
|
+
details = _SyncCallDetails(
|
|
85
|
+
client_call_details.method,
|
|
86
|
+
client_call_details.timeout,
|
|
87
|
+
credential_metadata(self._credential, client_call_details.metadata),
|
|
88
|
+
client_call_details.credentials,
|
|
89
|
+
client_call_details.wait_for_ready,
|
|
90
|
+
client_call_details.compression,
|
|
91
|
+
)
|
|
92
|
+
return continuation(details, request)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class _AsyncCredentialInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
|
|
96
|
+
def __init__(self, credential: Credential) -> None:
|
|
97
|
+
self._credential = credential
|
|
98
|
+
|
|
99
|
+
async def intercept_unary_unary(
|
|
100
|
+
self,
|
|
101
|
+
continuation: Callable[..., Any],
|
|
102
|
+
client_call_details: grpc.aio.ClientCallDetails,
|
|
103
|
+
request: Any,
|
|
104
|
+
) -> Any:
|
|
105
|
+
loop = asyncio.get_running_loop()
|
|
106
|
+
started_at = loop.time()
|
|
107
|
+
metadata = await async_credential_metadata(
|
|
108
|
+
self._credential, client_call_details.metadata, client_call_details.timeout
|
|
109
|
+
)
|
|
110
|
+
remaining_timeout = client_call_details.timeout
|
|
111
|
+
if remaining_timeout is not None:
|
|
112
|
+
remaining_timeout -= loop.time() - started_at
|
|
113
|
+
if remaining_timeout <= 0:
|
|
114
|
+
raise credential_deadline_error()
|
|
115
|
+
details = grpc.aio.ClientCallDetails(
|
|
116
|
+
client_call_details.method,
|
|
117
|
+
remaining_timeout,
|
|
118
|
+
metadata,
|
|
119
|
+
client_call_details.credentials,
|
|
120
|
+
client_call_details.wait_for_ready,
|
|
121
|
+
)
|
|
122
|
+
return await continuation(details, request)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def sync_channel(server_address: str, credential: Credential | None) -> grpc.Channel:
|
|
126
|
+
channel = grpc.insecure_channel(server_address)
|
|
127
|
+
if credential is None:
|
|
128
|
+
return channel
|
|
129
|
+
return grpc.intercept_channel(channel, _SyncCredentialInterceptor(credential))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def async_channel(
|
|
133
|
+
server_address: str, credential: Credential | None
|
|
134
|
+
) -> grpc.aio.Channel:
|
|
135
|
+
if credential is None:
|
|
136
|
+
return grpc.aio.insecure_channel(server_address)
|
|
137
|
+
return grpc.aio.insecure_channel(
|
|
138
|
+
server_address,
|
|
139
|
+
interceptors=[
|
|
140
|
+
cast(grpc.aio.ClientInterceptor, _AsyncCredentialInterceptor(credential))
|
|
141
|
+
],
|
|
142
|
+
)
|
|
@@ -200,6 +200,7 @@ def _worker_error_status(error: BaseException) -> status_pb2.Status:
|
|
|
200
200
|
_ERROR_TYPE_TRUNCATION_MARKER,
|
|
201
201
|
),
|
|
202
202
|
stack_trace=_worker_stack_trace(stack_trace_source),
|
|
203
|
+
grpc_status=grpc.StatusCode.UNKNOWN.value[0],
|
|
203
204
|
)
|
|
204
205
|
if retry_after_error is not None:
|
|
205
206
|
worker_error.retry_after_seconds = retry_after_error.after_seconds
|