ankusa 0.2.4__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.
- ankusa-0.2.4/.gitignore +48 -0
- ankusa-0.2.4/CHANGELOG.md +64 -0
- ankusa-0.2.4/LICENSE +190 -0
- ankusa-0.2.4/PKG-INFO +223 -0
- ankusa-0.2.4/README.md +209 -0
- ankusa-0.2.4/pyproject.toml +31 -0
- ankusa-0.2.4/src/ankusa/__init__.py +46 -0
- ankusa-0.2.4/src/ankusa/admin/__init__.py +10 -0
- ankusa-0.2.4/src/ankusa/admin/client.py +153 -0
- ankusa-0.2.4/src/ankusa/admin/errors.py +57 -0
- ankusa-0.2.4/src/ankusa/claim_check/__init__.py +22 -0
- ankusa-0.2.4/src/ankusa/claim_check/client.py +129 -0
- ankusa-0.2.4/src/ankusa/claim_check/errors.py +66 -0
- ankusa-0.2.4/src/ankusa/claim_check/ref.py +42 -0
- ankusa-0.2.4/src/ankusa/py.typed +0 -0
- ankusa-0.2.4/src/ankusa/routes/__init__.py +15 -0
- ankusa-0.2.4/src/ankusa/routes/client.py +162 -0
- ankusa-0.2.4/src/ankusa/routes/errors.py +69 -0
- ankusa-0.2.4/src/ankusa/webhook.py +73 -0
- ankusa-0.2.4/tests/test_admin.py +119 -0
- ankusa-0.2.4/tests/test_conformance.py +400 -0
- ankusa-0.2.4/tests/test_routes.py +119 -0
- ankusa-0.2.4/uv.lock +426 -0
ankusa-0.2.4/.gitignore
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# The directory Mix will write compiled artifacts to. Recursive: this repo
|
|
2
|
+
# is a mono-repo of multiple Mix projects (packages/*, examples/*/*), each
|
|
3
|
+
# with its own _build/.
|
|
4
|
+
**/_build/
|
|
5
|
+
|
|
6
|
+
# If you run "mix test --cover", coverage assets end up here.
|
|
7
|
+
**/cover/
|
|
8
|
+
|
|
9
|
+
# The directory Mix downloads your dependencies sources to.
|
|
10
|
+
**/deps/
|
|
11
|
+
|
|
12
|
+
# Where third-party dependencies like ExDoc output generated docs.
|
|
13
|
+
**/doc/
|
|
14
|
+
|
|
15
|
+
# Temporary files, for example, from tests.
|
|
16
|
+
/tmp/
|
|
17
|
+
packages/*/tmp/
|
|
18
|
+
|
|
19
|
+
# Local WAL, segments, quarantine, and DLQ written by the framework at runtime.
|
|
20
|
+
packages/*/data/
|
|
21
|
+
|
|
22
|
+
# If the VM crashes, it generates a dump, let's ignore it too.
|
|
23
|
+
erl_crash.dump
|
|
24
|
+
|
|
25
|
+
# Also ignore archive artifacts (built via "mix archive.build").
|
|
26
|
+
*.ez
|
|
27
|
+
|
|
28
|
+
# Ignore package tarballs (built via "mix hex.build").
|
|
29
|
+
packages/*/*.tar
|
|
30
|
+
|
|
31
|
+
# Node (examples/*/worker).
|
|
32
|
+
**/node_modules/
|
|
33
|
+
|
|
34
|
+
# TypeScript / Python SDK build output (built via "npm run build" /
|
|
35
|
+
# "npm pack" / "uv build").
|
|
36
|
+
packages/sdk-typescript/dist/
|
|
37
|
+
packages/sdk-python/dist/
|
|
38
|
+
|
|
39
|
+
# Python (packages/sdk-python, examples/quickstart).
|
|
40
|
+
**/.venv/
|
|
41
|
+
**/__pycache__/
|
|
42
|
+
**/*.egg-info/
|
|
43
|
+
**/.pytest_cache/
|
|
44
|
+
**/.mypy_cache/
|
|
45
|
+
*.tgz
|
|
46
|
+
|
|
47
|
+
# Load-generator output from examples/oban-consumer/run.sh (CSVs + JSON reports).
|
|
48
|
+
examples/oban-consumer/.e2e-out/
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `ankusa` (the PyPI package) are documented here.
|
|
4
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
5
|
+
this project follows [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.2.4] - 2026-09-28
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `RoutesClient(base_url, headers=None, timeout=10.0)`: the route-management
|
|
14
|
+
client (`routes.admin.port`) — `health`, `list_routes`, `create_route`,
|
|
15
|
+
`get_route`, `replace_route`, `update_route`, `delete_route`, `get_ip_rules`,
|
|
16
|
+
`put_ip_rules`, `test_route` — with a `RoutesError` hierarchy
|
|
17
|
+
(`RouteNotFoundError`, `RoutesRejectedError`, `RoutesUnavailableError`).
|
|
18
|
+
- `AdminClient(base_url, headers=None, timeout=10.0)`: the operator client
|
|
19
|
+
(`admin.port`) — `health`, `metrics`, `config`, `list_dead_letters`,
|
|
20
|
+
`replay_dead_letters`, `list_quarantined` — with an `AdminError` hierarchy
|
|
21
|
+
(`RoleNotEnabledError`, `AdminRejectedError`, `AdminUnavailableError`).
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- `parse_headers` no longer raises `ValueError` for an `x-ankusa-seq` value
|
|
26
|
+
that `str.isdigit()` accepts but `int()` rejects (e.g. `²`); a sequence
|
|
27
|
+
number now requires all-ASCII digits and is `None` otherwise.
|
|
28
|
+
|
|
29
|
+
## [0.2.1] - 2026-09-28
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- Claim-check refs are now `urn:ankusa:claim:v1:<tenant>:<claim_id>`, where
|
|
34
|
+
`claim_id` is a canonical uppercase ULID; `parse_claim_ref` returns
|
|
35
|
+
`ParsedClaimRef(tenant_id, claim_id, path)` and `redeem` fetches
|
|
36
|
+
`GET /v1/claims/{tenant_id}/{claim_id}`.
|
|
37
|
+
- `ClaimCheckClient.redeem(ref, sha256)` takes the expected sha256 (the queue
|
|
38
|
+
message's `sha256` field) and verifies the returned bytes against it. A
|
|
39
|
+
malformed `sha256` raises `InvalidClaimRefError` before any request.
|
|
40
|
+
|
|
41
|
+
## [0.1.0] - 2026-09-27
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- `ClaimCheckClient(base_url, headers=None, timeout=10.0)`, the first client
|
|
46
|
+
this package bundles: `.redeem(ref)` parses a claim-check ref, fetches its
|
|
47
|
+
bytes from the gateway, and verifies them against the ref's own declared
|
|
48
|
+
size and sha256 before returning them. `.health()` for a liveness probe.
|
|
49
|
+
Built on [`httpx`](https://www.python-httpx.org/) against the contract in
|
|
50
|
+
`priv/openapi/claim_check.v1.yaml`.
|
|
51
|
+
- `parse_claim_ref`, exported standalone.
|
|
52
|
+
- A `ClaimCheckError` hierarchy (`InvalidClaimRefError`,
|
|
53
|
+
`ClaimNotFoundError`, `ClaimRejectedError`, `ClaimIntegrityError`,
|
|
54
|
+
`ClaimCheckUnavailableError`), each carrying a `retryable` boolean, so a
|
|
55
|
+
consumer needs exactly one bit to route a failure to dead-letter or retry.
|
|
56
|
+
- `parse_headers(headers)`, for receivers of Ankusa's HTTP sink: parses
|
|
57
|
+
`x-ankusa-id`/`x-ankusa-source`/`x-ankusa-seq`/`x-ankusa-tenant`/
|
|
58
|
+
`content-type` into a `HookHeaders` dataclass, raising
|
|
59
|
+
`MissingHookIdError` if `x-ankusa-id` is absent.
|
|
60
|
+
|
|
61
|
+
[Unreleased]: https://github.com/jamescarr/ankusa/compare/sdk-python-v0.2.4...HEAD
|
|
62
|
+
[0.2.4]: https://github.com/jamescarr/ankusa/compare/sdk-python-v0.2.1...sdk-python-v0.2.4
|
|
63
|
+
[0.2.1]: https://github.com/jamescarr/ankusa/releases/tag/sdk-python-v0.2.1
|
|
64
|
+
[0.1.0]: https://github.com/jamescarr/ankusa/releases/tag/sdk-python-v0.1.0
|
ankusa-0.2.4/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing
|
|
141
|
+
the origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 The Ankusa Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
ankusa-0.2.4/PKG-INFO
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ankusa
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: Client SDK for Ankusa deployments. Bundles the claim-check gateway client, the route-management and operator (admin) clients, and a webhook-receiving header helper; more clients (ingest) land here as they're built.
|
|
5
|
+
Project-URL: Repository, https://github.com/jamescarr/ankusa
|
|
6
|
+
Project-URL: Homepage, https://github.com/jamescarr/ankusa/tree/main/packages/sdk-python
|
|
7
|
+
Project-URL: Issues, https://github.com/jamescarr/ankusa/issues
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: admin,ankusa,claim-check,routes,webhook
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Requires-Dist: httpx>=0.27
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# ankusa
|
|
16
|
+
|
|
17
|
+
The client SDK for [Ankusa](https://github.com/jamescarr/ankusa) deployments:
|
|
18
|
+
one PyPI package meant to bundle everything a non-Elixir consumer needs to
|
|
19
|
+
talk to an Ankusa deployment. Today that's the
|
|
20
|
+
[claim-check gateway](https://github.com/jamescarr/ankusa/blob/main/docs/claim-check.md)
|
|
21
|
+
client and a webhook-receiving header helper; more clients (ingest, admin)
|
|
22
|
+
land here as they're built.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
Not published yet. Until the first release, depend on it as a local path,
|
|
27
|
+
the same way the Elixir packages in this monorepo depend on `ankusa` core
|
|
28
|
+
before their first Hex release, and `packages/sdk-typescript` depends on
|
|
29
|
+
itself via `file:`.
|
|
30
|
+
|
|
31
|
+
With [`uv`](https://docs.astral.sh/uv/):
|
|
32
|
+
|
|
33
|
+
```toml
|
|
34
|
+
[project]
|
|
35
|
+
dependencies = ["ankusa"]
|
|
36
|
+
|
|
37
|
+
[tool.uv.sources]
|
|
38
|
+
ankusa = { path = "../../packages/sdk-python" }
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or with plain `pip`:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pip install -e ../../packages/sdk-python
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Claim-check client
|
|
48
|
+
|
|
49
|
+
Redeem a claim-check ref, verify the bytes it returns against the message's
|
|
50
|
+
`sha256`, and classify failures into dead-letter vs. retry,
|
|
51
|
+
without holding any object-store credentials. Conforms to the framework's
|
|
52
|
+
own contract, [`priv/openapi/claim_check.v1.yaml`](../ankusa/priv/openapi/claim_check.v1.yaml):
|
|
53
|
+
the spec is the source of truth, this package conforms to it, not the
|
|
54
|
+
reverse.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import os
|
|
58
|
+
|
|
59
|
+
from ankusa import ClaimCheckClient, ClaimCheckError
|
|
60
|
+
|
|
61
|
+
claim_check = ClaimCheckClient(os.environ.get("CLAIM_CHECK_URL", "http://localhost:4001"))
|
|
62
|
+
|
|
63
|
+
# A queue message that carries a claim also carries its sha256:
|
|
64
|
+
# "claim": "urn:ankusa:claim:v1:<tenant>:<claim_id>" (claim_id: uppercase ULID)
|
|
65
|
+
# "sha256": 64-char lowercase hex of the claim's bytes
|
|
66
|
+
def resolve_body(message: dict) -> bytes:
|
|
67
|
+
try:
|
|
68
|
+
return claim_check.redeem(message["claim"], message["sha256"])
|
|
69
|
+
except ClaimCheckError as err:
|
|
70
|
+
if not err.retryable:
|
|
71
|
+
# bad ref/sha256, 404, or an integrity mismatch: dead-letter, don't requeue
|
|
72
|
+
raise
|
|
73
|
+
# gateway unreachable or 5xx: safe to retry
|
|
74
|
+
raise
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`redeem()` does three things `GET /v1/claims/...` alone doesn't:
|
|
78
|
+
|
|
79
|
+
1. Parses the ref into its tenant id, claim id, and gateway path
|
|
80
|
+
(`GET /v1/claims/{tenant_id}/{claim_id}`) (`parse_claim_ref`, also
|
|
81
|
+
exported standalone).
|
|
82
|
+
2. Fetches the bytes.
|
|
83
|
+
3. Verifies them against the message's `sha256` (the gateway
|
|
84
|
+
itself does not check this, see "Redeem a claim" in
|
|
85
|
+
[`docs/claim-check.md`](https://github.com/jamescarr/ankusa/blob/main/docs/claim-check.md))
|
|
86
|
+
before ever returning them to you.
|
|
87
|
+
|
|
88
|
+
Every failure is a `ClaimCheckError` subclass with a `retryable` attribute,
|
|
89
|
+
so a consumer needs exactly one bit to decide dead-letter vs. retry:
|
|
90
|
+
|
|
91
|
+
| Class | `retryable` | Cause |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| `InvalidClaimRefError` | `False` | `ref` isn't a well-formed claim-check URN, or `sha256` isn't 64-char lowercase hex |
|
|
94
|
+
| `ClaimNotFoundError` | `False` | gateway `404`: expired by retention, or never written |
|
|
95
|
+
| `ClaimRejectedError` | `False` | gateway `4xx` other than `404` (`.status`, `.body`) |
|
|
96
|
+
| `ClaimIntegrityError` | `False` | sha256 of the returned bytes doesn't match |
|
|
97
|
+
| `ClaimCheckUnavailableError` | `True` | gateway `5xx`/`503`, or unreachable |
|
|
98
|
+
|
|
99
|
+
`health()` hits `GET /health` for a liveness probe.
|
|
100
|
+
|
|
101
|
+
`ClaimCheckClient` owns an `httpx.Client`; use it as a context manager
|
|
102
|
+
(`with ClaimCheckClient(...) as claim_check:`) or call `.close()` yourself
|
|
103
|
+
when done.
|
|
104
|
+
|
|
105
|
+
## Webhook receiver helper
|
|
106
|
+
|
|
107
|
+
Every receiver of Ankusa's HTTP sink needs the same handful of headers off
|
|
108
|
+
each request; `parse_headers` replaces the hand-rolled `self.headers.get(...)`
|
|
109
|
+
calls with one call and a typed result:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from ankusa import MissingHookIdError, parse_headers
|
|
113
|
+
|
|
114
|
+
def do_POST(self):
|
|
115
|
+
try:
|
|
116
|
+
hook = parse_headers(self.headers)
|
|
117
|
+
except MissingHookIdError:
|
|
118
|
+
self.send_response(400)
|
|
119
|
+
self.end_headers()
|
|
120
|
+
return
|
|
121
|
+
|
|
122
|
+
body = self.rfile.read(int(self.headers.get("content-length", "0")))
|
|
123
|
+
# hook.id, hook.source, hook.seq, hook.tenant, hook.content_type
|
|
124
|
+
...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`HookHeaders.id` is what a receiver dedupes on: delivery is at-least-once
|
|
128
|
+
(see "HTTP handoff" in
|
|
129
|
+
[`docs/integrations.md`](https://github.com/jamescarr/ankusa/blob/main/docs/integrations.md)),
|
|
130
|
+
so the same hook can arrive twice after a retry. Header lookup is always
|
|
131
|
+
case-insensitive, regardless of whether the mapping passed in already is.
|
|
132
|
+
|
|
133
|
+
[`examples/quickstart/worker.py`](https://github.com/jamescarr/ankusa/tree/main/examples/quickstart/worker.py)
|
|
134
|
+
uses this.
|
|
135
|
+
|
|
136
|
+
## Routes client
|
|
137
|
+
|
|
138
|
+
Manage route definitions and the global IP rules on the route-management
|
|
139
|
+
listener (`routes.admin.port`, default 4003) — the `routes` tag of
|
|
140
|
+
[`priv/openapi/admin.v1.yaml`](../ankusa/priv/openapi/admin.v1.yaml).
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import os
|
|
144
|
+
|
|
145
|
+
from ankusa import RoutesClient
|
|
146
|
+
|
|
147
|
+
routes = RoutesClient(os.environ.get("ROUTES_URL", "http://localhost:4003"))
|
|
148
|
+
|
|
149
|
+
routes.create_route({"id": "stripe", "path": "/webhooks/stripe"})
|
|
150
|
+
routes.get_ip_rules() # {"default": "allow", "rules": []}
|
|
151
|
+
routes.test_route({"method": "POST", "path": "/webhooks/stripe", "ip": "203.0.113.7"})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Methods: `health()`, `list_routes()`, `create_route()`, `get_route()`,
|
|
155
|
+
`replace_route()`, `update_route()`, `delete_route()`, `get_ip_rules()`,
|
|
156
|
+
`put_ip_rules()`, `test_route()`. Failures are `RoutesError` subclasses with a
|
|
157
|
+
`retryable` attribute: `RouteNotFoundError` (404), `RoutesRejectedError`
|
|
158
|
+
(400/409, carrying `code`, `field`, `message`, `conflicting_id`,
|
|
159
|
+
`max_routes`), and `RoutesUnavailableError` (5xx/unreachable, retryable).
|
|
160
|
+
|
|
161
|
+
## Admin client
|
|
162
|
+
|
|
163
|
+
The operator API on `admin.port` (default 4002): health, Prometheus metrics,
|
|
164
|
+
the redacted config, the DLQ, and the quarantine list — the `operations`,
|
|
165
|
+
`dlq`, and `quarantine` tags of `admin.v1.yaml`.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import os
|
|
169
|
+
|
|
170
|
+
from ankusa import AdminClient
|
|
171
|
+
|
|
172
|
+
admin = AdminClient(os.environ.get("ADMIN_URL", "http://localhost:4002"))
|
|
173
|
+
|
|
174
|
+
admin.health() # {"status": "ok", "instance": ..., "roles": [...]}
|
|
175
|
+
admin.list_dead_letters(limit=10)
|
|
176
|
+
admin.replay_dead_letters({"source_id": "demo"})
|
|
177
|
+
admin.list_quarantined()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Methods: `health()`, `metrics()` (Prometheus text), `config()`,
|
|
181
|
+
`list_dead_letters()`, `replay_dead_letters()`, `list_quarantined()`. Failures
|
|
182
|
+
are `AdminError` subclasses: `RoleNotEnabledError` (409, carrying `role`),
|
|
183
|
+
`AdminRejectedError` (400, carrying `code`), and `AdminUnavailableError`
|
|
184
|
+
(5xx/unreachable, retryable).
|
|
185
|
+
|
|
186
|
+
## Layout
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
src/ankusa/
|
|
190
|
+
__init__.py # umbrella barrel: re-exports every client this package bundles
|
|
191
|
+
py.typed
|
|
192
|
+
webhook.py # x-ankusa-* header parsing for HTTP-sink receivers
|
|
193
|
+
claim_check/ # the claim-check gateway client
|
|
194
|
+
__init__.py # barrel for this client
|
|
195
|
+
client.py
|
|
196
|
+
ref.py
|
|
197
|
+
errors.py
|
|
198
|
+
routes/ # the route-management client (routes.admin.port)
|
|
199
|
+
__init__.py
|
|
200
|
+
client.py
|
|
201
|
+
errors.py
|
|
202
|
+
admin/ # the operator client (admin.port)
|
|
203
|
+
__init__.py
|
|
204
|
+
client.py
|
|
205
|
+
errors.py
|
|
206
|
+
tests/
|
|
207
|
+
test_client.py
|
|
208
|
+
test_ref.py
|
|
209
|
+
test_webhook.py
|
|
210
|
+
test_routes.py
|
|
211
|
+
test_admin.py
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
A future client (say, an ingest helper) gets its own `src/ankusa/<name>/`
|
|
215
|
+
directory with the same shape, re-exported from `src/ankusa/__init__.py`.
|
|
216
|
+
|
|
217
|
+
## Develop
|
|
218
|
+
|
|
219
|
+
```sh
|
|
220
|
+
uv sync
|
|
221
|
+
uv run pytest
|
|
222
|
+
uv run mypy
|
|
223
|
+
```
|