ocel 0.0.0.dev0__tar.gz → 0.0.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.
Files changed (78) hide show
  1. {ocel-0.0.0.dev0 → ocel-0.0.1}/.gitignore +4 -4
  2. ocel-0.0.1/LICENSE +202 -0
  3. ocel-0.0.1/NOTICE +2 -0
  4. {ocel-0.0.0.dev0 → ocel-0.0.1}/PKG-INFO +9 -1
  5. {ocel-0.0.0.dev0 → ocel-0.0.1}/pyproject.toml +4 -1
  6. ocel-0.0.1/src/ocel/__init__.py +112 -0
  7. ocel-0.0.1/src/ocel/_binding.py +97 -0
  8. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/_declare.py +25 -23
  9. ocel-0.0.1/src/ocel/_error.py +2 -0
  10. ocel-0.0.1/src/ocel/_kv_authority.py +31 -0
  11. ocel-0.0.1/src/ocel/_payload.py +90 -0
  12. ocel-0.0.1/src/ocel/_realtime_token.py +62 -0
  13. ocel-0.0.1/src/ocel/_realtime_wire.py +95 -0
  14. ocel-0.0.1/src/ocel/_registry.py +36 -0
  15. ocel-0.0.1/src/ocel/_wire.py +49 -0
  16. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/bucket.py +276 -301
  17. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/env.py +142 -141
  18. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/bucket/v1/bucket_pb.py +1 -1
  19. ocel-0.0.1/src/ocel/gen/app/realtime/v1/realtime_connect.py +148 -0
  20. ocel-0.0.1/src/ocel/gen/app/realtime/v1/realtime_pb.py +93 -0
  21. ocel-0.0.1/src/ocel/gen/app/resources/v1/resources_pb.py +824 -0
  22. ocel-0.0.1/src/ocel/gen/app/task/v1/task_connect.py +538 -0
  23. ocel-0.0.1/src/ocel/gen/app/task/v1/task_pb.py +817 -0
  24. ocel-0.0.1/src/ocel/gen/app/topic/v1/__init__.py +1 -0
  25. ocel-0.0.1/src/ocel/gen/app/topic/v1/topic_connect.py +408 -0
  26. ocel-0.0.1/src/ocel/gen/app/topic/v1/topic_pb.py +758 -0
  27. ocel-0.0.1/src/ocel/gen/buf/__init__.py +1 -0
  28. ocel-0.0.1/src/ocel/gen/buf/validate/__init__.py +1 -0
  29. ocel-0.0.1/src/ocel/gen/common/__init__.py +1 -0
  30. ocel-0.0.1/src/ocel/gen/common/bindings/__init__.py +1 -0
  31. ocel-0.0.1/src/ocel/gen/common/bindings/v1/__init__.py +1 -0
  32. ocel-0.0.1/src/ocel/gen/common/bindings/v1/bindings_pb.py +569 -0
  33. ocel-0.0.1/src/ocel/kv.py +821 -0
  34. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/postgres.py +25 -9
  35. ocel-0.0.1/src/ocel/realtime.py +777 -0
  36. ocel-0.0.1/src/ocel/run.py +323 -0
  37. ocel-0.0.1/src/ocel/task.py +366 -0
  38. ocel-0.0.1/src/ocel/topic.py +440 -0
  39. ocel-0.0.1/src/ocel/worker.py +379 -0
  40. {ocel-0.0.0.dev0 → ocel-0.0.1}/tests/conftest.py +5 -0
  41. {ocel-0.0.0.dev0 → ocel-0.0.1}/tests/fakebucket.py +25 -25
  42. ocel-0.0.1/tests/fakerealtime.py +83 -0
  43. ocel-0.0.1/tests/fakeruntime.py +166 -0
  44. {ocel-0.0.0.dev0 → ocel-0.0.1}/tests/test_bucket.py +65 -65
  45. ocel-0.0.1/tests/test_delivery.py +618 -0
  46. {ocel-0.0.0.dev0 → ocel-0.0.1}/tests/test_env.py +21 -19
  47. ocel-0.0.1/tests/test_kv.py +405 -0
  48. ocel-0.0.1/tests/test_kv_encoding.py +94 -0
  49. ocel-0.0.1/tests/test_kv_tls.py +182 -0
  50. {ocel-0.0.0.dev0 → ocel-0.0.1}/tests/test_postgres.py +8 -8
  51. ocel-0.0.1/tests/test_postgres_tls.py +149 -0
  52. ocel-0.0.1/tests/test_realtime.py +752 -0
  53. ocel-0.0.1/tests/test_realtime_token.py +18 -0
  54. ocel-0.0.1/tests/test_realtime_wire.py +37 -0
  55. ocel-0.0.1/tests/test_runs.py +154 -0
  56. ocel-0.0.1/tests/test_task.py +291 -0
  57. ocel-0.0.1/tests/test_topic.py +237 -0
  58. ocel-0.0.1/tests/test_worker.py +33 -0
  59. ocel-0.0.0.dev0/src/ocel/__init__.py +0 -50
  60. ocel-0.0.0.dev0/src/ocel/_binding.py +0 -53
  61. ocel-0.0.0.dev0/src/ocel/gen/app/resources/v1/resources_pb.py +0 -223
  62. ocel-0.0.0.dev0/src/ocel/gen/common/bindings/v1/bindings_pb.py +0 -293
  63. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/_live.py +0 -0
  64. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/__init__.py +0 -0
  65. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/__init__.py +0 -0
  66. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/bucket/__init__.py +0 -0
  67. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/bucket/v1/__init__.py +0 -0
  68. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/bucket/v1/bucket_connect.py +0 -0
  69. {ocel-0.0.0.dev0/src/ocel/gen/app/resources → ocel-0.0.1/src/ocel/gen/app/realtime}/__init__.py +0 -0
  70. {ocel-0.0.0.dev0/src/ocel/gen/app/resources → ocel-0.0.1/src/ocel/gen/app/realtime}/v1/__init__.py +0 -0
  71. {ocel-0.0.0.dev0/src/ocel/gen/buf → ocel-0.0.1/src/ocel/gen/app/resources}/__init__.py +0 -0
  72. {ocel-0.0.0.dev0/src/ocel/gen/buf/validate → ocel-0.0.1/src/ocel/gen/app/resources/v1}/__init__.py +0 -0
  73. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/resources/v1/resources_connect.py +0 -0
  74. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/app/resources/v1/variables_pb.py +0 -0
  75. {ocel-0.0.0.dev0/src/ocel/gen/common → ocel-0.0.1/src/ocel/gen/app/task}/__init__.py +0 -0
  76. {ocel-0.0.0.dev0/src/ocel/gen/common/bindings → ocel-0.0.1/src/ocel/gen/app/task/v1}/__init__.py +0 -0
  77. {ocel-0.0.0.dev0/src/ocel/gen/common/bindings/v1 → ocel-0.0.1/src/ocel/gen/app/topic}/__init__.py +0 -0
  78. {ocel-0.0.0.dev0 → ocel-0.0.1}/src/ocel/gen/buf/validate/validate_pb.py +0 -0
