netbox-super-cli 1.0.0__py3-none-any.whl
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.
- netbox_super_cli-1.0.0.dist-info/METADATA +182 -0
- netbox_super_cli-1.0.0.dist-info/RECORD +71 -0
- netbox_super_cli-1.0.0.dist-info/WHEEL +4 -0
- netbox_super_cli-1.0.0.dist-info/entry_points.txt +3 -0
- netbox_super_cli-1.0.0.dist-info/licenses/LICENSE +201 -0
- nsc/__init__.py +5 -0
- nsc/__main__.py +6 -0
- nsc/_version.py +3 -0
- nsc/aliases/__init__.py +24 -0
- nsc/aliases/resolver.py +112 -0
- nsc/auth/__init__.py +5 -0
- nsc/auth/verify.py +143 -0
- nsc/builder/__init__.py +5 -0
- nsc/builder/build.py +514 -0
- nsc/cache/__init__.py +5 -0
- nsc/cache/store.py +295 -0
- nsc/cli/__init__.py +1 -0
- nsc/cli/aliases_commands.py +264 -0
- nsc/cli/app.py +291 -0
- nsc/cli/cache_commands.py +159 -0
- nsc/cli/commands_dump.py +57 -0
- nsc/cli/config_commands.py +156 -0
- nsc/cli/globals.py +65 -0
- nsc/cli/handlers.py +660 -0
- nsc/cli/init_commands.py +95 -0
- nsc/cli/login_commands.py +265 -0
- nsc/cli/profiles_commands.py +256 -0
- nsc/cli/registration.py +465 -0
- nsc/cli/runtime.py +290 -0
- nsc/cli/skill_commands.py +186 -0
- nsc/cli/writes/__init__.py +10 -0
- nsc/cli/writes/apply.py +177 -0
- nsc/cli/writes/bulk.py +231 -0
- nsc/cli/writes/coercion.py +9 -0
- nsc/cli/writes/confirmation.py +96 -0
- nsc/cli/writes/input.py +358 -0
- nsc/cli/writes/preflight.py +182 -0
- nsc/config/__init__.py +23 -0
- nsc/config/loader.py +69 -0
- nsc/config/models.py +54 -0
- nsc/config/settings.py +36 -0
- nsc/config/writer.py +207 -0
- nsc/http/__init__.py +6 -0
- nsc/http/audit.py +183 -0
- nsc/http/client.py +365 -0
- nsc/http/errors.py +35 -0
- nsc/http/retry.py +90 -0
- nsc/model/__init__.py +23 -0
- nsc/model/command_model.py +125 -0
- nsc/output/__init__.py +1 -0
- nsc/output/csv_.py +34 -0
- nsc/output/errors.py +346 -0
- nsc/output/explain.py +194 -0
- nsc/output/flatten.py +25 -0
- nsc/output/headers.py +9 -0
- nsc/output/json_.py +21 -0
- nsc/output/jsonl.py +21 -0
- nsc/output/render.py +47 -0
- nsc/output/table.py +50 -0
- nsc/output/yaml_.py +28 -0
- nsc/schema/__init__.py +1 -0
- nsc/schema/hashing.py +24 -0
- nsc/schema/loader.py +66 -0
- nsc/schema/models.py +109 -0
- nsc/schema/source.py +120 -0
- nsc/schemas/__init__.py +1 -0
- nsc/schemas/bundled/__init__.py +1 -0
- nsc/schemas/bundled/manifest.yaml +5 -0
- nsc/schemas/bundled/netbox-4.6.0-beta2.json.gz +0 -0
- nsc/skill/__init__.py +35 -0
- skills/netbox-super-cli/SKILL.md +127 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netbox-super-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Dynamic NetBox CLI generated from the live OpenAPI schema.
|
|
5
|
+
Project-URL: Homepage, https://github.com/thomaschristory/netbox-super-cli
|
|
6
|
+
Project-URL: Issues, https://github.com/thomaschristory/netbox-super-cli/issues
|
|
7
|
+
Author-email: Thomas <mick27@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: automation,cli,netbox,openapi
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: System :: Networking
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Requires-Dist: httpx>=0.27
|
|
20
|
+
Requires-Dist: platformdirs>=4.2
|
|
21
|
+
Requires-Dist: pydantic>=2.7
|
|
22
|
+
Requires-Dist: rich>=13.7
|
|
23
|
+
Requires-Dist: ruamel-yaml>=0.18
|
|
24
|
+
Requires-Dist: structlog>=24.1
|
|
25
|
+
Requires-Dist: typer>=0.12
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# netbox-super-cli (`nsc`)
|
|
29
|
+
|
|
30
|
+
A Python CLI for [NetBox](https://netbox.dev/) that builds its command tree dynamically from your install's live OpenAPI schema. The same binary works against any NetBox version and exposes plugin-provided endpoints automatically — the schema, not hand-written code, defines the surface.
|
|
31
|
+
|
|
32
|
+
> **Docs:** [thomaschristory.github.io/netbox-super-cli](https://thomaschristory.github.io/netbox-super-cli/) — the full guide, including install, first-run, guides, and the auto-generated CLI/config/exit-code reference.
|
|
33
|
+
|
|
34
|
+
> **Status:** Phase 3 complete (`v0.3.0-phase3`). The full read + safe-write surface is shipped: dynamic command tree, dry-run-by-default writes with `--apply` to commit, `--explain` for resolved-request introspection, bulk-endpoint detection with loop fallback, stable error envelopes with locked exit codes, append-only audit log, and a live-NetBox e2e suite running in CI against `netboxcommunity/netbox:v4.5.9`. Not yet on PyPI.
|
|
35
|
+
|
|
36
|
+
## Why
|
|
37
|
+
|
|
38
|
+
- **Plugins just work.** If your install has plugins, their endpoints appear as commands automatically.
|
|
39
|
+
- **Multi-instance.** Named profiles per NetBox instance, plus env-var overrides.
|
|
40
|
+
- **Safe by default.** POST/PATCH/PUT/DELETE preview as dry-runs unless you pass `--apply`.
|
|
41
|
+
- **Agent-friendly.** Deterministic command shape, machine-readable JSON output, stable error envelope with documented exit codes.
|
|
42
|
+
|
|
43
|
+
## Install (preview)
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
uv tool install netbox-super-cli
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Not on PyPI yet; install from source:
|
|
50
|
+
```
|
|
51
|
+
git clone https://github.com/thomaschristory/netbox-super-cli
|
|
52
|
+
cd netbox-super-cli
|
|
53
|
+
uv sync
|
|
54
|
+
uv run nsc --version
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Reading
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
export NSC_URL=https://netbox.example.com
|
|
61
|
+
export NSC_TOKEN=$(cat ~/.netbox-token)
|
|
62
|
+
|
|
63
|
+
uv run nsc dcim devices list
|
|
64
|
+
uv run nsc dcim devices list --site-id 42 --status active --all --output json
|
|
65
|
+
uv run nsc dcim devices get 7
|
|
66
|
+
uv run nsc circuits providers list --output csv
|
|
67
|
+
uv run nsc ipam prefixes list --filter created__gte=2026-01-01 --output yaml
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Writing
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
# Dry-run by default — shows the resolved request without sending it.
|
|
74
|
+
uv run nsc dcim devices create -f device.yaml --explain
|
|
75
|
+
|
|
76
|
+
# Commit with --apply.
|
|
77
|
+
uv run nsc dcim devices create -f device.yaml --apply
|
|
78
|
+
|
|
79
|
+
# Bulk create: one HTTP call when the schema supports it, sequential loop otherwise.
|
|
80
|
+
uv run nsc dcim devices create -f devices.yaml --apply
|
|
81
|
+
uv run nsc dcim devices create -f devices.yaml --no-bulk --on-error continue --apply
|
|
82
|
+
|
|
83
|
+
# NDJSON / JSONL — one record per line; parse failures abort the whole batch
|
|
84
|
+
# before any wire request fires (`type: input_error`, exit 4, `details.bad_lines`).
|
|
85
|
+
uv run nsc dcim devices create -f devices.ndjson --apply
|
|
86
|
+
cat devices.ndjson | uv run nsc dcim devices create -f - --apply
|
|
87
|
+
|
|
88
|
+
# Per-field overrides (CLI wins over file on overlap).
|
|
89
|
+
uv run nsc dcim devices update 42 --field status=active --apply
|
|
90
|
+
|
|
91
|
+
# Delete; default is exit-0 if already gone, --strict turns missing-id into exit 9.
|
|
92
|
+
uv run nsc dcim devices delete 42 --apply
|
|
93
|
+
uv run nsc dcim devices delete 42 --apply --strict
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Every write attempt — dry-run included — appends one line to `~/.nsc/logs/audit.jsonl`; the most recent exchange is also mirrored to `~/.nsc/logs/last-request.json`.
|
|
97
|
+
|
|
98
|
+
### Bulk input formats
|
|
99
|
+
|
|
100
|
+
| Form | File extension or stdin shape | Routing |
|
|
101
|
+
|------|-------------------------------|---------|
|
|
102
|
+
| YAML mapping | `.yaml` / `.yml` | Single record. |
|
|
103
|
+
| YAML list | `.yaml` / `.yml` | Bulk: one record per list item. |
|
|
104
|
+
| JSON object | `.json` or `{...}EOF` on stdin | Single record. |
|
|
105
|
+
| JSON array | `.json` or `[...]` on stdin | Bulk: one record per array item. |
|
|
106
|
+
| **NDJSON** | **`.ndjson` / `.jsonl` or `{...}\n{...}` on stdin** | **Bulk: one record per line.** |
|
|
107
|
+
|
|
108
|
+
Stdin is sniffed from the first 512 bytes (first non-whitespace byte plus a one-object lookahead for newline-then-`{`). NDJSON parse failures collect up to 20 `bad_lines` and abort before any wire request; `--no-bulk` still forces a loop fallback for any bulk shape.
|
|
109
|
+
|
|
110
|
+
### Audit log sensitivity
|
|
111
|
+
|
|
112
|
+
`audit.jsonl` is **confidential** (not secret). It records what was sent — record-level data your account had write access to. The CLI redacts:
|
|
113
|
+
|
|
114
|
+
- HTTP headers in the `SENSITIVE_HEADERS` set (e.g. `Authorization`, `X-API-Key`) — replaced with `"<redacted>"`.
|
|
115
|
+
- Request-body fields whose OpenAPI definition has `format: password` OR whose name (case-insensitive) is one of: `password`, `secret`, `token`, `api_key`, `apikey`, `private_key`, `passphrase`, `client_secret`. Nested fields and arrays of objects are walked recursively.
|
|
116
|
+
|
|
117
|
+
The wire body sent to NetBox is **not** redacted — only the audit log. A failed write still records the redacted body; redaction is irreversible. Treat `audit.jsonl` like a verbose application log: gate it behind your home-directory permissions and rotate / archive accordingly. A "redact everything" mode is deferred to Phase 5+.
|
|
118
|
+
|
|
119
|
+
## Output and errors
|
|
120
|
+
|
|
121
|
+
- `--output {table,json,yaml,csv,jsonl}`. Table is the default on a TTY; JSON is the default when stdout is piped.
|
|
122
|
+
- On `--output json`, the records array is emitted directly (no NetBox-style `count`/`results` wrapper); single-record writes emit the resulting record dict.
|
|
123
|
+
- Failures emit a stable `ErrorEnvelope` (JSON to stdout on `--output json`, Rich panel to stderr otherwise) with `type ∈ {auth, not_found, validation, conflict, rate_limited, server, transport, schema, config, client, internal, ambiguous_alias, unknown_alias, input_error}` and a documented exit code per type. See `CHANGELOG.md` and the spec for the full table.
|
|
124
|
+
|
|
125
|
+
## Schema introspection
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
# Dump every endpoint in the bundled NetBox schema as JSON.
|
|
129
|
+
uv run nsc commands --schema nsc/schemas/bundled/netbox-4.6.0-beta2.json.gz --output json | head
|
|
130
|
+
|
|
131
|
+
# Or against a live install.
|
|
132
|
+
uv run nsc commands --schema https://netbox.example.com/api/schema/?format=json --output json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Cache management
|
|
136
|
+
|
|
137
|
+
The on-disk command-model cache lives at `~/.nsc/cache/<profile>/<schema-hash>.json` and is regenerated automatically when the live NetBox schema changes. Over time, removed profiles or upgraded NetBox versions can leave orphan entries behind.
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
nsc cache prune # show what would be deleted (dry-run)
|
|
141
|
+
nsc cache prune --apply # actually delete
|
|
142
|
+
nsc cache prune --max-age 30 --apply # also delete cache files older than 30 days
|
|
143
|
+
nsc cache prune --output json # structured envelope for scripts
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
What gets pruned:
|
|
147
|
+
|
|
148
|
+
1. Cache directories for profiles that are no longer in your config.
|
|
149
|
+
2. Cache files whose schema-hash differs from the live NetBox schema (skipped per-profile when offline).
|
|
150
|
+
3. With `--max-age <days>`: cache files older than the threshold (excludes files already covered by rule 1).
|
|
151
|
+
|
|
152
|
+
The `adhoc` cache directory (used by env-var-only invocations like `NSC_URL=… nsc dcim devices list`) is never pruned automatically.
|
|
153
|
+
|
|
154
|
+
## Shell completion
|
|
155
|
+
|
|
156
|
+
`nsc` ships static completion stubs that complete subcommands and option names.
|
|
157
|
+
|
|
158
|
+
```sh
|
|
159
|
+
nsc --install-completion # auto-detects $SHELL
|
|
160
|
+
nsc --show-completion # prints the script instead of installing
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Typer supports `bash`, `zsh`, `fish`, and `pwsh`. Completion of dynamic values (resource names, profile names, filter keys) is on the post-1.0 roadmap.
|
|
164
|
+
|
|
165
|
+
## Bundled Skill for AI agents
|
|
166
|
+
|
|
167
|
+
`nsc` ships a portable Skill bundle at `skills/netbox-super-cli/SKILL.md`
|
|
168
|
+
that briefs an AI agent on how to drive `nsc` correctly (dry-run discipline,
|
|
169
|
+
JSON output, error envelope, audit log).
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
nsc skill install --target claude-code # dry-run; prints the destination
|
|
173
|
+
nsc skill install --target claude-code --apply # actually copies
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Targets: `claude-code`, `codex`, `gemini`, `copilot`. Where a target has no
|
|
177
|
+
documented programmatic install path, the helper prints actionable manual
|
|
178
|
+
instructions instead of guessing.
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
Apache 2.0.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
nsc/__init__.py,sha256=m3dxzeerYWKx1uanN0eXxsI-1vF0cA2UqQ6QPhxlfrU,151
|
|
2
|
+
nsc/__main__.py,sha256=o6bw5_SYx7G6OUgdvA5o1IgFLOth3IjPa741_feV8dg,115
|
|
3
|
+
nsc/_version.py,sha256=ZFf1U38OicuxDHWVw0hGLGemnX6dwinKiaDIIDLeT6Y,77
|
|
4
|
+
nsc/aliases/__init__.py,sha256=_dgnKhUQqU3JQTp23ciehgFPrYSHo3NlI8vtTg4cSlE,521
|
|
5
|
+
nsc/aliases/resolver.py,sha256=d_7zkqNqKDs3xpdC-RrMNjYVVqJ1uXe5wZwjKsG_t2k,3376
|
|
6
|
+
nsc/auth/__init__.py,sha256=OHVmmfh8diZdW-gf1cKLtHZAqS-i60k4QmI5YXwqLuc,161
|
|
7
|
+
nsc/auth/verify.py,sha256=Vmu1Xva0KdOsNQ8-E-pOjRwwsUNTXx3jacEENhHYy3E,5235
|
|
8
|
+
nsc/builder/__init__.py,sha256=aa-ZXHJwGXDVrwHdSS8yyGphpZ2xYQy0qYJd-sNK6mo,147
|
|
9
|
+
nsc/builder/build.py,sha256=32z7kRO2BENJHxlwCUlQfPsr2-b1v_SojxJv61YwkGU,17185
|
|
10
|
+
nsc/cache/__init__.py,sha256=G0tQrEuIxVyv0Lf2Hxn7afUFP0-XJBTGPIqx4wpNK0g,115
|
|
11
|
+
nsc/cache/store.py,sha256=dsE_--LW0ewtHg7qGlJyIiVv4WpXGBgR6X6vdOjqefw,9874
|
|
12
|
+
nsc/cli/__init__.py,sha256=7je0t2iYb1FoeXL5DZ-ohzuXRNd8pGv5vOGsSNVpgdk,42
|
|
13
|
+
nsc/cli/aliases_commands.py,sha256=A8NmzyhG1-dgv7__mHuPenq57-XTfzbxMH8pKmavSls,10854
|
|
14
|
+
nsc/cli/app.py,sha256=ygbCQHLbq4VWzE7YgVuXZxFUcgWjIGrU1_3XsBR6Em8,10067
|
|
15
|
+
nsc/cli/cache_commands.py,sha256=zDWdbuG8aLf7aA2I9uUH-RGywkH2LKLj7C5sCgEmWd4,5199
|
|
16
|
+
nsc/cli/commands_dump.py,sha256=RrUC4oAJO9SB61eriC6hZX3LiyGfhgn8zxWTvDYJqrE,1715
|
|
17
|
+
nsc/cli/config_commands.py,sha256=rTKcOdsV5OyARV4IlRzhq8xsTfkzJctmSFzVs_SxGcI,4519
|
|
18
|
+
nsc/cli/globals.py,sha256=dPuQ1hyPSBfnhzeYtA2lOl3EwG66y4RSQQhxc9KuD9o,1732
|
|
19
|
+
nsc/cli/handlers.py,sha256=9BeiEGScAqbYOJOFZ4QU50v5Aa5vyTL8NbkSKgXOdpc,20483
|
|
20
|
+
nsc/cli/init_commands.py,sha256=iVU3ECuz0xP-ilHlqutPioDMuk44tSXr6TnqEWqXmS4,3047
|
|
21
|
+
nsc/cli/login_commands.py,sha256=r0rblP9FoHXm349WKC2rAHDSQ3NkllOaAlpPTa8yYH8,9058
|
|
22
|
+
nsc/cli/profiles_commands.py,sha256=TreEzstU8QBNwZRnoagnQe9dAj5A60FVJzGTCaftctg,8045
|
|
23
|
+
nsc/cli/registration.py,sha256=O4XPjOv72DNyt_U9UCQ_pNR-lonzi_tyENoR2KnYlPY,15701
|
|
24
|
+
nsc/cli/runtime.py,sha256=JFeaTk4eADdJdIGgZLqNaShnZcURB-Fgf78c3xBYB8M,9178
|
|
25
|
+
nsc/cli/skill_commands.py,sha256=8QBg5QwjsZOB5y0az5smioGiHtwsFqfI6YFvYY0WK7Q,5745
|
|
26
|
+
nsc/cli/writes/__init__.py,sha256=xlFMyVSTsr17Uu3W7hRhQh3pvZ_hC6A1q-kh-R_4tCk,265
|
|
27
|
+
nsc/cli/writes/apply.py,sha256=12Nz3w2K4AnY1TYj3TMGfenuMUr_KlazC_KuVaXPoXw,5419
|
|
28
|
+
nsc/cli/writes/bulk.py,sha256=h6acUykZBo2a0LV5ZrjAVesLESXY8CumLFFgvS6UU4U,7248
|
|
29
|
+
nsc/cli/writes/coercion.py,sha256=YM9u1tYmFZB1zHe-cEVS1gtNDdFpsziO3_uK_7q_U1E,317
|
|
30
|
+
nsc/cli/writes/confirmation.py,sha256=OjGWw-iIiv71JXjM41eDJ4YVy5OGenBzKpZ1SVx2skQ,2513
|
|
31
|
+
nsc/cli/writes/input.py,sha256=IE1yZcy62uYaaDnfikYVPSTUdeEqByLNZtDnYPia9-M,11898
|
|
32
|
+
nsc/cli/writes/preflight.py,sha256=kakx66XeRB_kqGnUkldJA5T7eIjbTbrBmmj5mOwV4eg,5175
|
|
33
|
+
nsc/config/__init__.py,sha256=I01yJXHUcrsAO2AzHxQnvNacqebrhPdoXI1HRqeqqmA,441
|
|
34
|
+
nsc/config/loader.py,sha256=yejt2c318pawEOv_74dYQHJSxUzqav8jXM_EayXUTow,2323
|
|
35
|
+
nsc/config/models.py,sha256=Uc1gd87mfw4W-eBhNVtL_Kx9aG72yTq8rVtEPD0mfH4,1352
|
|
36
|
+
nsc/config/settings.py,sha256=vKE6DxVAw699oF10B_E1BlgPfaD92_nz76GyJ3L5-1k,850
|
|
37
|
+
nsc/config/writer.py,sha256=3sfyYCYmSEimK35H6bJzadpHUdBemkhVmhUBO9gDTUo,7375
|
|
38
|
+
nsc/http/__init__.py,sha256=Az35N8Zc0N2OiDR_0SVKuBmbIVJNvaJx_pyfbm7SI90,206
|
|
39
|
+
nsc/http/audit.py,sha256=p01On-w_JdrPwLH1ZRQzKAZ9LLIlisHlFkkLNcNyDAo,6126
|
|
40
|
+
nsc/http/client.py,sha256=MHcIh8aObY0j10u6uoMJ_kQJOKFPMqOWtecfsZEkmMc,12470
|
|
41
|
+
nsc/http/errors.py,sha256=BSn3-kVziMdieP0QXRjoc3MJhg56l58GFvx6Vh8Qpc4,1038
|
|
42
|
+
nsc/http/retry.py,sha256=g15O-SC4jo6PSXYOwRyd7hQ5ejo8MxYb53qCflJ1KvE,2784
|
|
43
|
+
nsc/model/__init__.py,sha256=qCU--gwzpFqWcpAYdmswrCSAwW8CthN-m9rDfoo2yTo,395
|
|
44
|
+
nsc/model/command_model.py,sha256=9yh1LQIUe07xy-gLjdtpe629n_3b0qkYwpHp-9Hh2Zc,3507
|
|
45
|
+
nsc/output/__init__.py,sha256=vhKPzYhOrDV8QSeZ783TbKidjRcL6fGtxePi0hnDPZM,89
|
|
46
|
+
nsc/output/csv_.py,sha256=VTwFBkf9ITAMfmgEXxtml15VEx9WMKibvd8hyr-KniM,1015
|
|
47
|
+
nsc/output/errors.py,sha256=AmDepQohfA-Fot1TlNZ5Ht5dq9CTodswxPUIdsPIk3s,10639
|
|
48
|
+
nsc/output/explain.py,sha256=vtgHyU5nf5vHqB-87uElNhSSrVmclyOAfYFnZRMTK1M,6732
|
|
49
|
+
nsc/output/flatten.py,sha256=vXV043zhm2h7GVsuSIECbiaQyLjJJbFoQzy4kIQ4pNM,724
|
|
50
|
+
nsc/output/headers.py,sha256=fHjkLMdzgaLtXvptEPUAD9yxeqnGNQXAIGPOwc1FldM,249
|
|
51
|
+
nsc/output/json_.py,sha256=vKmIfvBRNEatYcc8rPjMXRU6hoPp8Ul-uUJe5XoKj3Y,459
|
|
52
|
+
nsc/output/jsonl.py,sha256=yjorxD1arHuU_oU4u__przFZUvlU1Y4gwxPS0eFyKEc,444
|
|
53
|
+
nsc/output/render.py,sha256=592idcoXWSDqa_tmvrXJ259u4Cq3506BR5kblkAytC4,1371
|
|
54
|
+
nsc/output/table.py,sha256=cWXWdaxS3JIhe9pau1cEXjj1fwl8gR5NYhliRSnGjHs,1359
|
|
55
|
+
nsc/output/yaml_.py,sha256=owyxkCstnFMQ25saejiOUa9TeQ3tLexgnl0pC4Bxzms,698
|
|
56
|
+
nsc/schema/__init__.py,sha256=72rlI7t-jVa_QVAyc0YEYPVSEqkOK8hLf5X-wLTV-JI,29
|
|
57
|
+
nsc/schema/hashing.py,sha256=W247Xz1cQfSInCEUSt3Bj71cbiDOtWecmRqnaGknvbU,730
|
|
58
|
+
nsc/schema/loader.py,sha256=5kp9i3LErWu3IzdC869ejc_6dj_vBwBRZ2LsJQ22Io8,2277
|
|
59
|
+
nsc/schema/models.py,sha256=OmiKbbKP5lMGw44Wo7731CyjHcBphlBrvIktBV7GNUA,3038
|
|
60
|
+
nsc/schema/source.py,sha256=IaB51cUAYFlPw29lWaiIvVP1v0oT3z6JfVUcy_vv6e4,3925
|
|
61
|
+
nsc/schemas/__init__.py,sha256=NRzj9L5FF8hzEXG7MTE-VK787WdVonSOFYTDs7dfbJU,52
|
|
62
|
+
nsc/schemas/bundled/__init__.py,sha256=GJJm8w7xSPGwIrh-t515jtzK_6UT7v2eL33FeG3_P4Q,68
|
|
63
|
+
nsc/schemas/bundled/manifest.yaml,sha256=KMe60X9drH-aDPGI3f6Y9-nV_mPd1Sh1eh34KFBZg_I,168
|
|
64
|
+
nsc/schemas/bundled/netbox-4.6.0-beta2.json.gz,sha256=33ghJddbndw9jDM9RbaNuEx1H5U7XtEXcz8qHaHoNEA,380458
|
|
65
|
+
nsc/skill/__init__.py,sha256=_DimBHGVFM1ziZPF6agmjNlohl3NvbmA6y99te1K2Bk,1243
|
|
66
|
+
skills/netbox-super-cli/SKILL.md,sha256=DA7wsnnXKt2IOaYk9jGBAV9-WdgCD2cJeMZXEdspArc,5172
|
|
67
|
+
netbox_super_cli-1.0.0.dist-info/METADATA,sha256=b2HtPvaRIndMGftp1mt2tQO6i4txVnCT48ueGaoywEo,8871
|
|
68
|
+
netbox_super_cli-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
69
|
+
netbox_super_cli-1.0.0.dist-info/entry_points.txt,sha256=jjMFpDejc7zQO8bUngITxM5Y7Z-K-AJD7x6r21CFXPc,77
|
|
70
|
+
netbox_super_cli-1.0.0.dist-info/licenses/LICENSE,sha256=1znkGGTbsCa1OQme6fa9deEpek_dzM0st2jROF-ghDo,11353
|
|
71
|
+
netbox_super_cli-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
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 Object
|
|
36
|
+
form, made available under the License, as indicated by a copyright
|
|
37
|
+
notice that is included in or attached to the work (an example is
|
|
38
|
+
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 purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the 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 the
|
|
141
|
+
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 exemplary 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
nsc/__init__.py
ADDED
nsc/__main__.py
ADDED
nsc/_version.py
ADDED
nsc/aliases/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Public alias resolver surface.
|
|
2
|
+
|
|
3
|
+
Imports nothing from `nsc.cli`, `nsc.http`, or any framework — same hard
|
|
4
|
+
rule as `nsc.model`. Consumers (`nsc/cli/aliases_commands.py`) call
|
|
5
|
+
`resolve(verb, term, command_model)` and pattern-match on the result.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from nsc.aliases.resolver import (
|
|
11
|
+
AliasVerb,
|
|
12
|
+
AmbiguousAlias,
|
|
13
|
+
ResolvedAlias,
|
|
14
|
+
UnknownAlias,
|
|
15
|
+
resolve,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"AliasVerb",
|
|
20
|
+
"AmbiguousAlias",
|
|
21
|
+
"ResolvedAlias",
|
|
22
|
+
"UnknownAlias",
|
|
23
|
+
"resolve",
|
|
24
|
+
]
|
nsc/aliases/resolver.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Pure resolver for `nsc ls / get / rm / search`.
|
|
2
|
+
|
|
3
|
+
Exposes `resolve(verb, term, command_model)` returning one of
|
|
4
|
+
`ResolvedAlias / AmbiguousAlias / UnknownAlias`. No I/O, no Typer, no
|
|
5
|
+
HTTP — caller wires the result into the dynamic-tree handlers.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from enum import StrEnum
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, ConfigDict
|
|
13
|
+
|
|
14
|
+
from nsc.model.command_model import CommandModel, HttpMethod, Operation, Resource
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AliasVerb(StrEnum):
|
|
18
|
+
LS = "ls"
|
|
19
|
+
GET = "get"
|
|
20
|
+
RM = "rm"
|
|
21
|
+
SEARCH = "search"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class _Frozen(BaseModel):
|
|
25
|
+
model_config = ConfigDict(frozen=True, extra="forbid")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ResolvedAlias(_Frozen):
|
|
29
|
+
"""Exactly one (tag, resource, operation) triple matched the term."""
|
|
30
|
+
|
|
31
|
+
tag: str
|
|
32
|
+
resource_name: str
|
|
33
|
+
operation: Operation
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AmbiguousAlias(_Frozen):
|
|
37
|
+
""">=2 (tag, resource) pairs matched. Sorted lexicographically by tag, then resource."""
|
|
38
|
+
|
|
39
|
+
verb: AliasVerb
|
|
40
|
+
term: str
|
|
41
|
+
candidates: list[tuple[str, str]]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class UnknownAlias(_Frozen):
|
|
45
|
+
"""0 matches for ls/get/rm; or `/api/search/` missing for search."""
|
|
46
|
+
|
|
47
|
+
verb: AliasVerb
|
|
48
|
+
term: str
|
|
49
|
+
reason: str = "no_such_resource"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def resolve(
|
|
53
|
+
verb: AliasVerb, term: str, model: CommandModel
|
|
54
|
+
) -> ResolvedAlias | AmbiguousAlias | UnknownAlias:
|
|
55
|
+
if verb is AliasVerb.SEARCH:
|
|
56
|
+
return _resolve_search(term, model)
|
|
57
|
+
return _resolve_term(verb, term, model)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _resolve_term(
|
|
61
|
+
verb: AliasVerb, term: str, model: CommandModel
|
|
62
|
+
) -> ResolvedAlias | AmbiguousAlias | UnknownAlias:
|
|
63
|
+
needle = term.lower()
|
|
64
|
+
candidates: list[tuple[str, str, Operation]] = []
|
|
65
|
+
for tag_name in sorted(model.tags):
|
|
66
|
+
tag = model.tags[tag_name]
|
|
67
|
+
for resource_name in sorted(tag.resources):
|
|
68
|
+
if resource_name.lower() != needle:
|
|
69
|
+
continue
|
|
70
|
+
resource = tag.resources[resource_name]
|
|
71
|
+
op = _required_op_for(verb, resource)
|
|
72
|
+
if op is None:
|
|
73
|
+
continue
|
|
74
|
+
candidates.append((tag_name, resource_name, op))
|
|
75
|
+
if len(candidates) == 1:
|
|
76
|
+
resolved_tag, resolved_resource, resolved_op = candidates[0]
|
|
77
|
+
return ResolvedAlias(
|
|
78
|
+
tag=resolved_tag, resource_name=resolved_resource, operation=resolved_op
|
|
79
|
+
)
|
|
80
|
+
if len(candidates) > 1:
|
|
81
|
+
return AmbiguousAlias(
|
|
82
|
+
verb=verb,
|
|
83
|
+
term=term,
|
|
84
|
+
candidates=[(t, r) for t, r, _ in candidates],
|
|
85
|
+
)
|
|
86
|
+
return UnknownAlias(verb=verb, term=term)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _required_op_for(verb: AliasVerb, resource: Resource) -> Operation | None:
|
|
90
|
+
"""Return the `Operation` the verb requires on `resource`, or None."""
|
|
91
|
+
if verb is AliasVerb.LS:
|
|
92
|
+
return resource.list_op
|
|
93
|
+
if verb is AliasVerb.GET:
|
|
94
|
+
return resource.get_op
|
|
95
|
+
if verb is AliasVerb.RM:
|
|
96
|
+
return resource.delete_op
|
|
97
|
+
return None # SEARCH does not flow through this branch
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _resolve_search(term: str, model: CommandModel) -> ResolvedAlias | UnknownAlias:
|
|
101
|
+
for tag_name, resource_name, op in model.iter_operations():
|
|
102
|
+
if op.path == "/api/search/" and op.http_method is HttpMethod.GET:
|
|
103
|
+
return ResolvedAlias(
|
|
104
|
+
tag=tag_name,
|
|
105
|
+
resource_name=resource_name,
|
|
106
|
+
operation=op,
|
|
107
|
+
)
|
|
108
|
+
return UnknownAlias(
|
|
109
|
+
verb=AliasVerb.SEARCH,
|
|
110
|
+
term=term,
|
|
111
|
+
reason="search_endpoint_unavailable",
|
|
112
|
+
)
|