educate-custodian-consumer 0.1.3__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.
- educate_custodian_consumer-0.1.3/.gitignore +9 -0
- educate_custodian_consumer-0.1.3/CHANGELOG.md +52 -0
- educate_custodian_consumer-0.1.3/PKG-INFO +176 -0
- educate_custodian_consumer-0.1.3/README.md +151 -0
- educate_custodian_consumer-0.1.3/pyproject.toml +72 -0
- educate_custodian_consumer-0.1.3/src/educate_custodian_consumer/__init__.py +54 -0
- educate_custodian_consumer-0.1.3/src/educate_custodian_consumer/client.py +675 -0
- educate_custodian_consumer-0.1.3/src/educate_custodian_consumer/errors.py +57 -0
- educate_custodian_consumer-0.1.3/src/educate_custodian_consumer/py.typed +0 -0
- educate_custodian_consumer-0.1.3/src/educate_custodian_consumer/settings.py +279 -0
- educate_custodian_consumer-0.1.3/tests/conftest.py +138 -0
- educate_custodian_consumer-0.1.3/tests/test_client_fetch.py +305 -0
- educate_custodian_consumer-0.1.3/tests/test_events.py +277 -0
- educate_custodian_consumer-0.1.3/tests/test_fetch_mode.py +241 -0
- educate_custodian_consumer-0.1.3/tests/test_settings.py +166 -0
- educate_custodian_consumer-0.1.3/tests/test_token.py +153 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `educate-custodian-consumer`.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project uses [semantic versioning](https://semver.org/) — with a
|
|
7
|
+
deliberate `0.x` major, because the API will move once a second app uses it.
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
Nothing yet.
|
|
12
|
+
|
|
13
|
+
## [0.1.0] — unreleased
|
|
14
|
+
|
|
15
|
+
First extraction of the client from
|
|
16
|
+
`examples/fastapi-consumer-typed-config/`. Not yet published to PyPI: that
|
|
17
|
+
needs a LICENSE decision and PyPI project ownership first (docs/22 §22.7d).
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `CustodianSettings` — a `pydantic-settings` base class carrying the
|
|
22
|
+
`custodian_*` env fields, the `model_config` settings that aren't
|
|
23
|
+
cosmetic, `custodian_fields()` and `assert_fully_loaded()`.
|
|
24
|
+
- `from_secret()` / `from_config()` field markers, with `name=` for the
|
|
25
|
+
case where a field can't be named after its secret.
|
|
26
|
+
- `CustodianClient` — `start()`, `close()`, `refresh_all()`, and the
|
|
27
|
+
`loaded_from_custodian` and `fetch_mode` properties.
|
|
28
|
+
- Batch fetch as the default path: one `POST .../secrets/values` and one
|
|
29
|
+
`GET .../configs/values` at startup instead of one request per field.
|
|
30
|
+
- `custodian_fetch_mode` (`auto` / `batch` / `per_name`). `auto` falls back
|
|
31
|
+
to per-name fetches, once per process, against a Custodian deployment
|
|
32
|
+
that predates the batch endpoints — so this package can be installed
|
|
33
|
+
before that deployment happens.
|
|
34
|
+
- `custodian_nats_url=""` as a supported degraded mode: no live
|
|
35
|
+
invalidation, logged as a warning at startup.
|
|
36
|
+
- An exception hierarchy under `CustodianError`, so callers can distinguish
|
|
37
|
+
an unreadable secret from a scope problem without parsing messages.
|
|
38
|
+
|
|
39
|
+
### Changed from the example this was extracted from
|
|
40
|
+
|
|
41
|
+
- **A full refresh now reverts fields Custodian no longer answers for.**
|
|
42
|
+
The example only logged them, which left a deleted secret's last value in
|
|
43
|
+
place until the process restarted. Only fields Custodian actually
|
|
44
|
+
supplied are reverted; a field that was always on its env value is left
|
|
45
|
+
alone.
|
|
46
|
+
- **Reverting a required field no longer raises.** Restoring the
|
|
47
|
+
"unset" sentinel through `setattr` fails validation against the field's
|
|
48
|
+
own annotation — so a `secret.deleted` event for a field with no default
|
|
49
|
+
raised a pydantic error from inside the NATS callback. It is now restored
|
|
50
|
+
the same way pydantic itself sets it at construction time, which also
|
|
51
|
+
lets `assert_fully_loaded()` see the hole again.
|
|
52
|
+
- Errors are typed rather than a single `CustodianError`.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: educate-custodian-consumer
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Typed runtime config and secrets for Educate! apps, backed by Custodian
|
|
5
|
+
Project-URL: Repository, https://github.com/experienceeducate/educate-secrets-manager
|
|
6
|
+
Keywords: configuration,fastapi,pydantic,secrets
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Framework :: Pydantic :: 2
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
15
|
+
Requires-Dist: nats-py>=2.7
|
|
16
|
+
Requires-Dist: pydantic-settings>=2.3
|
|
17
|
+
Requires-Dist: pydantic>=2.7
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
22
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
23
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# educate-custodian-consumer
|
|
27
|
+
|
|
28
|
+
Typed runtime config and secrets for Educate! apps, backed by
|
|
29
|
+
[Custodian](https://github.com/experienceeducate/educate-secrets-manager).
|
|
30
|
+
|
|
31
|
+
Declare what your app needs as ordinary typed fields. This package fetches
|
|
32
|
+
them at startup, keeps them current when they change, and gets out of the
|
|
33
|
+
way — application code reads a plain attribute and never knows that one
|
|
34
|
+
value came from a `.env` file and another from an encrypted store over the
|
|
35
|
+
network, or that the second one silently rotated twenty minutes into the
|
|
36
|
+
process's life.
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from typing import Any
|
|
40
|
+
from educate_custodian_consumer import CustodianSettings, from_config, from_secret
|
|
41
|
+
|
|
42
|
+
class Settings(CustodianSettings):
|
|
43
|
+
clerk_secret_key: str = from_secret()
|
|
44
|
+
database_url: str = from_secret("postgresql://localhost:5432/sample_dev")
|
|
45
|
+
max_upload_size_mb: int = from_config(10)
|
|
46
|
+
checkout_rollout: dict[str, Any] = from_config({})
|
|
47
|
+
registration_flow_enabled: bool = from_config(False, name="ENABLE_NEW_REGISTRATION_FLOW")
|
|
48
|
+
|
|
49
|
+
log_level: str = "INFO" # plain env config, read identically
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from contextlib import asynccontextmanager
|
|
54
|
+
from educate_custodian_consumer import CustodianClient
|
|
55
|
+
from fastapi import FastAPI
|
|
56
|
+
|
|
57
|
+
settings = Settings()
|
|
58
|
+
client = CustodianClient(settings)
|
|
59
|
+
|
|
60
|
+
@asynccontextmanager
|
|
61
|
+
async def lifespan(app: FastAPI):
|
|
62
|
+
await client.start() # fetch, assert fully loaded, subscribe
|
|
63
|
+
try:
|
|
64
|
+
yield
|
|
65
|
+
finally:
|
|
66
|
+
await client.close()
|
|
67
|
+
|
|
68
|
+
app = FastAPI(lifespan=lifespan)
|
|
69
|
+
|
|
70
|
+
@app.get("/limits")
|
|
71
|
+
async def limits():
|
|
72
|
+
return {"max_upload_size_mb": settings.max_upload_size_mb} # always current
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
FastAPI is the example, not a dependency: the client is `httpx` + `nats-py`
|
|
76
|
+
+ pydantic, and works the same from a worker or a script.
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install educate-custodian-consumer
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Python 3.12+.
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
Every setting below is read from the environment (or `.env`), and only from
|
|
89
|
+
there. They say *where* to fetch and *with what*, so they can't themselves
|
|
90
|
+
come from Custodian.
|
|
91
|
+
|
|
92
|
+
| Env var | Default | |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `CUSTODIAN_ORG_SLUG` | — | required |
|
|
95
|
+
| `CUSTODIAN_APP_SLUG` | — | required |
|
|
96
|
+
| `CUSTODIAN_ENV_SLUG` | — | required |
|
|
97
|
+
| `CUSTODIAN_API_KEY` | — | required; the `sk_live_...` service-account key |
|
|
98
|
+
| `CUSTODIAN_BASE_URL` | `http://localhost:8080` | |
|
|
99
|
+
| `CUSTODIAN_NATS_URL` | `nats://localhost:4222` | empty disables live updates |
|
|
100
|
+
| `CUSTODIAN_FETCH_MODE` | `auto` | `auto`, `batch` or `per_name` |
|
|
101
|
+
| `CUSTODIAN_TOKEN_REFRESH_MARGIN_SECONDS` | `60` | |
|
|
102
|
+
| `CUSTODIAN_HTTP_TIMEOUT_SECONDS` | `10.0` | |
|
|
103
|
+
|
|
104
|
+
## How values resolve
|
|
105
|
+
|
|
106
|
+
Three layers, each overriding the one before:
|
|
107
|
+
|
|
108
|
+
1. **Field default** — what you get with no configuration anywhere.
|
|
109
|
+
2. **Environment** — `.env` and real env vars, pydantic-settings' normal job.
|
|
110
|
+
3. **Custodian** — fetched at startup, re-fetched on change.
|
|
111
|
+
|
|
112
|
+
**Custodian wins.** Env is the bootstrap and offline-dev layer; Custodian is
|
|
113
|
+
authoritative at runtime.
|
|
114
|
+
|
|
115
|
+
A field marked `from_secret()` / `from_config()` with no default *must* be
|
|
116
|
+
supplied by one of the layers: `start()` raises rather than let the app
|
|
117
|
+
serve traffic half-configured. Give a field a real default and it becomes a
|
|
118
|
+
genuine fallback instead.
|
|
119
|
+
|
|
120
|
+
Names match case-insensitively, so a `clerk_secret_key` field resolves the
|
|
121
|
+
`CLERK_SECRET_KEY` the console shows. Pass `name=` only when a field can't
|
|
122
|
+
be named after its secret at all.
|
|
123
|
+
|
|
124
|
+
## Live updates
|
|
125
|
+
|
|
126
|
+
`start()` subscribes to this app/environment's change events and re-fetches
|
|
127
|
+
the affected field when one arrives — the event says *that* something
|
|
128
|
+
changed, never what it changed to, so the value always comes from the API.
|
|
129
|
+
Rotating a secret in the console updates every running replica within about
|
|
130
|
+
a second, with no restart and no polling.
|
|
131
|
+
|
|
132
|
+
Deleting a value in Custodian reverts the field to whatever env or the field
|
|
133
|
+
default supplied, rather than leaving it stale.
|
|
134
|
+
|
|
135
|
+
Set `CUSTODIAN_NATS_URL=""` to disable this. It's supported, and it's a
|
|
136
|
+
downgrade the package logs loudly: the process then holds the values it
|
|
137
|
+
booted with until it restarts.
|
|
138
|
+
|
|
139
|
+
## `missing` vs. `unreadable`
|
|
140
|
+
|
|
141
|
+
The distinction the client exists to get right. "No value here" means fall
|
|
142
|
+
back to the layer underneath. "A value exists and Custodian could not
|
|
143
|
+
produce it" means **keep what you have and never fall back** — falling back
|
|
144
|
+
asserts that no value exists, and for that name one does.
|
|
145
|
+
|
|
146
|
+
So an unreadable secret fails startup, even when an env fallback would have
|
|
147
|
+
satisfied the field. A runtime refresh does the opposite: it logs the name
|
|
148
|
+
and Custodian's `request_id`, and keeps serving on the value it has.
|
|
149
|
+
|
|
150
|
+
## `fetch_mode`
|
|
151
|
+
|
|
152
|
+
`auto` (the default) fetches everything in two requests where the Custodian
|
|
153
|
+
it's pointed at supports batch endpoints, and falls back to one request per
|
|
154
|
+
field — for the life of the process, logged once — where it doesn't. That
|
|
155
|
+
makes this package installable against a deployment that hasn't taken the
|
|
156
|
+
batch endpoints yet, and it picks up the improvement the day that deployment
|
|
157
|
+
does.
|
|
158
|
+
|
|
159
|
+
`batch` refuses to fall back. `per_name` pins the one-request-per-field
|
|
160
|
+
behavior.
|
|
161
|
+
|
|
162
|
+
## What this package will never do
|
|
163
|
+
|
|
164
|
+
- **No writes.** No create, no rotate, no approvals, no admin surface. The
|
|
165
|
+
`-consumer` in the name is the promise.
|
|
166
|
+
- **No secret value in any log line, `repr`, or exception message.** Errors
|
|
167
|
+
carry the name and scope; `loaded_from_custodian` returns names only, and
|
|
168
|
+
is safe in a health check.
|
|
169
|
+
- **No on-disk cache.** Nothing is written to a file, a temp dir, or a
|
|
170
|
+
`~/.custodian` anything.
|
|
171
|
+
- **No env var read** other than the `CUSTODIAN_*` set above.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
Not yet chosen — see the repository. This package is not published to PyPI
|
|
176
|
+
until it is.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# educate-custodian-consumer
|
|
2
|
+
|
|
3
|
+
Typed runtime config and secrets for Educate! apps, backed by
|
|
4
|
+
[Custodian](https://github.com/experienceeducate/educate-secrets-manager).
|
|
5
|
+
|
|
6
|
+
Declare what your app needs as ordinary typed fields. This package fetches
|
|
7
|
+
them at startup, keeps them current when they change, and gets out of the
|
|
8
|
+
way — application code reads a plain attribute and never knows that one
|
|
9
|
+
value came from a `.env` file and another from an encrypted store over the
|
|
10
|
+
network, or that the second one silently rotated twenty minutes into the
|
|
11
|
+
process's life.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from typing import Any
|
|
15
|
+
from educate_custodian_consumer import CustodianSettings, from_config, from_secret
|
|
16
|
+
|
|
17
|
+
class Settings(CustodianSettings):
|
|
18
|
+
clerk_secret_key: str = from_secret()
|
|
19
|
+
database_url: str = from_secret("postgresql://localhost:5432/sample_dev")
|
|
20
|
+
max_upload_size_mb: int = from_config(10)
|
|
21
|
+
checkout_rollout: dict[str, Any] = from_config({})
|
|
22
|
+
registration_flow_enabled: bool = from_config(False, name="ENABLE_NEW_REGISTRATION_FLOW")
|
|
23
|
+
|
|
24
|
+
log_level: str = "INFO" # plain env config, read identically
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from contextlib import asynccontextmanager
|
|
29
|
+
from educate_custodian_consumer import CustodianClient
|
|
30
|
+
from fastapi import FastAPI
|
|
31
|
+
|
|
32
|
+
settings = Settings()
|
|
33
|
+
client = CustodianClient(settings)
|
|
34
|
+
|
|
35
|
+
@asynccontextmanager
|
|
36
|
+
async def lifespan(app: FastAPI):
|
|
37
|
+
await client.start() # fetch, assert fully loaded, subscribe
|
|
38
|
+
try:
|
|
39
|
+
yield
|
|
40
|
+
finally:
|
|
41
|
+
await client.close()
|
|
42
|
+
|
|
43
|
+
app = FastAPI(lifespan=lifespan)
|
|
44
|
+
|
|
45
|
+
@app.get("/limits")
|
|
46
|
+
async def limits():
|
|
47
|
+
return {"max_upload_size_mb": settings.max_upload_size_mb} # always current
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
FastAPI is the example, not a dependency: the client is `httpx` + `nats-py`
|
|
51
|
+
+ pydantic, and works the same from a worker or a script.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install educate-custodian-consumer
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Python 3.12+.
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
Every setting below is read from the environment (or `.env`), and only from
|
|
64
|
+
there. They say *where* to fetch and *with what*, so they can't themselves
|
|
65
|
+
come from Custodian.
|
|
66
|
+
|
|
67
|
+
| Env var | Default | |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `CUSTODIAN_ORG_SLUG` | — | required |
|
|
70
|
+
| `CUSTODIAN_APP_SLUG` | — | required |
|
|
71
|
+
| `CUSTODIAN_ENV_SLUG` | — | required |
|
|
72
|
+
| `CUSTODIAN_API_KEY` | — | required; the `sk_live_...` service-account key |
|
|
73
|
+
| `CUSTODIAN_BASE_URL` | `http://localhost:8080` | |
|
|
74
|
+
| `CUSTODIAN_NATS_URL` | `nats://localhost:4222` | empty disables live updates |
|
|
75
|
+
| `CUSTODIAN_FETCH_MODE` | `auto` | `auto`, `batch` or `per_name` |
|
|
76
|
+
| `CUSTODIAN_TOKEN_REFRESH_MARGIN_SECONDS` | `60` | |
|
|
77
|
+
| `CUSTODIAN_HTTP_TIMEOUT_SECONDS` | `10.0` | |
|
|
78
|
+
|
|
79
|
+
## How values resolve
|
|
80
|
+
|
|
81
|
+
Three layers, each overriding the one before:
|
|
82
|
+
|
|
83
|
+
1. **Field default** — what you get with no configuration anywhere.
|
|
84
|
+
2. **Environment** — `.env` and real env vars, pydantic-settings' normal job.
|
|
85
|
+
3. **Custodian** — fetched at startup, re-fetched on change.
|
|
86
|
+
|
|
87
|
+
**Custodian wins.** Env is the bootstrap and offline-dev layer; Custodian is
|
|
88
|
+
authoritative at runtime.
|
|
89
|
+
|
|
90
|
+
A field marked `from_secret()` / `from_config()` with no default *must* be
|
|
91
|
+
supplied by one of the layers: `start()` raises rather than let the app
|
|
92
|
+
serve traffic half-configured. Give a field a real default and it becomes a
|
|
93
|
+
genuine fallback instead.
|
|
94
|
+
|
|
95
|
+
Names match case-insensitively, so a `clerk_secret_key` field resolves the
|
|
96
|
+
`CLERK_SECRET_KEY` the console shows. Pass `name=` only when a field can't
|
|
97
|
+
be named after its secret at all.
|
|
98
|
+
|
|
99
|
+
## Live updates
|
|
100
|
+
|
|
101
|
+
`start()` subscribes to this app/environment's change events and re-fetches
|
|
102
|
+
the affected field when one arrives — the event says *that* something
|
|
103
|
+
changed, never what it changed to, so the value always comes from the API.
|
|
104
|
+
Rotating a secret in the console updates every running replica within about
|
|
105
|
+
a second, with no restart and no polling.
|
|
106
|
+
|
|
107
|
+
Deleting a value in Custodian reverts the field to whatever env or the field
|
|
108
|
+
default supplied, rather than leaving it stale.
|
|
109
|
+
|
|
110
|
+
Set `CUSTODIAN_NATS_URL=""` to disable this. It's supported, and it's a
|
|
111
|
+
downgrade the package logs loudly: the process then holds the values it
|
|
112
|
+
booted with until it restarts.
|
|
113
|
+
|
|
114
|
+
## `missing` vs. `unreadable`
|
|
115
|
+
|
|
116
|
+
The distinction the client exists to get right. "No value here" means fall
|
|
117
|
+
back to the layer underneath. "A value exists and Custodian could not
|
|
118
|
+
produce it" means **keep what you have and never fall back** — falling back
|
|
119
|
+
asserts that no value exists, and for that name one does.
|
|
120
|
+
|
|
121
|
+
So an unreadable secret fails startup, even when an env fallback would have
|
|
122
|
+
satisfied the field. A runtime refresh does the opposite: it logs the name
|
|
123
|
+
and Custodian's `request_id`, and keeps serving on the value it has.
|
|
124
|
+
|
|
125
|
+
## `fetch_mode`
|
|
126
|
+
|
|
127
|
+
`auto` (the default) fetches everything in two requests where the Custodian
|
|
128
|
+
it's pointed at supports batch endpoints, and falls back to one request per
|
|
129
|
+
field — for the life of the process, logged once — where it doesn't. That
|
|
130
|
+
makes this package installable against a deployment that hasn't taken the
|
|
131
|
+
batch endpoints yet, and it picks up the improvement the day that deployment
|
|
132
|
+
does.
|
|
133
|
+
|
|
134
|
+
`batch` refuses to fall back. `per_name` pins the one-request-per-field
|
|
135
|
+
behavior.
|
|
136
|
+
|
|
137
|
+
## What this package will never do
|
|
138
|
+
|
|
139
|
+
- **No writes.** No create, no rotate, no approvals, no admin surface. The
|
|
140
|
+
`-consumer` in the name is the promise.
|
|
141
|
+
- **No secret value in any log line, `repr`, or exception message.** Errors
|
|
142
|
+
carry the name and scope; `loaded_from_custodian` returns names only, and
|
|
143
|
+
is safe in a health check.
|
|
144
|
+
- **No on-disk cache.** Nothing is written to a file, a temp dir, or a
|
|
145
|
+
`~/.custodian` anything.
|
|
146
|
+
- **No env var read** other than the `CUSTODIAN_*` set above.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
Not yet chosen — see the repository. This package is not published to PyPI
|
|
151
|
+
until it is.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "educate-custodian-consumer"
|
|
3
|
+
version = "0.1.3"
|
|
4
|
+
description = "Typed runtime config and secrets for Educate! apps, backed by Custodian"
|
|
5
|
+
requires-python = ">=3.12"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
# No `license` yet, and that is deliberate rather than an oversight: the
|
|
8
|
+
# repository has no LICENSE file and picking one is a decision nobody has
|
|
9
|
+
# made (docs/22 §22.12 Q2). It blocks the first upload to PyPI, not the
|
|
10
|
+
# code — everything else in this package works from a local path install.
|
|
11
|
+
keywords = ["secrets", "configuration", "pydantic", "fastapi"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Framework :: Pydantic :: 2",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"httpx>=0.27",
|
|
22
|
+
"pydantic>=2.7",
|
|
23
|
+
"pydantic-settings>=2.3",
|
|
24
|
+
# Base dependency, not an extra: live invalidation is the reason this
|
|
25
|
+
# package exists rather than a .env file, so making it opt-in inverts
|
|
26
|
+
# the default. An app that genuinely can't reach NATS sets
|
|
27
|
+
# `custodian_nats_url=""` and gets a supported degraded mode.
|
|
28
|
+
"nats-py>=2.7",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Repository = "https://github.com/experienceeducate/educate-secrets-manager"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
# Matches the backend's shape (`pip install -e ".[dev]"`), so the package is
|
|
36
|
+
# installable with plain pip in an environment that has no uv.
|
|
37
|
+
dev = [
|
|
38
|
+
"pytest>=8",
|
|
39
|
+
"pytest-asyncio>=0.23",
|
|
40
|
+
"respx>=0.21",
|
|
41
|
+
"ruff>=0.5",
|
|
42
|
+
"mypy>=1.10",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
# hatchling, matching backend/pyproject.toml — one build backend in the repo.
|
|
47
|
+
requires = ["hatchling"]
|
|
48
|
+
build-backend = "hatchling.build"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/educate_custodian_consumer"]
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
line-length = 100
|
|
55
|
+
src = ["src", "tests"]
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
python_version = "3.12"
|
|
62
|
+
strict = true
|
|
63
|
+
files = ["src"]
|
|
64
|
+
|
|
65
|
+
[[tool.mypy.overrides]]
|
|
66
|
+
# nats-py ships no type information.
|
|
67
|
+
module = ["nats.*"]
|
|
68
|
+
ignore_missing_imports = true
|
|
69
|
+
|
|
70
|
+
[tool.pytest.ini_options]
|
|
71
|
+
asyncio_mode = "auto"
|
|
72
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Typed runtime config and secrets for Educate! apps, backed by Custodian.
|
|
2
|
+
|
|
3
|
+
from educate_custodian_consumer import CustodianSettings, from_secret, from_config
|
|
4
|
+
|
|
5
|
+
class Settings(CustodianSettings):
|
|
6
|
+
clerk_secret_key: str = from_secret()
|
|
7
|
+
max_upload_size_mb: int = from_config(10)
|
|
8
|
+
|
|
9
|
+
settings = Settings()
|
|
10
|
+
client = CustodianClient(settings)
|
|
11
|
+
await client.start() # fetch, assert fully loaded, subscribe
|
|
12
|
+
|
|
13
|
+
This package is the **read path only**, and the `-consumer` in its name is a
|
|
14
|
+
promise: no writes, no rotation, no approvals, no admin surface. Those
|
|
15
|
+
belong to the console.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
19
|
+
|
|
20
|
+
from .client import CustodianClient
|
|
21
|
+
from .errors import (
|
|
22
|
+
CustodianAuthError,
|
|
23
|
+
CustodianError,
|
|
24
|
+
CustodianRateLimitError,
|
|
25
|
+
CustodianRequestError,
|
|
26
|
+
CustodianScopeError,
|
|
27
|
+
CustodianSettingsError,
|
|
28
|
+
CustodianUnreadableError,
|
|
29
|
+
)
|
|
30
|
+
from .settings import CustodianField, CustodianSettings, FetchMode, from_config, from_secret
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
# Single-sourced from pyproject.toml, so the version can't drift from
|
|
34
|
+
# the one that was actually built and published.
|
|
35
|
+
__version__ = version("educate-custodian-consumer")
|
|
36
|
+
except PackageNotFoundError: # pragma: no cover - only when run from a source tree
|
|
37
|
+
__version__ = "0.0.0.dev0"
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"CustodianAuthError",
|
|
41
|
+
"CustodianClient",
|
|
42
|
+
"CustodianError",
|
|
43
|
+
"CustodianField",
|
|
44
|
+
"CustodianRateLimitError",
|
|
45
|
+
"CustodianRequestError",
|
|
46
|
+
"CustodianScopeError",
|
|
47
|
+
"CustodianSettings",
|
|
48
|
+
"CustodianSettingsError",
|
|
49
|
+
"CustodianUnreadableError",
|
|
50
|
+
"FetchMode",
|
|
51
|
+
"__version__",
|
|
52
|
+
"from_config",
|
|
53
|
+
"from_secret",
|
|
54
|
+
]
|