@@ -1,5 +1,5 @@
1
1
  # Logs
2
- logs
2
+ /logs/
3
3
  *.log
4
4
  npm-debug.log*
5
5
  yarn-debug.log*
@@ -190,6 +190,8 @@ crates/target/
190
190
  tests/fixtures/sdk/rust/target/
191
191
  tests/fixtures/sdk/rust-workspace/target/
192
192
  tests/fixtures/deploy/rust/server/target/
193
+ tests/fixtures/worker/rust/target/
194
+ tests/fixtures/realtime/rust/target/
193
195
 
194
196
  .workflow-data
195
197
  packages/cli-*/bin/
@@ -216,9 +218,7 @@ cli/platform/dist/
216
218
 
217
219
  mise.local.toml
218
220
 
219
- # `go build` inside the helper's own directory; the embedded copies are built into
220
- # platform/vps/provider/host/dist by host/generate.sh.
221
- platform/vps/provider/cmd/proxyctl/proxyctl
221
+ platform/vps/provider/cmd/switchboard/switchboard
222
222
 
223
223
  # Turborepo
224
224
  .turbo
ocel-0.0.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
ocel-0.0.1/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Ocel
2
+ Copyright 2026 The Ocel Authors
@@ -1,11 +1,19 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ocel
3
- Version: 0.0.0.dev0
3
+ Version: 0.0.1
4
4
  Summary: Declare the infrastructure a Python app needs from the app itself
