nacho-python 0.1.1__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nacho_python-1.1.0/PKG-INFO +174 -0
- nacho_python-1.1.0/README.md +124 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/__init__.py +1 -10
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/_version.py +1 -1
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/cli/main.py +16 -20
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/client.py +57 -44
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/config.py +118 -119
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/env.py +5 -5
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/event.py +31 -33
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/schema.py +14 -8
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/server/__init__.py +1 -1
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/server/app.py +69 -63
- nacho_python-1.1.0/nacho/server/auth.py +137 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/server/models.py +14 -14
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/server/runtime.py +245 -101
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/server/ui/index.html +1162 -228
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/storage/__init__.py +6 -4
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/storage/base.py +8 -7
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/storage/file.py +4 -4
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/storage/remote.py +64 -14
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/utils/io.py +8 -20
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/utils/path.py +8 -7
- nacho_python-1.1.0/nacho_python.egg-info/PKG-INFO +174 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho_python.egg-info/SOURCES.txt +0 -22
- nacho_python-1.1.0/nacho_python.egg-info/requires.txt +38 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/pyproject.toml +33 -24
- nacho_python-0.1.1/PKG-INFO +0 -859
- nacho_python-0.1.1/README.md +0 -812
- nacho_python-0.1.1/nacho/server/auth.py +0 -183
- nacho_python-0.1.1/nacho_python.egg-info/PKG-INFO +0 -859
- nacho_python-0.1.1/nacho_python.egg-info/requires.txt +0 -35
- {nacho_python-0.1.1 → nacho_python-1.1.0}/LICENSE +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/MANIFEST.in +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/cli/__init__.py +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho/utils/__init__.py +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho_python.egg-info/dependency_links.txt +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho_python.egg-info/entry_points.txt +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/nacho_python.egg-info/top_level.txt +0 -0
- {nacho_python-0.1.1 → nacho_python-1.1.0}/setup.cfg +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nacho-python
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Nacho - Lightweight, schema-first dynamic configuration service
|
|
5
|
+
Author-email: "Nya Foundation Team (k3scat)" <k3scat@github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nya-foundation/nacho
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/nya-foundation/nacho/issues
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
19
|
+
Requires-Dist: tomli-w>=1.1.0
|
|
20
|
+
Provides-Extra: server
|
|
21
|
+
Requires-Dist: fastapi>=0.115.0; extra == "server"
|
|
22
|
+
Requires-Dist: pydantic>=2.9.0; extra == "server"
|
|
23
|
+
Requires-Dist: uvicorn>=0.32.0; extra == "server"
|
|
24
|
+
Requires-Dist: websockets>=13.0; extra == "server"
|
|
25
|
+
Provides-Extra: remote
|
|
26
|
+
Requires-Dist: requests>=2.32.0; extra == "remote"
|
|
27
|
+
Requires-Dist: websocket-client>=1.8.0; extra == "remote"
|
|
28
|
+
Provides-Extra: schema
|
|
29
|
+
Requires-Dist: jsonschema>=4.23.0; extra == "schema"
|
|
30
|
+
Requires-Dist: rfc3986-validator>=0.1.1; extra == "schema"
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: nacho-python[remote,schema,server]; extra == "all"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=8.3.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
|
|
37
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
38
|
+
Requires-Dist: httpx2>=2.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: nacho-python[all]; extra == "dev"
|
|
40
|
+
Provides-Extra: lint
|
|
41
|
+
Requires-Dist: ruff>=0.15.0; extra == "lint"
|
|
42
|
+
Requires-Dist: mypy>=1.14.0; extra == "lint"
|
|
43
|
+
Requires-Dist: types-pyyaml; extra == "lint"
|
|
44
|
+
Requires-Dist: types-requests; extra == "lint"
|
|
45
|
+
Requires-Dist: types-jsonschema; extra == "lint"
|
|
46
|
+
Provides-Extra: uitest
|
|
47
|
+
Requires-Dist: playwright>=1.45; extra == "uitest"
|
|
48
|
+
Requires-Dist: pytest-playwright>=0.5.0; extra == "uitest"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
<div align="center">
|
|
52
|
+
|
|
53
|
+
<picture>
|
|
54
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-dark.svg">
|
|
55
|
+
<img src="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-light.svg" alt="Nacho" width="300">
|
|
56
|
+
</picture>
|
|
57
|
+
|
|
58
|
+
**Dynamic configuration for Python.**<br>
|
|
59
|
+
A library for local files, and a server when changes need to reach running services.
|
|
60
|
+
|
|
61
|
+
[English](https://github.com/Nya-Foundation/nacho/blob/main/README.md) ·
|
|
62
|
+
[中文](https://github.com/Nya-Foundation/nacho/blob/main/README_zh.md) ·
|
|
63
|
+
[日本語](https://github.com/Nya-Foundation/nacho/blob/main/README_ja.md)
|
|
64
|
+
|
|
65
|
+
[](https://pypi.org/project/nacho-python/)
|
|
66
|
+
[](https://pypi.org/project/nacho-python/)
|
|
67
|
+
[](https://codecov.io/gh/nya-foundation/nacho)
|
|
68
|
+
[](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
69
|
+
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
Nacho treats configuration as validated, versioned data. Use it as a library
|
|
73
|
+
against a local file, or run its server so that every connected service
|
|
74
|
+
receives a change the moment it is made, with no redeploy and no restart.
|
|
75
|
+
|
|
76
|
+
- **Validated.** Every write is checked against a JSON Schema, and optionally
|
|
77
|
+
your own rules, before it is stored.
|
|
78
|
+
- **Live.** Services subscribe over WebSocket and react through event handlers.
|
|
79
|
+
- **Versioned.** Every revision is kept and can be inspected, compared, and
|
|
80
|
+
restored.
|
|
81
|
+
- **Safe under concurrency.** Revision-checked writes turn lost updates into
|
|
82
|
+
explicit conflicts.
|
|
83
|
+
- **Format-agnostic.** JSON, YAML, and TOML are interchangeable in files, API
|
|
84
|
+
payloads, and the editor.
|
|
85
|
+
- **Self-contained.** The server ships a REST API, a CLI, and a single-file
|
|
86
|
+
web UI with no build step.
|
|
87
|
+
|
|
88
|
+
## Install
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install nacho-python # library: local files and in-memory configs
|
|
92
|
+
pip install "nacho-python[schema]" # + JSON Schema validation
|
|
93
|
+
pip install "nacho-python[server]" # + configuration server and web UI
|
|
94
|
+
pip install "nacho-python[remote]" # + client for a configuration server
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Requires Python 3.11 or later. A container image is published as
|
|
98
|
+
`k3scat/nacho` and `ghcr.io/nya-foundation/nacho`.
|
|
99
|
+
|
|
100
|
+
## Use it as a library
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from nacho import Nacho
|
|
104
|
+
|
|
105
|
+
config = Nacho("config.yaml", schema="schema.json", events=True)
|
|
106
|
+
|
|
107
|
+
port = config.get_int("server.port", default=8000)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@config.on_change("features.*")
|
|
111
|
+
def on_flag_change(path, new_value, **_):
|
|
112
|
+
print(f"{path} is now {new_value}")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
config.set("features.beta", True) # validated, then on_flag_change fires
|
|
116
|
+
config.save()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Run a server
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
nacho server --config config.yaml --schema schema.json --api-key "$NACHO_KEY"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The server listens on `http://127.0.0.1:8000` and serves the REST API, the
|
|
126
|
+
web UI at `/ui`, and interactive API documentation at `/docs`.
|
|
127
|
+
|
|
128
|
+
## Connect a service
|
|
129
|
+
|
|
130
|
+
Swap the file for a `RemoteStorageBackend`. The rest of the code stays the
|
|
131
|
+
same, and handlers now fire when anyone changes the configuration on the
|
|
132
|
+
server.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from nacho import Nacho, RemoteStorageBackend
|
|
136
|
+
|
|
137
|
+
config = Nacho(
|
|
138
|
+
storage=RemoteStorageBackend(
|
|
139
|
+
url="http://127.0.0.1:8000",
|
|
140
|
+
app_name="my-service",
|
|
141
|
+
api_key="...",
|
|
142
|
+
watch=True,
|
|
143
|
+
),
|
|
144
|
+
events=True,
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Documentation
|
|
149
|
+
|
|
150
|
+
| Guide | Covers |
|
|
151
|
+
|---|---|
|
|
152
|
+
| [Library](https://github.com/Nya-Foundation/nacho/blob/main/docs/library.md) | Reading and writing, transactions, validation, events, environment overrides |
|
|
153
|
+
| [Remote client](https://github.com/Nya-Foundation/nacho/blob/main/docs/remote-client.md) | Connecting a service to a server, conflicts, reconnection |
|
|
154
|
+
| [Server](https://github.com/Nya-Foundation/nacho/blob/main/docs/server.md) | Running and embedding the server, the web UI, authentication, Docker |
|
|
155
|
+
| [REST API](https://github.com/Nya-Foundation/nacho/blob/main/docs/rest-api.md) | Endpoints, payloads, revisions, history, the WebSocket stream |
|
|
156
|
+
| [CLI](https://github.com/Nya-Foundation/nacho/blob/main/docs/cli.md) | Every `nacho` command and its exit codes |
|
|
157
|
+
|
|
158
|
+
## Project status
|
|
159
|
+
|
|
160
|
+
Nacho is feature-complete and in maintenance mode. It receives bug fixes,
|
|
161
|
+
security fixes, and dependency updates; new features are not planned. The
|
|
162
|
+
public API (the `Nacho` class, the storage backends, the REST API, and the
|
|
163
|
+
CLI) is stable under semantic versioning.
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
See [CONTRIBUTING.md](https://github.com/Nya-Foundation/nacho/blob/main/CONTRIBUTING.md).
|
|
168
|
+
Questions and bug reports go to the
|
|
169
|
+
[issue tracker](https://github.com/Nya-Foundation/nacho/issues) or the
|
|
170
|
+
[Nya Foundation Discord](https://discord.gg/jXAxVPSs7K).
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
[MIT](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-dark.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/Nya-Foundation/nacho/main/assets/brand/logo-horizontal-light.svg" alt="Nacho" width="300">
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+
**Dynamic configuration for Python.**<br>
|
|
9
|
+
A library for local files, and a server when changes need to reach running services.
|
|
10
|
+
|
|
11
|
+
[English](https://github.com/Nya-Foundation/nacho/blob/main/README.md) ·
|
|
12
|
+
[中文](https://github.com/Nya-Foundation/nacho/blob/main/README_zh.md) ·
|
|
13
|
+
[日本語](https://github.com/Nya-Foundation/nacho/blob/main/README_ja.md)
|
|
14
|
+
|
|
15
|
+
[](https://pypi.org/project/nacho-python/)
|
|
16
|
+
[](https://pypi.org/project/nacho-python/)
|
|
17
|
+
[](https://codecov.io/gh/nya-foundation/nacho)
|
|
18
|
+
[](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
Nacho treats configuration as validated, versioned data. Use it as a library
|
|
23
|
+
against a local file, or run its server so that every connected service
|
|
24
|
+
receives a change the moment it is made, with no redeploy and no restart.
|
|
25
|
+
|
|
26
|
+
- **Validated.** Every write is checked against a JSON Schema, and optionally
|
|
27
|
+
your own rules, before it is stored.
|
|
28
|
+
- **Live.** Services subscribe over WebSocket and react through event handlers.
|
|
29
|
+
- **Versioned.** Every revision is kept and can be inspected, compared, and
|
|
30
|
+
restored.
|
|
31
|
+
- **Safe under concurrency.** Revision-checked writes turn lost updates into
|
|
32
|
+
explicit conflicts.
|
|
33
|
+
- **Format-agnostic.** JSON, YAML, and TOML are interchangeable in files, API
|
|
34
|
+
payloads, and the editor.
|
|
35
|
+
- **Self-contained.** The server ships a REST API, a CLI, and a single-file
|
|
36
|
+
web UI with no build step.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install nacho-python # library: local files and in-memory configs
|
|
42
|
+
pip install "nacho-python[schema]" # + JSON Schema validation
|
|
43
|
+
pip install "nacho-python[server]" # + configuration server and web UI
|
|
44
|
+
pip install "nacho-python[remote]" # + client for a configuration server
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Python 3.11 or later. A container image is published as
|
|
48
|
+
`k3scat/nacho` and `ghcr.io/nya-foundation/nacho`.
|
|
49
|
+
|
|
50
|
+
## Use it as a library
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from nacho import Nacho
|
|
54
|
+
|
|
55
|
+
config = Nacho("config.yaml", schema="schema.json", events=True)
|
|
56
|
+
|
|
57
|
+
port = config.get_int("server.port", default=8000)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@config.on_change("features.*")
|
|
61
|
+
def on_flag_change(path, new_value, **_):
|
|
62
|
+
print(f"{path} is now {new_value}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
config.set("features.beta", True) # validated, then on_flag_change fires
|
|
66
|
+
config.save()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Run a server
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
nacho server --config config.yaml --schema schema.json --api-key "$NACHO_KEY"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The server listens on `http://127.0.0.1:8000` and serves the REST API, the
|
|
76
|
+
web UI at `/ui`, and interactive API documentation at `/docs`.
|
|
77
|
+
|
|
78
|
+
## Connect a service
|
|
79
|
+
|
|
80
|
+
Swap the file for a `RemoteStorageBackend`. The rest of the code stays the
|
|
81
|
+
same, and handlers now fire when anyone changes the configuration on the
|
|
82
|
+
server.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from nacho import Nacho, RemoteStorageBackend
|
|
86
|
+
|
|
87
|
+
config = Nacho(
|
|
88
|
+
storage=RemoteStorageBackend(
|
|
89
|
+
url="http://127.0.0.1:8000",
|
|
90
|
+
app_name="my-service",
|
|
91
|
+
api_key="...",
|
|
92
|
+
watch=True,
|
|
93
|
+
),
|
|
94
|
+
events=True,
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
| Guide | Covers |
|
|
101
|
+
|---|---|
|
|
102
|
+
| [Library](https://github.com/Nya-Foundation/nacho/blob/main/docs/library.md) | Reading and writing, transactions, validation, events, environment overrides |
|
|
103
|
+
| [Remote client](https://github.com/Nya-Foundation/nacho/blob/main/docs/remote-client.md) | Connecting a service to a server, conflicts, reconnection |
|
|
104
|
+
| [Server](https://github.com/Nya-Foundation/nacho/blob/main/docs/server.md) | Running and embedding the server, the web UI, authentication, Docker |
|
|
105
|
+
| [REST API](https://github.com/Nya-Foundation/nacho/blob/main/docs/rest-api.md) | Endpoints, payloads, revisions, history, the WebSocket stream |
|
|
106
|
+
| [CLI](https://github.com/Nya-Foundation/nacho/blob/main/docs/cli.md) | Every `nacho` command and its exit codes |
|
|
107
|
+
|
|
108
|
+
## Project status
|
|
109
|
+
|
|
110
|
+
Nacho is feature-complete and in maintenance mode. It receives bug fixes,
|
|
111
|
+
security fixes, and dependency updates; new features are not planned. The
|
|
112
|
+
public API (the `Nacho` class, the storage backends, the REST API, and the
|
|
113
|
+
CLI) is stable under semantic versioning.
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
See [CONTRIBUTING.md](https://github.com/Nya-Foundation/nacho/blob/main/CONTRIBUTING.md).
|
|
118
|
+
Questions and bug reports go to the
|
|
119
|
+
[issue tracker](https://github.com/Nya-Foundation/nacho/issues) or the
|
|
120
|
+
[Nya Foundation Discord](https://discord.gg/jXAxVPSs7K).
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
[MIT](https://github.com/Nya-Foundation/nacho/blob/main/LICENSE)
|
|
@@ -4,6 +4,7 @@ from ._version import __version__
|
|
|
4
4
|
from .config import Nacho
|
|
5
5
|
from .event import EventType
|
|
6
6
|
from .schema import HAS_SCHEMA_DEPS, ValidationError
|
|
7
|
+
from .server import HAS_SERVER_DEPS, NachoOrchestrator
|
|
7
8
|
from .storage import (
|
|
8
9
|
HAS_REMOTE_DEPS,
|
|
9
10
|
AuthError,
|
|
@@ -16,13 +17,6 @@ from .storage import (
|
|
|
16
17
|
StorageError,
|
|
17
18
|
)
|
|
18
19
|
|
|
19
|
-
try:
|
|
20
|
-
from .server.app import NachoOrchestrator
|
|
21
|
-
|
|
22
|
-
HAS_SERVER_DEPS = True
|
|
23
|
-
except ImportError: # pragma: no cover - optional 'server' extra not installed
|
|
24
|
-
HAS_SERVER_DEPS = False
|
|
25
|
-
|
|
26
20
|
__all__ = [
|
|
27
21
|
"__version__",
|
|
28
22
|
"Nacho",
|
|
@@ -41,6 +35,3 @@ __all__ = [
|
|
|
41
35
|
"HAS_REMOTE_DEPS",
|
|
42
36
|
"HAS_SERVER_DEPS",
|
|
43
37
|
]
|
|
44
|
-
if not HAS_SERVER_DEPS:
|
|
45
|
-
# Keep __all__ truthful so `from nacho import *` never hits an undefined name.
|
|
46
|
-
__all__.remove("NachoOrchestrator")
|
|
@@ -8,8 +8,9 @@ import ipaddress
|
|
|
8
8
|
import json
|
|
9
9
|
import logging
|
|
10
10
|
import sys
|
|
11
|
+
from collections.abc import Callable
|
|
11
12
|
from pathlib import Path
|
|
12
|
-
from typing import TYPE_CHECKING, Any
|
|
13
|
+
from typing import TYPE_CHECKING, Any
|
|
13
14
|
|
|
14
15
|
from nacho import HAS_REMOTE_DEPS, HAS_SCHEMA_DEPS, HAS_SERVER_DEPS
|
|
15
16
|
from nacho._version import __version__
|
|
@@ -26,11 +27,9 @@ if TYPE_CHECKING: # pragma: no cover - typing only
|
|
|
26
27
|
|
|
27
28
|
LOGGER = logging.getLogger("nacho.cli")
|
|
28
29
|
|
|
29
|
-
# Exit codes
|
|
30
|
-
# are produced by the @cli_command wrapper from the typed client errors.
|
|
30
|
+
# Exit codes produced by the @cli_command wrapper from typed client errors.
|
|
31
31
|
EXIT_OK = 0
|
|
32
32
|
EXIT_ERROR = 1
|
|
33
|
-
EXIT_USAGE = 2
|
|
34
33
|
EXIT_NOT_FOUND = 3
|
|
35
34
|
EXIT_CONFLICT = 4
|
|
36
35
|
EXIT_AUTH = 5
|
|
@@ -49,7 +48,7 @@ def banner() -> str:
|
|
|
49
48
|
return f"{BANNER} Lightweight, self-hosted dynamic configuration · v{__version__}\n"
|
|
50
49
|
|
|
51
50
|
|
|
52
|
-
BUILT_IN_TEMPLATES = {
|
|
51
|
+
BUILT_IN_TEMPLATES: dict[str, dict[str, Any]] = {
|
|
53
52
|
"empty": {},
|
|
54
53
|
"web-app": {
|
|
55
54
|
"app": {"name": "web-app", "version": "1.0.0", "port": 3000},
|
|
@@ -110,21 +109,21 @@ def require_remote_deps() -> None:
|
|
|
110
109
|
raise ImportError("Remote features require: pip install nacho-python[remote]")
|
|
111
110
|
|
|
112
111
|
|
|
113
|
-
def build_client(args: argparse.Namespace, app_name:
|
|
112
|
+
def build_client(args: argparse.Namespace, app_name: str | None = None) -> "NachoClient":
|
|
114
113
|
"""Build the one NachoClient a command uses from --remote/--app-name/--api-key."""
|
|
115
114
|
require_remote_deps()
|
|
116
115
|
from nacho.client import NachoClient
|
|
117
116
|
|
|
118
117
|
return NachoClient(
|
|
119
118
|
args.remote,
|
|
120
|
-
app_name=app_name or getattr(args, "app_name", "default"
|
|
119
|
+
app_name=app_name or getattr(args, "app_name", None) or "default",
|
|
121
120
|
api_key=args.api_key,
|
|
122
121
|
)
|
|
123
122
|
|
|
124
123
|
|
|
125
124
|
def create_config(
|
|
126
|
-
config_path:
|
|
127
|
-
schema:
|
|
125
|
+
config_path: str | None = None,
|
|
126
|
+
schema: str | None = None,
|
|
128
127
|
read_only: bool = False,
|
|
129
128
|
) -> Nacho:
|
|
130
129
|
"""Create a Nacho instance for a local config file."""
|
|
@@ -245,10 +244,6 @@ def create_parser() -> argparse.ArgumentParser:
|
|
|
245
244
|
server.add_argument("--schema", help="Schema file path")
|
|
246
245
|
server.add_argument("--data-dir", help="Directory for API-created app state")
|
|
247
246
|
server.add_argument("--api-key", help="API key for authentication")
|
|
248
|
-
server.add_argument(
|
|
249
|
-
"--read-only-api-key",
|
|
250
|
-
help="Additional API key granting read access only (GETs and WebSocket watch)",
|
|
251
|
-
)
|
|
252
247
|
server.add_argument("--app-name", help="Application name for config server")
|
|
253
248
|
server.add_argument(
|
|
254
249
|
"--history-limit",
|
|
@@ -256,7 +251,11 @@ def create_parser() -> argparse.ArgumentParser:
|
|
|
256
251
|
default=50,
|
|
257
252
|
help="Revision snapshots to keep per app for rollback (0 disables history)",
|
|
258
253
|
)
|
|
259
|
-
server.add_argument(
|
|
254
|
+
server.add_argument(
|
|
255
|
+
"--read-only",
|
|
256
|
+
action="store_true",
|
|
257
|
+
help="Serve reads only — every write is refused, whoever the caller is",
|
|
258
|
+
)
|
|
260
259
|
server.add_argument("--reload", action="store_true", help="Auto-reload for development")
|
|
261
260
|
server.set_defaults(func=cmd_server)
|
|
262
261
|
|
|
@@ -443,9 +442,7 @@ def cmd_server(args: argparse.Namespace) -> int:
|
|
|
443
442
|
|
|
444
443
|
print(banner())
|
|
445
444
|
|
|
446
|
-
|
|
447
|
-
# exposure warning only applies when NO key protects the server.
|
|
448
|
-
if not args.api_key and not args.read_only_api_key and not is_loopback_host(args.host):
|
|
445
|
+
if not args.api_key and not is_loopback_host(args.host):
|
|
449
446
|
print(
|
|
450
447
|
"WARNING: serving on a non-loopback interface without --api-key — "
|
|
451
448
|
"anyone who can reach this host has full write access.",
|
|
@@ -460,7 +457,6 @@ def cmd_server(args: argparse.Namespace) -> int:
|
|
|
460
457
|
orchestrator = NachoOrchestrator(
|
|
461
458
|
apps=apps,
|
|
462
459
|
api_key=args.api_key,
|
|
463
|
-
read_only_api_key=args.read_only_api_key,
|
|
464
460
|
read_only=args.read_only,
|
|
465
461
|
data_dir=args.data_dir,
|
|
466
462
|
history_limit=args.history_limit,
|
|
@@ -675,7 +671,7 @@ def cmd_history_diff(args: argparse.Namespace) -> int:
|
|
|
675
671
|
schema_b = client.get_schema()
|
|
676
672
|
label_b = f"current (revision {revision})"
|
|
677
673
|
|
|
678
|
-
def as_lines(config: dict) ->
|
|
674
|
+
def as_lines(config: dict) -> list[str]:
|
|
679
675
|
return json.dumps(config, indent=2, sort_keys=True, ensure_ascii=False).splitlines()
|
|
680
676
|
|
|
681
677
|
diff = list(
|
|
@@ -734,7 +730,7 @@ def cmd_watch(args: argparse.Namespace) -> int:
|
|
|
734
730
|
# ---------------------------------------------------------------------------
|
|
735
731
|
# Entry point
|
|
736
732
|
# ---------------------------------------------------------------------------
|
|
737
|
-
def main_cli(argv:
|
|
733
|
+
def main_cli(argv: list[str] | None = None) -> int:
|
|
738
734
|
"""Main CLI entry point."""
|
|
739
735
|
parser = create_parser()
|
|
740
736
|
args = parser.parse_args(argv)
|