nidl-client 0.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.
- nidl_client-0.1.0/LICENSE +43 -0
- nidl_client-0.1.0/LICENSE-APACHE +202 -0
- nidl_client-0.1.0/LICENSE-MIT +21 -0
- nidl_client-0.1.0/PKG-INFO +131 -0
- nidl_client-0.1.0/README.md +115 -0
- nidl_client-0.1.0/pyproject.toml +23 -0
- nidl_client-0.1.0/setup.cfg +4 -0
- nidl_client-0.1.0/src/nidl_client/__init__.py +902 -0
- nidl_client-0.1.0/src/nidl_client/commands.py +78 -0
- nidl_client-0.1.0/src/nidl_client.egg-info/PKG-INFO +131 -0
- nidl_client-0.1.0/src/nidl_client.egg-info/SOURCES.txt +12 -0
- nidl_client-0.1.0/src/nidl_client.egg-info/dependency_links.txt +1 -0
- nidl_client-0.1.0/src/nidl_client.egg-info/top_level.txt +1 -0
- nidl_client-0.1.0/tests/test_client.py +543 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Licence
|
|
2
|
+
|
|
3
|
+
nidl is dual-licensed under either of
|
|
4
|
+
|
|
5
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](./LICENSE-APACHE))
|
|
6
|
+
- MIT License ([LICENSE-MIT](./LICENSE-MIT))
|
|
7
|
+
|
|
8
|
+
at your option. This is the Rust ecosystem's customary dual licence, and it is what the
|
|
9
|
+
great majority of this project's own dependencies already use.
|
|
10
|
+
|
|
11
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for
|
|
12
|
+
inclusion in this work by you, as defined in the Apache-2.0 licence, shall be dual
|
|
13
|
+
licensed as above, without any additional terms or conditions.
|
|
14
|
+
|
|
15
|
+
## Third-party notice
|
|
16
|
+
|
|
17
|
+
This notice is scoped to what each build contains, as
|
|
18
|
+
`.hermes/artifacts/plugin-cli-foundation/F-DEPENDENCY-SECURITY-AUDIT.md` s.2 records it. Its
|
|
19
|
+
obligations are recorded here rather than left to be discovered.
|
|
20
|
+
|
|
21
|
+
**The headless binary** (`nidl-core`, built without default features: what a handed build
|
|
22
|
+
contains) has one dependency under a copyleft licence:
|
|
23
|
+
|
|
24
|
+
**`option-ext`** (MPL-2.0), used unmodified, reached through `dirs` → `dirs-sys`. MPL-2.0 is
|
|
25
|
+
file-level copyleft: the obligation attaches to modifications of MPL-licensed *files*, not
|
|
26
|
+
to the work that links them. nidl modifies none, so what is owed is the notice above and
|
|
27
|
+
availability of that component's source, which is published at its own repository. It
|
|
28
|
+
places no constraint on nidl's own terms.
|
|
29
|
+
|
|
30
|
+
Everything else in the headless binary's dependency graph is permissive. No crate in it is under
|
|
31
|
+
GPL, LGPL or AGPL.
|
|
32
|
+
|
|
33
|
+
**The desktop app** (built with default features, and not distributed today) also contains the
|
|
34
|
+
four MPL-2.0 crates of its webview's CSS stack, each used unmodified, with the same obligation as
|
|
35
|
+
`option-ext`: **`cssparser`**, **`cssparser-macros`**, **`dtoa-short`** and **`selectors`**. No
|
|
36
|
+
crate in it is under GPL, LGPL or AGPL either.
|
|
37
|
+
|
|
38
|
+
**The website** (`@nidl/web`, private, and not distributed) depends on
|
|
39
|
+
**`@img/sharp-libvips-darwin-arm64`** (LGPL-3.0-or-later), a prebuilt image library reached through
|
|
40
|
+
`next` → `sharp`. Publishing the website would make its LGPL obligation live.
|
|
41
|
+
|
|
42
|
+
`tests/licence_notice_test.rs` reads both Rust dependency graphs, and fails when a copyleft crate in
|
|
43
|
+
either is not named here or a crate under GPL, LGPL or AGPL appears.
|
|
@@ -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.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Criss Moldovan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nidl-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Drive a running nidl core from a Python program, over its local socket or its remote port.
|
|
5
|
+
License: MIT OR Apache-2.0
|
|
6
|
+
Project-URL: Source, https://github.com/crissmoldovan/nidl/tree/main/clients/python
|
|
7
|
+
Classifier: Operating System :: MacOS
|
|
8
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: LICENSE-APACHE
|
|
14
|
+
License-File: LICENSE-MIT
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# nidl-client
|
|
18
|
+
|
|
19
|
+
Drive a running [nidl](https://github.com/crissmoldovan/nidl) core from a Python program, over
|
|
20
|
+
its local socket, or over HTTPS to its remote port on another machine.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import nidl_client
|
|
24
|
+
|
|
25
|
+
nidl = nidl_client.connect() # the core serving ~/.nidl; or connect("/path/to/data")
|
|
26
|
+
if nidl.has("targets.list"):
|
|
27
|
+
targets = nidl.command("targets.list")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **It never starts a core.** When none is running, `connect()` raises `NidlError` with code
|
|
31
|
+
`not_running` and says how to start one: `nidl serve --data-dir ~/.nidl`, or open the nidl app.
|
|
32
|
+
- **It checks the socket before trusting it:** each folder on the way is yours or root's and not
|
|
33
|
+
writable by others, the control folder is `0700`, the core's record is a private file describing
|
|
34
|
+
this folder's core, the socket is the one that record names, and the process at the other end
|
|
35
|
+
runs as you (`SO_PEERCRED` on Linux, `LOCAL_PEERCRED` on macOS). A check that fails is
|
|
36
|
+
`unsafe_folder`. Python's standard library cannot read ACLs; the Rust library checks those too.
|
|
37
|
+
- **It is an app, not the owner.** It connects as the `app` client kind: it can read, draft,
|
|
38
|
+
preview and apply, but credential commands, such as connecting an account or unlocking
|
|
39
|
+
credentials, are refused with `requires_owner_action`. Those are yours to run, from the CLI or
|
|
40
|
+
the desktop.
|
|
41
|
+
- **Command names are listed.** `CommandName` is a `Literal` of the commands an app may run,
|
|
42
|
+
generated from the core's registry, and `COMMAND_NAMES` holds them. `command()` is annotated
|
|
43
|
+
with it, so a type checker flags a misspelled or refused name. At run time any string goes to the
|
|
44
|
+
core, so a newer core's command still works. Results are plain JSON.
|
|
45
|
+
- **Each call is one connection:** the folder is checked, the core says hello, the command runs,
|
|
46
|
+
the connection closes.
|
|
47
|
+
|
|
48
|
+
`NidlError` has `code` for programs, `message` for people, and `outcome`: `not_started`, or
|
|
49
|
+
`unknown` when the connection was lost after the command was sent, since it may have run. The
|
|
50
|
+
codes: `not_running`, `unsafe_folder`, `not_offered`, `version_conflict`, `path_too_long`,
|
|
51
|
+
`timeout`, `protocol_error`, or the core's own, such as `not_found` or `requires_owner_action`.
|
|
52
|
+
|
|
53
|
+
## A core on another machine
|
|
54
|
+
|
|
55
|
+
When a machine's owner has turned on nidl's remote port there (`nidl remote enable`) and issued you
|
|
56
|
+
a remote token (`nidl remote-tokens issue`), connect to that core by its URL, `https://HOST:PORT`:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
nidl = nidl_client.connect(
|
|
60
|
+
url="https://nidl.example:8443",
|
|
61
|
+
token=os.environ["NIDL_TOKEN"],
|
|
62
|
+
fingerprint="sha256:...", # as `nidl remote status` shows it on that machine
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- **The certificate is checked before the token is sent.** With a fingerprint, only nidl's own
|
|
67
|
+
certificate with that fingerprint is accepted, as SSH remembers a host's key; the handshake still
|
|
68
|
+
proves the server holds its key. Without one, the certificate must be one the system trusts for the URL's
|
|
69
|
+
host, as when the owner serves a certificate of their own. Anything else fails with
|
|
70
|
+
`untrusted_certificate`, and nothing is sent.
|
|
71
|
+
- **The token's scope decides what runs.** A `read` token lists and reads. An `operate` token also
|
|
72
|
+
drafts targets, refreshes catalogs and readings, and previews and applies routing. Neither runs
|
|
73
|
+
credential commands or starts paid model checks: those stay with the owner at the machine
|
|
74
|
+
(`requires_owner_action`).
|
|
75
|
+
- **`nidl.identity`** has no `root` or `instanceNonce` for a remote core, which does not say what names
|
|
76
|
+
its files; it says the token's `scope`.
|
|
77
|
+
- **Each call is one HTTPS connection** to the remote port, closed after the answer.
|
|
78
|
+
|
|
79
|
+
The remote codes, beside those above: `unauthorized` (the token is unknown, revoked or expired),
|
|
80
|
+
`untrusted_certificate` (the certificate is not the one expected; nothing was sent), `throttled`
|
|
81
|
+
(too many failed attempts from this address; wait a minute), `invalid_input` (the URL, token or
|
|
82
|
+
fingerprint is malformed, or the command is over 1 MiB), `unavailable` (the machine could not be
|
|
83
|
+
reached, or its core is busy or not serving), and `unsupported` (that nidl's remote port takes no
|
|
84
|
+
commands; update it there).
|
|
85
|
+
|
|
86
|
+
## Lending your project's key, and reporting readings
|
|
87
|
+
|
|
88
|
+
Another program can use nidl for its own accounts once the owner has made it a project there
|
|
89
|
+
(`nidl projects create`), with a **borrowed** account for each API key it holds
|
|
90
|
+
(`nidl projects add-account`, mode `borrowed`) and an API target with an app token
|
|
91
|
+
(`nidl targets create`, `nidl app-tokens issue`). Your program lends nidl its key for as long as it
|
|
92
|
+
wants requests to the target's endpoint, `/h/<target>/v1/…`, routed with it, and takes it back:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
lease = nidl.lend(account_id, api_key, app_token=os.environ["NIDL_APP_TOKEN"], expires_in_seconds=3600)
|
|
96
|
+
# ... calls to the target's endpoint route with the key while the lease lives ...
|
|
97
|
+
nidl.withdraw(account_id)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- **The key travels in the socket's secret frame,** never in a command's arguments, so
|
|
101
|
+
`command("pools.lend")` is refused with `invalid_input`. nidl keeps it in memory only, never on
|
|
102
|
+
disk, for 60 seconds to 12 hours (an hour unless you say) and never past the app token. It is
|
|
103
|
+
dropped when the lease expires, when you withdraw it, when the owner revokes the token or removes
|
|
104
|
+
its target, and when the core stops. Lend again to renew it.
|
|
105
|
+
- **The app token proves the account is your project's.** A token of another project's target, a
|
|
106
|
+
revoked or expired one, or none, is refused with `not_authorized`.
|
|
107
|
+
- **On this machine only.** `lend` and `withdraw` on a remote core fail with `unsupported` before
|
|
108
|
+
anything is sent.
|
|
109
|
+
- The lease is `{accountId, lentAt, expiresAt, lentBy}`, `lentBy` being your app token's id. It
|
|
110
|
+
never holds the key.
|
|
111
|
+
|
|
112
|
+
Python cannot wipe the `str` you pass in; the frame's own bytes are overwritten once sent.
|
|
113
|
+
|
|
114
|
+
An **observed** account is one nidl never holds a key for, a subscription for instance, whose quota
|
|
115
|
+
your program reports so the owner sees it beside their own:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
nidl.observe(account_id, [{"key": "five_hour", "percent": 37.5, "resetsAt": "2026-10-21T15:00:00Z"}])
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
At most 16 windows, each a `key`, a `percent` from 0 to 100, and optionally a `label` and a
|
|
122
|
+
`resetsAt`, captured within the last 24 hours (now, unless you say). On a remote core this needs an
|
|
123
|
+
`operate` token bound to your project (`nidl remote-tokens issue` with its `project`).
|
|
124
|
+
|
|
125
|
+
Long-running commands return an operation id: poll it with
|
|
126
|
+
`nidl.command("operations.get", {"operationId": ...})`.
|
|
127
|
+
|
|
128
|
+
The protocol is described in
|
|
129
|
+
[docs/protocol/nidl-core-protocol.md](https://github.com/crissmoldovan/nidl/blob/main/docs/protocol/nidl-core-protocol.md).
|
|
130
|
+
Python 3.9 or later, macOS or Linux, standard library only: the remote port uses `ssl` and
|
|
131
|
+
`http.client`.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# nidl-client
|
|
2
|
+
|
|
3
|
+
Drive a running [nidl](https://github.com/crissmoldovan/nidl) core from a Python program, over
|
|
4
|
+
its local socket, or over HTTPS to its remote port on another machine.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
import nidl_client
|
|
8
|
+
|
|
9
|
+
nidl = nidl_client.connect() # the core serving ~/.nidl; or connect("/path/to/data")
|
|
10
|
+
if nidl.has("targets.list"):
|
|
11
|
+
targets = nidl.command("targets.list")
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- **It never starts a core.** When none is running, `connect()` raises `NidlError` with code
|
|
15
|
+
`not_running` and says how to start one: `nidl serve --data-dir ~/.nidl`, or open the nidl app.
|
|
16
|
+
- **It checks the socket before trusting it:** each folder on the way is yours or root's and not
|
|
17
|
+
writable by others, the control folder is `0700`, the core's record is a private file describing
|
|
18
|
+
this folder's core, the socket is the one that record names, and the process at the other end
|
|
19
|
+
runs as you (`SO_PEERCRED` on Linux, `LOCAL_PEERCRED` on macOS). A check that fails is
|
|
20
|
+
`unsafe_folder`. Python's standard library cannot read ACLs; the Rust library checks those too.
|
|
21
|
+
- **It is an app, not the owner.** It connects as the `app` client kind: it can read, draft,
|
|
22
|
+
preview and apply, but credential commands, such as connecting an account or unlocking
|
|
23
|
+
credentials, are refused with `requires_owner_action`. Those are yours to run, from the CLI or
|
|
24
|
+
the desktop.
|
|
25
|
+
- **Command names are listed.** `CommandName` is a `Literal` of the commands an app may run,
|
|
26
|
+
generated from the core's registry, and `COMMAND_NAMES` holds them. `command()` is annotated
|
|
27
|
+
with it, so a type checker flags a misspelled or refused name. At run time any string goes to the
|
|
28
|
+
core, so a newer core's command still works. Results are plain JSON.
|
|
29
|
+
- **Each call is one connection:** the folder is checked, the core says hello, the command runs,
|
|
30
|
+
the connection closes.
|
|
31
|
+
|
|
32
|
+
`NidlError` has `code` for programs, `message` for people, and `outcome`: `not_started`, or
|
|
33
|
+
`unknown` when the connection was lost after the command was sent, since it may have run. The
|
|
34
|
+
codes: `not_running`, `unsafe_folder`, `not_offered`, `version_conflict`, `path_too_long`,
|
|
35
|
+
`timeout`, `protocol_error`, or the core's own, such as `not_found` or `requires_owner_action`.
|
|
36
|
+
|
|
37
|
+
## A core on another machine
|
|
38
|
+
|
|
39
|
+
When a machine's owner has turned on nidl's remote port there (`nidl remote enable`) and issued you
|
|
40
|
+
a remote token (`nidl remote-tokens issue`), connect to that core by its URL, `https://HOST:PORT`:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
nidl = nidl_client.connect(
|
|
44
|
+
url="https://nidl.example:8443",
|
|
45
|
+
token=os.environ["NIDL_TOKEN"],
|
|
46
|
+
fingerprint="sha256:...", # as `nidl remote status` shows it on that machine
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **The certificate is checked before the token is sent.** With a fingerprint, only nidl's own
|
|
51
|
+
certificate with that fingerprint is accepted, as SSH remembers a host's key; the handshake still
|
|
52
|
+
proves the server holds its key. Without one, the certificate must be one the system trusts for the URL's
|
|
53
|
+
host, as when the owner serves a certificate of their own. Anything else fails with
|
|
54
|
+
`untrusted_certificate`, and nothing is sent.
|
|
55
|
+
- **The token's scope decides what runs.** A `read` token lists and reads. An `operate` token also
|
|
56
|
+
drafts targets, refreshes catalogs and readings, and previews and applies routing. Neither runs
|
|
57
|
+
credential commands or starts paid model checks: those stay with the owner at the machine
|
|
58
|
+
(`requires_owner_action`).
|
|
59
|
+
- **`nidl.identity`** has no `root` or `instanceNonce` for a remote core, which does not say what names
|
|
60
|
+
its files; it says the token's `scope`.
|
|
61
|
+
- **Each call is one HTTPS connection** to the remote port, closed after the answer.
|
|
62
|
+
|
|
63
|
+
The remote codes, beside those above: `unauthorized` (the token is unknown, revoked or expired),
|
|
64
|
+
`untrusted_certificate` (the certificate is not the one expected; nothing was sent), `throttled`
|
|
65
|
+
(too many failed attempts from this address; wait a minute), `invalid_input` (the URL, token or
|
|
66
|
+
fingerprint is malformed, or the command is over 1 MiB), `unavailable` (the machine could not be
|
|
67
|
+
reached, or its core is busy or not serving), and `unsupported` (that nidl's remote port takes no
|
|
68
|
+
commands; update it there).
|
|
69
|
+
|
|
70
|
+
## Lending your project's key, and reporting readings
|
|
71
|
+
|
|
72
|
+
Another program can use nidl for its own accounts once the owner has made it a project there
|
|
73
|
+
(`nidl projects create`), with a **borrowed** account for each API key it holds
|
|
74
|
+
(`nidl projects add-account`, mode `borrowed`) and an API target with an app token
|
|
75
|
+
(`nidl targets create`, `nidl app-tokens issue`). Your program lends nidl its key for as long as it
|
|
76
|
+
wants requests to the target's endpoint, `/h/<target>/v1/…`, routed with it, and takes it back:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
lease = nidl.lend(account_id, api_key, app_token=os.environ["NIDL_APP_TOKEN"], expires_in_seconds=3600)
|
|
80
|
+
# ... calls to the target's endpoint route with the key while the lease lives ...
|
|
81
|
+
nidl.withdraw(account_id)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **The key travels in the socket's secret frame,** never in a command's arguments, so
|
|
85
|
+
`command("pools.lend")` is refused with `invalid_input`. nidl keeps it in memory only, never on
|
|
86
|
+
disk, for 60 seconds to 12 hours (an hour unless you say) and never past the app token. It is
|
|
87
|
+
dropped when the lease expires, when you withdraw it, when the owner revokes the token or removes
|
|
88
|
+
its target, and when the core stops. Lend again to renew it.
|
|
89
|
+
- **The app token proves the account is your project's.** A token of another project's target, a
|
|
90
|
+
revoked or expired one, or none, is refused with `not_authorized`.
|
|
91
|
+
- **On this machine only.** `lend` and `withdraw` on a remote core fail with `unsupported` before
|
|
92
|
+
anything is sent.
|
|
93
|
+
- The lease is `{accountId, lentAt, expiresAt, lentBy}`, `lentBy` being your app token's id. It
|
|
94
|
+
never holds the key.
|
|
95
|
+
|
|
96
|
+
Python cannot wipe the `str` you pass in; the frame's own bytes are overwritten once sent.
|
|
97
|
+
|
|
98
|
+
An **observed** account is one nidl never holds a key for, a subscription for instance, whose quota
|
|
99
|
+
your program reports so the owner sees it beside their own:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
nidl.observe(account_id, [{"key": "five_hour", "percent": 37.5, "resetsAt": "2026-10-21T15:00:00Z"}])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
At most 16 windows, each a `key`, a `percent` from 0 to 100, and optionally a `label` and a
|
|
106
|
+
`resetsAt`, captured within the last 24 hours (now, unless you say). On a remote core this needs an
|
|
107
|
+
`operate` token bound to your project (`nidl remote-tokens issue` with its `project`).
|
|
108
|
+
|
|
109
|
+
Long-running commands return an operation id: poll it with
|
|
110
|
+
`nidl.command("operations.get", {"operationId": ...})`.
|
|
111
|
+
|
|
112
|
+
The protocol is described in
|
|
113
|
+
[docs/protocol/nidl-core-protocol.md](https://github.com/crissmoldovan/nidl/blob/main/docs/protocol/nidl-core-protocol.md).
|
|
114
|
+
Python 3.9 or later, macOS or Linux, standard library only: the remote port uses `ssl` and
|
|
115
|
+
`http.client`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nidl-client"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Drive a running nidl core from a Python program, over its local socket or its remote port."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT OR Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = []
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Operating System :: MacOS",
|
|
15
|
+
"Operating System :: POSIX :: Linux",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Source = "https://github.com/crissmoldovan/nidl/tree/main/clients/python"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.packages.find]
|
|
23
|
+
where = ["src"]
|