5
5
  License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
6
8
  Requires-Python: >=3.12
7
9
  Requires-Dist: connectrpc<0.13,>=0.12.1
8
10
  Requires-Dist: protobuf-py<0.5,>=0.4
9
11
  Requires-Dist: pyqwest<0.11,>=0.10
12
+ Provides-Extra: kv
13
+ Requires-Dist: redis>=5.0.1; extra == 'kv'
10
14
  Provides-Extra: postgres
11
15
  Requires-Dist: asyncpg>=0.30; extra == 'postgres'
16
+ Provides-Extra: pydantic
17
+ Requires-Dist: pydantic<3,>=2.7; extra == 'pydantic'
18
+ Provides-Extra: realtime
19
+ Requires-Dist: cryptography>=43; extra == 'realtime'
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ocel"
3
- version = "0.0.0.dev0"
3
+ version = "0.0.1"
4
4
  description = "Declare the infrastructure a Python app needs from the app itself"
5
5
  requires-python = ">=3.12"
6
6
  license = "Apache-2.0"
@@ -9,6 +9,9 @@ dependencies = ["connectrpc>=0.12.1,<0.13", "protobuf-py>=0.4,<0.5", "pyqwest>=0
9
9
 
10
10
  [project.optional-dependencies]
11
11
  postgres = ["asyncpg>=0.30"]
12
+ pydantic = ["pydantic>=2.7,<3"]
13
+ kv = ["redis>=5.0.1"]
14
+ realtime = ["cryptography>=43"]
12
15
 
13
16
  [build-system]
14
17
  requires = ["hatchling>=1.27"]
@@ -0,0 +1,112 @@
1
+ from ocel._binding import UnprovisionedResourceError
2
+ from ocel.bucket import (
3
+ AsyncBucket,
4
+ AsyncObjectBody,
5
+ Bucket,
6
+ ObjectBody,
7
+ ObjectInfo,
8
+ ObjectNotFound,
9
+ PreconditionFailed,
10
+ SignedUpload,
11
+ SyncBucket,
12
+ bucket,
13
+ )
14
+ from ocel.env import (
15
+ Env,
16
+ EnvDefinitionError,
17
+ EnvScopeError,
18
+ EnvValueError,
19
+ Group,
20
+ Secret,
21
+ deployment_url,
22
+ group,
23
+ var,
24
+ )
25
+ from ocel.kv import KV, InvalidKVValueError, kv
26
+ from ocel.postgres import Postgres, postgres
27
+ from ocel.realtime import (
28
+ Channel,
29
+ Realtime,
30
+ RealtimePublishError,
31
+ RealtimeRequest,
32
+ RuleContext,
33
+ realtime,
34
+ )
35
+ from ocel.run import (
36
+ AbortTaskRunError,
37
+ CatchErrorResult,
38
+ Run,
39
+ RunAttempt,
40
+ RunContext,
41
+ RunHandle,
42
+ RunMessage,
43
+ RunPage,
44
+ RunResult,
45
+ Runs,
46
+ RunStatus,
47
+ runs,
48
+ )
49
+ from ocel.task import Batch, Debounce, Task, Trigger, task
50
+ from ocel.topic import Consumer, DeadLetter, DeadLetterPage, DeadLetters, Lane, Retry, Topic, topic
51
+ from ocel.worker import Worker, worker
52
+
53
+ __all__ = [
54
+ "AbortTaskRunError",
55
+ "AsyncBucket",
56
+ "AsyncObjectBody",
57
+ "Batch",
58
+ "Bucket",
59
+ "CatchErrorResult",
60
+ "Channel",
61
+ "Consumer",
62
+ "DeadLetter",
63
+ "DeadLetterPage",
64
+ "DeadLetters",
65
+ "Debounce",
66
+ "Env",
67
+ "EnvDefinitionError",
68
+ "EnvScopeError",
69
+ "EnvValueError",
70
+ "Group",
71
+ "InvalidKVValueError",
72
+ "KV",
73
+ "Lane",
74
+ "ObjectBody",
75
+ "ObjectInfo",
76
+ "ObjectNotFound",
77
+ "Postgres",
78
+ "PreconditionFailed",
79
+ "Realtime",
80
+ "RealtimePublishError",
81
+ "RealtimeRequest",
82
+ "Retry",
83
+ "Run",
84
+ "RunAttempt",
85
+ "RunContext",
86
+ "RunHandle",
87
+ "RunMessage",
88
+ "RunPage",
89
+ "RunResult",
90
+ "RuleContext",
91
+ "RunStatus",
92
+ "Runs",
93
+ "Secret",
94
+ "SignedUpload",
95
+ "SyncBucket",
96
+ "Task",
97
+ "Topic",
98
+ "Trigger",
99
+ "UnprovisionedResourceError",
100
+ "Worker",
101
+ "bucket",
102
+ "deployment_url",
103
+ "group",
104
+ "kv",
105
+ "postgres",
106
+ "realtime",
107
+ "runs",
108
+ "task",
109
+ "topic",
110
+ "var",
111
+ "worker",
112
+ ]
@@ -0,0 +1,97 @@
1
+ import os
2
+
3
+ from ocel._live import live_value
4
+ from ocel.gen.common.bindings.v1.bindings_pb import (
5
+ Binding,
6
+ BucketProperties,
7
+ KvProperties,
8
+ PostgresProperties,
9
+ RealtimeProperties,
10
+ )
11
+
12
+ _RUNTIME_ADDRESS_ENV = "OCEL_RUNTIME_ADDRESS"
13
+ _SESSION_TOKEN_ENV = "OCEL_SESSION_TOKEN"
14
+
15
+
16
+ class UnprovisionedResourceError(RuntimeError):
17
+ """Raised when app code reaches for a resource this run never provisioned, which is
18
+ discovery: the pass that reads the declarations before anything is provisioned. Catch
19
+ it to keep a boot path alive when the resource is optional there; anything else raised
20
+ from the same call means the resource exists and is genuinely broken."""
21
+
22
+
23
+ def refuse_unprovisioned(what: str, access: str) -> UnprovisionedResourceError:
24
+ return UnprovisionedResourceError(
25
+ f"'{what}' cannot be used during discovery: "
26
+ f"tried to access '{access}' before the resource was provisioned"
27
+ )
28
+
29
+
30
+ def read_postgres_binding(name: str) -> PostgresProperties:
31
+ return _read_properties(name, "postgres")
32
+
33
+
34
+ def read_bucket_binding(name: str) -> BucketProperties:
35
+ return _read_properties(name, "bucket")
36
+
37
+
38
+ def read_kv_binding(name: str) -> KvProperties:
39
+ return _read_properties(name, "kv")
40
+
41
+
42
+ def read_realtime_binding(name: str) -> RealtimeProperties:
43
+ return _read_properties(name, "realtime")
44
+
45
+
46
+ def refuse_unbound(name: str, kind: str) -> RuntimeError | None:
47
+ found = _find_properties(name, kind)
48
+ return found if isinstance(found, RuntimeError) else None
49
+
50
+
51
+ def read_runtime() -> tuple[str, dict[str, str]]:
52
+ address = os.environ.get(_RUNTIME_ADDRESS_ENV)
53
+ if not address:
54
+ raise RuntimeError(
55
+ f"{_RUNTIME_ADDRESS_ENV} is not defined, so no resource the ocel runtime "
56
+ f"serves can be reached. Run `ocel dev` to serve it locally, or "
57
+ f"`ocel deploy` to have the deployed runtime's address delivered."
58
+ )
59
+ token = os.environ.get(_SESSION_TOKEN_ENV)
60
+ if not token:
61
+ raise RuntimeError(
62
+ f"{_SESSION_TOKEN_ENV} is not defined, so the ocel runtime at {address} "
63
+ f"would refuse every call. It is delivered beside {_RUNTIME_ADDRESS_ENV} by "
64
+ f"`ocel dev` and by the deployed runtime, never set by hand."
65
+ )
66
+ return address.rstrip("/"), {"Authorization": f"Bearer {token}"}
67
+
68
+
69
+ def _read_properties(name: str, kind: str):
70
+ found = _find_properties(name, kind)
71
+ if isinstance(found, RuntimeError):
72
+ raise found
73
+ return found
74
+
75
+
76
+ def _find_properties(name: str, kind: str):
77
+ key = f"OCEL_RESOURCE_{kind.upper()}_{name}"
78
+ raw = os.environ.get(key) or live_value(key)
79
+ if not raw:
80
+ return RuntimeError(
81
+ f"Value for {key} is not defined. Run `ocel dev` to resolve it locally, "
82
+ f"or `ocel deploy` to have it delivered from the resource this app binds."
83
+ )
84
+ try:
85
+ delivered = Binding.from_json(raw, ignore_unknown_fields=True)
86
+ except Exception:
87
+ return RuntimeError(
88
+ f"{key} does not contain a binding record, "
89
+ f"so this app cannot read it as a {kind.upper()}"
90
+ )
91
+ properties = delivered.properties
92
+ if properties is None or properties.field != kind:
93
+ found = properties.field.upper() if properties else "UNSPECIFIED"
94
+ return RuntimeError(
95
+ f"{key} contains a {found} binding, and this app reads it as a {kind.upper()}"
96
+ )
97
+ return properties.value
@@ -1,7 +1,9 @@
1
+ import inspect
1
2
  import os
2
3
  from importlib.metadata import PackageNotFoundError
3
4
  from importlib.metadata import version as _installed
4
5
 
6
+ from ocel._error import format_error
5
7
  from ocel.gen.app.resources.v1.resources_connect import ResourceServiceClientSync
6
8
  from ocel.gen.app.resources.v1.resources_pb import DeclareRequest
7
9
  from ocel.gen.app.resources.v1.variables_pb import (
@@ -17,62 +19,62 @@ _DEV_SERVER_TOKEN_ENV = "OCEL_DEV_SERVER_TOKEN"
17
19
  _SDK_VERSION_HEADER = "Ocel-Sdk-Version"
18
20
 
19
21
 
20
- def sdk_version() -> str:
22
+ def read_sdk_version() -> str:
21
23
  try:
22
24
  return _installed("ocel")
23
25
  except PackageNotFoundError:
24
26
  return "dev"
25
27
 
26
28
 
27
- def discovering() -> bool:
29
+ def is_discovering() -> bool:
28
30
  return os.environ.get(_PHASE_ENV) == DISCOVERY_PHASE
29
31
 
30
32
 
31
- def _client() -> ResourceServiceClientSync:
33
+ def _new_client() -> ResourceServiceClientSync:
32
34
  address = os.environ.get(_DEV_SERVER_ENV, "").rstrip("/")
33
35
  return ResourceServiceClientSync(address, send_compression=None)
34
36
 
35
37
 
36
- def _headers() -> dict[str, str]:
38
+ def _build_headers() -> dict[str, str]:
37
39
  return {
38
40
  "Authorization": f"Bearer {os.environ.get(_DEV_SERVER_TOKEN_ENV, '')}",
39
- _SDK_VERSION_HEADER: f"python/{sdk_version()}",
41
+ _SDK_VERSION_HEADER: f"python/{read_sdk_version()}",
40
42
  }
41
43
 
42
44
 
45
+ def find_caller_source() -> str:
46
+ caller = inspect.stack(0)[2]
47
+ return f"{caller.filename}:{caller.lineno}"
48
+
49
+
43
50
  def declare(request: DeclareRequest) -> None:
44
51
  try:
45
- with _client() as client:
46
- client.declare(request, headers=_headers())
52
+ with _new_client() as client:
53
+ client.declare(request, headers=_build_headers())
47
54
  except Exception as error:
48
- raise _failed(request, error) from None
55
+ raise _build_declare_error(request, error) from None
49
56
 
50
57
 
51
58
  def declare_env(request: DeclareEnvRequest) -> DeclareEnvResponse:
52
59
  try:
53
- with _client() as client:
54
- return client.declare_env(request, headers=_headers())
60
+ with _new_client() as client:
61
+ return client.declare_env(request, headers=_build_headers())
55
62
  except Exception as error:
56
- raise _env_failed(error) from None
63
+ raise _build_env_error(error) from None
57
64
 
58
65
 
59
66
  def report_env_problems(request: ReportEnvProblemsRequest) -> None:
60
67
  try:
61
- with _client() as client:
62
- client.report_env_problems(request, headers=_headers())
68
+ with _new_client() as client:
69
+ client.report_env_problems(request, headers=_build_headers())
63
70
  except Exception as error:
64
- raise _env_failed(error) from None
71
+ raise _build_env_error(error) from None
65
72
 
66
73
 
67
- def _failed(request: DeclareRequest, error: Exception) -> RuntimeError:
68
- said = _said(error)
74
+ def _build_declare_error(request: DeclareRequest, error: Exception) -> RuntimeError:
69
75
  kind = request.config.field if request.config else "resource"
70
- return RuntimeError(f"ocel: declare {kind} '{request.resource.name}': {said}")
71
-
72
-
73
- def _env_failed(error: Exception) -> RuntimeError:
74
- return RuntimeError(f"ocel: declare env: {_said(error)}")
76
+ return RuntimeError(f"ocel: declare {kind} '{request.resource.name}': {format_error(error)}")
75
77
 
76
78
 
77
- def _said(error: Exception) -> str:
78
- return str(error).strip() or type(error).__name__
79
+ def _build_env_error(error: Exception) -> RuntimeError:
80
+ return RuntimeError(f"ocel: declare env: {format_error(error)}")
@@ -0,0 +1,2 @@
1
+ def format_error(error: BaseException) -> str:
2
+ return str(error).strip() or type(error).__name__
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ import ssl
4
+ from collections.abc import Mapping
5
+ from typing import Any
6
+
7
+ import redis.asyncio.connection
8
+ import redis.connection
9
+
10
+
11
+ class AuthorityConnection(redis.connection.Connection):
12
+ def __init__(self, *, ssl_authority: ssl.SSLContext, **kwargs: Any):
13
+ self._authority = ssl_authority
14
+ super().__init__(**kwargs)
15
+
16
+ def _connect(self):
17
+ plain = super()._connect()
18
+ try:
19
+ return self._authority.wrap_socket(plain, server_hostname=self.host)
20
+ except OSError:
21
+ plain.close()
22
+ raise
23
+
24
+
25
+ class AsyncAuthorityConnection(redis.asyncio.connection.Connection):
26
+ def __init__(self, *, ssl_authority: ssl.SSLContext, **kwargs: Any):
27
+ self._authority = ssl_authority
28
+ super().__init__(**kwargs)
29
+
30
+ def _connection_arguments(self) -> Mapping:
31
+ return {**super()._connection_arguments(), "ssl": self._authority}