csw-tools 0.3.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.
Files changed (64) hide show
  1. csw_tools-0.3.0/.python-version +1 -0
  2. csw_tools-0.3.0/DEV-GUIDELINES.md +241 -0
  3. csw_tools-0.3.0/LICENSE +201 -0
  4. csw_tools-0.3.0/PKG-INFO +184 -0
  5. csw_tools-0.3.0/README.md +167 -0
  6. csw_tools-0.3.0/pyproject.toml +60 -0
  7. csw_tools-0.3.0/pyproject.toml.orig +49 -0
  8. csw_tools-0.3.0/src/csw_tools/__init__.py +1 -0
  9. csw_tools-0.3.0/src/csw_tools/__main__.py +6 -0
  10. csw_tools-0.3.0/src/csw_tools/change_control.py +64 -0
  11. csw_tools-0.3.0/src/csw_tools/cli.py +291 -0
  12. csw_tools-0.3.0/src/csw_tools/commands/__init__.py +1 -0
  13. csw_tools-0.3.0/src/csw_tools/commands/clean_stale_labels/README.md +91 -0
  14. csw_tools-0.3.0/src/csw_tools/commands/clean_stale_labels/__init__.py +5 -0
  15. csw_tools-0.3.0/src/csw_tools/commands/clean_stale_labels/command.py +272 -0
  16. csw_tools-0.3.0/src/csw_tools/commands/common.py +55 -0
  17. csw_tools-0.3.0/src/csw_tools/commands/configure_credentials/README.md +64 -0
  18. csw_tools-0.3.0/src/csw_tools/commands/configure_credentials/__init__.py +5 -0
  19. csw_tools-0.3.0/src/csw_tools/commands/configure_credentials/command.py +94 -0
  20. csw_tools-0.3.0/src/csw_tools/commands/convert_labels/README.md +103 -0
  21. csw_tools-0.3.0/src/csw_tools/commands/convert_labels/__init__.py +5 -0
  22. csw_tools-0.3.0/src/csw_tools/commands/convert_labels/command.py +197 -0
  23. csw_tools-0.3.0/src/csw_tools/commands/create_scopes/README.md +156 -0
  24. csw_tools-0.3.0/src/csw_tools/commands/create_scopes/__init__.py +5 -0
  25. csw_tools-0.3.0/src/csw_tools/commands/create_scopes/command.py +673 -0
  26. csw_tools-0.3.0/src/csw_tools/commands/init/README.md +59 -0
  27. csw_tools-0.3.0/src/csw_tools/commands/init/__init__.py +5 -0
  28. csw_tools-0.3.0/src/csw_tools/commands/init/command.py +120 -0
  29. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/README.md +169 -0
  30. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/__init__.py +5 -0
  31. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/api.py +145 -0
  32. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/command.py +271 -0
  33. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/execution.py +410 -0
  34. csw_tools-0.3.0/src/csw_tools/commands/prune_agents/planner.py +375 -0
  35. csw_tools-0.3.0/src/csw_tools/commands/prune_policy/README.md +19 -0
  36. csw_tools-0.3.0/src/csw_tools/commands/prune_policy/__init__.py +5 -0
  37. csw_tools-0.3.0/src/csw_tools/commands/prune_policy/command.py +20 -0
  38. csw_tools-0.3.0/src/csw_tools/commands/sync_collection_rules/README.md +19 -0
  39. csw_tools-0.3.0/src/csw_tools/commands/sync_collection_rules/__init__.py +5 -0
  40. csw_tools-0.3.0/src/csw_tools/commands/sync_collection_rules/command.py +20 -0
  41. csw_tools-0.3.0/src/csw_tools/config.example.toml +45 -0
  42. csw_tools-0.3.0/src/csw_tools/config.py +204 -0
  43. csw_tools-0.3.0/src/csw_tools/config_defaults.py +36 -0
  44. csw_tools-0.3.0/src/csw_tools/context.py +90 -0
  45. csw_tools-0.3.0/src/csw_tools/csw_api.py +201 -0
  46. csw_tools-0.3.0/src/csw_tools/dashboard.py +137 -0
  47. csw_tools-0.3.0/src/csw_tools/dashboard_context.py +52 -0
  48. csw_tools-0.3.0/src/csw_tools/interaction.py +37 -0
  49. csw_tools-0.3.0/src/csw_tools/keyring_store.py +39 -0
  50. csw_tools-0.3.0/src/csw_tools/output_logging.py +271 -0
  51. csw_tools-0.3.0/src/csw_tools/project-python-version.txt +1 -0
  52. csw_tools-0.3.0/src/csw_tools/project_info.py +121 -0
  53. csw_tools-0.3.0/tests/conftest.py +30 -0
  54. csw_tools-0.3.0/tests/test_cli.py +441 -0
  55. csw_tools-0.3.0/tests/test_config.py +194 -0
  56. csw_tools-0.3.0/tests/test_configure_credentials.py +229 -0
  57. csw_tools-0.3.0/tests/test_csw_api.py +185 -0
  58. csw_tools-0.3.0/tests/test_dashboard.py +103 -0
  59. csw_tools-0.3.0/tests/test_init.py +234 -0
  60. csw_tools-0.3.0/tests/test_keyring_store.py +75 -0
  61. csw_tools-0.3.0/tests/test_new_commands.py +707 -0
  62. csw_tools-0.3.0/tests/test_output_logging.py +320 -0
  63. csw_tools-0.3.0/tests/test_project_info.py +90 -0
  64. csw_tools-0.3.0/tests/test_prune_agents.py +769 -0
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,241 @@
1
+ # csw-tools developer guidelines
2
+
3
+ This document describes the shared framework used by every command. End-user
4
+ and command-specific behavior belongs in the command README linked from the
5
+ root [README.md](README.md).
6
+
7
+ ## Project layout
8
+
9
+ ```text
10
+ csw-tools/
11
+ ├── pyproject.toml Project metadata, dependencies and tool settings
12
+ ├── uv.lock Locked development dependency graph
13
+ ├── .python-version Project Python target used by uv/pyenv
14
+ ├── src/csw_tools/
15
+ │ ├── cli.py Root Click group and command registration
16
+ │ ├── context.py Per-invocation AppContext
17
+ │ ├── config.py TOML loading and setting resolution
18
+ │ ├── config_defaults.py Shared constants and backend defaults
19
+ │ ├── dashboard.py Dashboard validation and normalization
20
+ │ ├── dashboard_context.py Dashboard command decorator
21
+ │ ├── csw_api.py tetpyclient construction and checked API facade
22
+ │ ├── keyring_store.py Testable operating-system keyring adapter
23
+ │ ├── interaction.py Interactive-terminal safeguard
24
+ │ ├── change_control.py Backup creation, persistence and validation
25
+ │ ├── project_info.py Diagnostic version metadata
26
+ │ └── commands/ One subpackage and README per command
27
+ └── tests/ pytest coverage for shared and command behavior
28
+ ```
29
+
30
+ `pyproject.toml` is the source of package metadata and dependency declarations.
31
+ The package version is defined there only. `.python-version` selects the project
32
+ interpreter; the packaged `project-python-version.txt` mirrors it so an installed
33
+ wheel can report the same target. A test prevents those values from drifting.
34
+
35
+ ## Command entrypoint: inputs and outputs
36
+
37
+ The console entrypoint declared in `pyproject.toml` calls `csw_tools.cli:cli`.
38
+ The root Click group validates common inputs, builds one `AppContext`, and lets
39
+ Click pass that object to the selected command.
40
+
41
+ ```text
42
+ CLI arguments ─┐
43
+ config.toml ────┼─> root Click group ─> AppContext ─> selected command
44
+ backend defaults┘ │
45
+ ├─ resolved settings
46
+ interactive prompt (when still needed) ──┤
47
+ OS keyring (lazy) ────────────────────────┤
48
+ ├─ Common output directory
49
+ ├─ Rich stdout console
50
+ └─ Rich stderr console
51
+ ```
52
+
53
+ Settings resolve in this order:
54
+
55
+ 1. CLI value
56
+ 2. Command or common `config.toml` value
57
+ 3. Backend default
58
+ 4. Interactive prompt when the value is required and still unresolved
59
+
60
+ Global options must precede the command. Command-specific configuration tables
61
+ become Click `default_map` entries, so Click performs the final CLI-over-config
62
+ selection for command options. A command can also inspect its validated table
63
+ with `app.config_for(command_name)`.
64
+
65
+ Normal results go to `app.console` on stdout. Warnings, progress, and diagnostic
66
+ messages go to `app.error_console` on stderr. Use Rich tables and panels through
67
+ those shared consoles; do not create new consoles inside a command. Expected
68
+ usage, configuration, backup, or API failures should become `click.UsageError`
69
+ or `click.ClickException` so callers receive a useful message and nonzero exit.
70
+
71
+ `[common].output_dir` and the global `--output-dir` select one shared location
72
+ for command-owned backups, journals, reports, and logs. Relative paths resolve
73
+ from the current working directory. Commands choose their own filenames and
74
+ formats but use `app.output_dir` instead of defining directory options.
75
+
76
+ CLI transcript logging is controlled by `[common].log_cli_output` and
77
+ `--log-cli-output/--no-log-cli-output`, and is enabled by default. The root group
78
+ tees application-emitted stdout and stderr to one ANSI-free text file while
79
+ preserving the original terminal streams. It suppresses entered prompt values
80
+ and remains active through Click's final handled-error rendering. Root help,
81
+ eager version output, unknown commands, and configuration failures that occur
82
+ before common settings resolve are intentionally not logged.
83
+
84
+ ## Click command structure
85
+
86
+ Each command is a subpackage under `src/csw_tools/commands/` with an
87
+ `__init__.py`, `command.py`, and `README.md`. Export its Click command from the
88
+ subpackage, import it in `cli.py`, and register it with `cli.add_command(...)`.
89
+
90
+ A dashboard-backed interactive command normally follows this shape:
91
+
92
+ ```python
93
+ @click.command("example")
94
+ @click.option("--value")
95
+ @pass_app_context
96
+ @interactive_command
97
+ @dashboard_command
98
+ def command(app: AppContext, value: str | None) -> None: ...
99
+ ```
100
+
101
+ Decorator order is significant. `pass_app_context` supplies the shared object,
102
+ `interactive_command` rejects redirected/non-terminal stdin before prompting,
103
+ and `dashboard_command` resolves the dashboard, activates dashboard-scoped
104
+ services, and prints the dashboard panel. A deliberately non-interactive mode
105
+ requires a command-specific guard and explicit safety design.
106
+
107
+ Click owns option parsing and help. Keep the command docstring useful because it
108
+ is the authoritative `COMMAND --help` text. Rich owns presentation after inputs
109
+ are valid. Never let formatting truncate identifiers needed to review a change.
110
+
111
+ ## Shared context and configuration
112
+
113
+ `AppContext` contains validated configuration, the selected config path, the
114
+ base keyring service name, normalized dashboard state, TLS verification, and
115
+ the two Rich consoles. It contains a keyring accessor, not plaintext secrets.
116
+
117
+ `config.py` validates known TOML sections and common value types. Unknown
118
+ sections and common keys fail early rather than being silently ignored. The
119
+ removed command-level `backup_dir` setting fails with a migration message rather
120
+ than being ignored.
121
+ `config_defaults.py` is for true backend defaults and fixed identifiers. Add a
122
+ command name and config section there when its options may be configured.
123
+
124
+ The default user config is OS-native. An explicit `--config` path must exist for
125
+ normal commands; the implicit default is optional. Commands should receive
126
+ resolved values from Click/AppContext rather than reparsing TOML themselves.
127
+
128
+ ## Dashboard, credentials, and CSW API
129
+
130
+ `dashboard.py` accepts a SaaS short name, any valid ASCII FQDN, or an HTTPS
131
+ origin. A short name expands under `tetrationcloud.com`; a dotted non-SaaS FQDN
132
+ normalizes to the same URL-based identity as its explicit HTTPS form. IP
133
+ addresses and ambiguous single-label on-premises hosts require the explicit
134
+ URL. Normalization rejects user information, paths, queries, fragments, and
135
+ custom ports so API endpoints and keyring namespaces are unambiguous.
136
+
137
+ `dashboard_command` prompts only if no dashboard was supplied, calls
138
+ `AppContext.activate_dashboard()`, and displays the canonical selection. The
139
+ activation appends the dashboard name to the base keyring service, isolating
140
+ credentials between organizations. Its Rich panel shows a display name and the
141
+ canonical URL using markup-safe text objects.
142
+
143
+ `create_api_client()` retrieves the fixed API-key and secret usernames lazily
144
+ from `KeyringStore` and constructs `tetpyclient.RestClient` with the normalized
145
+ HTTPS endpoint and configured TLS verification. Never write credentials to
146
+ configuration, logs, backups, exception text, or Rich output.
147
+
148
+ `CswApi` is the checked facade around `tetpyclient`. It centralizes request
149
+ encoding, HTTP status checks, JSON decoding, common CSW operations, and inventory
150
+ pagination. Unexpected response shapes, repeated offsets, or invalid JSON fail
151
+ closed with `CswRequestError`. Put shared, stable operations here; keep
152
+ release-specific or command-only adapters inside that command's package.
153
+
154
+ Use only the API permissions a command needs and document them in its README.
155
+ Keep TLS verification enabled unless the user explicitly disables it for a
156
+ trusted deployment.
157
+
158
+ ## Rich, interaction, and change control
159
+
160
+ Use Rich for human-reviewable panels, tables, warnings, and summaries. Preserve
161
+ full object identifiers and identifying name tails. Markup must be disabled for
162
+ untrusted dashboard/API text when it could be interpreted as Rich markup.
163
+
164
+ Most commands use `interactive_command` because their workflows can prompt for
165
+ missing settings or approvals. Help and the eager `--version` option must remain
166
+ usable without a terminal and before configuration or dashboard resolution.
167
+
168
+ Mutating commands should default to dry-run and use the helpers in
169
+ `commands/common.py` and `change_control.py`. Create the backup before the first
170
+ mutation, journal attempted and completed operations atomically, verify command
171
+ and dashboard identity during recovery, and stop further mutations if the
172
+ journal cannot be persisted. Write those artifacts beneath `app.output_dir` and
173
+ define recovery limitations in the command README.
174
+
175
+ ## Core setup commands
176
+
177
+ ### `init`
178
+
179
+ The root CLI uses valid existing common output settings for `init`, but falls
180
+ back to CLI/backend defaults when the existing configuration is missing or
181
+ invalid so it can still be replaced. The command receives the resolved target
182
+ through `AppContext.config_path`, reads the packaged example with
183
+ `importlib.resources`, writes beside the target, and atomically replaces it only
184
+ after confirmation. After any successful create, replace, or retain path, it
185
+ offers to open the containing directory through the native desktop launcher.
186
+ Launcher errors are warnings and do not turn successful initialization into a
187
+ failure. It does not activate a dashboard or keyring.
188
+
189
+ ### `configure-credentials`
190
+
191
+ This command uses the normal interactive and dashboard decorators. Dashboard
192
+ activation constructs the scoped keyring service before the command checks the
193
+ two fixed usernames. The stored API key is partially masked, and the API secret
194
+ is never displayed. New-value prompts hide each one, collect it once, and report
195
+ only its character count. Keyring errors must never include secrets and should
196
+ warn that separate writes may leave an incomplete pair.
197
+
198
+ See the command READMEs for complete user-facing details:
199
+
200
+ - [`init`](src/csw_tools/commands/init/README.md)
201
+ - [`configure-credentials`](src/csw_tools/commands/configure_credentials/README.md)
202
+
203
+ ## Adding or changing a command
204
+
205
+ 1. Create or update its command subpackage and README.
206
+ 2. Define Click arguments/options and their backend defaults without duplicating
207
+ global configuration or dashboard setup.
208
+ 3. Register new config sections/constants and the command in the root CLI.
209
+ 4. Use shared context, API, output, interaction, and backup helpers where their
210
+ contracts apply.
211
+ 5. Document inputs, required API capabilities, dry-run/apply semantics, failure
212
+ behavior, recovery limits, and command-specific architecture.
213
+ 6. Add unit tests for parsing/planning and CLI tests for help, success, failure,
214
+ output, interactive safety, API validation, and partial mutation handling.
215
+
216
+ Do not put command-specific implementation notes in this file. Link to the
217
+ command README instead.
218
+
219
+ ## Development workflow
220
+
221
+ Install the Python 3.12 locked environment and run the CLI:
222
+
223
+ ```console
224
+ uv sync
225
+ uv run csw-tools --help
226
+ uv run csw-tools --version
227
+ ```
228
+
229
+ Run all checks before submitting changes:
230
+
231
+ ```console
232
+ uv run ruff format --check .
233
+ uv run ruff check .
234
+ uv run pytest
235
+ uv lock --check
236
+ uv build
237
+ ```
238
+
239
+ `uv build` uses the `uv_build` backend configured in `pyproject.toml`. Test the
240
+ built wheel from outside the checkout when changing packaged resources,
241
+ entrypoints, or version reporting.
@@ -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
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the 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 consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ 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.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: csw-tools
3
+ Version: 0.3.0
4
+ Summary: A collection of automation utilities for Cisco Secure Workload (CSW), available through this single package.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Dist: click>=8.4.2
10
+ Requires-Dist: keyring>=25.7.0
11
+ Requires-Dist: rich>=15.0.0
12
+ Requires-Dist: tetpyclient>=1.0.8
13
+ Requires-Python: >=3.12
14
+ Project-URL: Homepage, https://github.com/structured-com/csw-tools
15
+ Project-URL: Issues, https://github.com/structured-com/csw-tools/issues
16
+ Description-Content-Type: text/markdown
17
+
18
+ # csw-tools
19
+
20
+ A collection of automation utilities for Cisco Secure Workload (CSW, formerly
21
+ Tetration), available through a single command-line package.
22
+
23
+ ## Current utilities
24
+
25
+ **These core utilities set up `csw-tools` for general use:**
26
+
27
+ | Command | Description | Documentation |
28
+ |---|---|---|
29
+ | `init` | Create or replace the per-user `config.toml` | [Guide](src/csw_tools/commands/init/README.md) |
30
+ | `configure-credentials` | Inspect or replace CSW API credentials in the OS keyring | [Guide](src/csw_tools/commands/configure_credentials/README.md) |
31
+
32
+ **The following command is implemented for production use:**
33
+
34
+ | Command | Description | Documentation |
35
+ |---|---|---|
36
+ | `create-scopes` | Create scopes in bulk from CSV | [Guide](src/csw_tools/commands/create_scopes/README.md) |
37
+
38
+ **The following commands are in DEV/TESTING state and generally should not be used in production yet:**
39
+
40
+ | Command | Description | Documentation |
41
+ |---|---|---|
42
+ | `clean-stale-labels` | Remove old static labels for workloads absent from current inventory | [Guide](src/csw_tools/commands/clean_stale_labels/README.md) |
43
+ | `convert-labels` | Persist observed inventory fields as per-workload static labels | [Guide](src/csw_tools/commands/convert_labels/README.md) |
44
+ | `prune-agents` | Preview and destructively decommission stale agents and clean explicit related objects | [Guide](src/csw_tools/commands/prune_agents/README.md) |
45
+ | `prune-policy` | Not implemented: remove or filter entries within a workspace policy | [Guide](src/csw_tools/commands/prune_policy/README.md) |
46
+ | `sync-collection-rules` | Not implemented: validate collection rules against scope and filter IPs | [Guide](src/csw_tools/commands/sync_collection_rules/README.md) |
47
+
48
+ ## Installation
49
+
50
+ The project requires Python 3.12 or later. [uv](https://docs.astral.sh/uv/) is
51
+ the preferred installation and development tool, although normal Python package
52
+ installation also works.
53
+
54
+ Once uv is installed, install the package as a tool:
55
+
56
+ ```console
57
+ uv tool install csw-tools
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ List the available commands, common options, and project version information:
63
+
64
+ ```console
65
+ csw-tools --help
66
+ csw-tools --version
67
+ ```
68
+
69
+ Global options must appear before the command name. The command and its own
70
+ options follow:
71
+
72
+ ```console
73
+ csw-tools create-scopes scopes.csv
74
+ csw-tools --dashboard my-company.tetrationcloud.com prune-agents
75
+ csw-tools -d my-company configure-credentials
76
+ ```
77
+
78
+ Command-generated files use `csw-tools-outputs/` in the current working
79
+ directory and a basic CLI log is enabled by default.
80
+
81
+ Every command's guide is linked from the tables above. The command help is the
82
+ authoritative option list:
83
+
84
+ ```console
85
+ csw-tools COMMAND --help
86
+ ```
87
+
88
+ ## CSW Dashboard Selection
89
+
90
+ A dashboard may be supplied as its short SaaS name, a full FQDN, or an HTTPS
91
+ origin:
92
+
93
+ ```console
94
+ csw-tools -d my-company COMMAND
95
+ csw-tools -d my-company.tetrationcloud.com COMMAND
96
+ csw-tools -d mycsw.example.org COMMAND
97
+ csw-tools -d https://mycsw.example.org COMMAND
98
+ ```
99
+
100
+ A short name is auto-appended by default with `.tetrationcloud.com`. Any FQDN is used as
101
+ given with HTTPS. IP addresses and single-label on-premises hosts require HTTPS:// explicitly, such as `-d https://192.0.2.10` or
102
+ `-d https://csw-local`.
103
+
104
+ TLS certificate verification is enabled by default. Use
105
+ `--no-dashboard-verify-tls` only for a trusted deployment whose certificate
106
+ cannot be validated normally.
107
+
108
+ ## Configuration
109
+
110
+ Settings are resolved in this order:
111
+
112
+ 1. CLI arguments
113
+ 2. `config.toml` values
114
+ 3. Backend defaults from `config_defaults.py`
115
+ 4. Interactive prompt for an unresolved required value
116
+
117
+ `config.toml` is optional but useful for values that are reused often. Create
118
+ or replace it interactively with:
119
+
120
+ ```console
121
+ csw-tools init
122
+ ```
123
+
124
+ This copies the packaged
125
+ [`config.example.toml`](src/csw_tools/config.example.toml) to the OS-native
126
+ per-user location:
127
+
128
+ - macOS: `~/Library/Application Support/csw-tools/config.toml`
129
+ - Linux: `${XDG_CONFIG_HOME:-~/.config}/csw-tools/config.toml`
130
+ - Windows: `%APPDATA%\csw-tools\config.toml`
131
+
132
+ If needed, use `--config PATH` before the command name to select a different file.
133
+
134
+ Common output behavior can be reused across every command:
135
+
136
+ ```toml
137
+ [common]
138
+ output_dir = "csw-tools-outputs"
139
+ log_cli_output = true
140
+ ```
141
+
142
+ Relative output paths are resolved from the current working directory. Absolute
143
+ paths and paths beginning with `~` are also accepted. CLI transcript logging is
144
+ enabled by default; disable it for one run with `--no-log-cli-output` before the
145
+ command name. Each transcript combines stdout and stderr in a plain-text file
146
+ named `csw-tools-COMMAND-YYYYMMDDTHHMMSSmmmZ.log`, prints its absolute path to
147
+ stderr in quotes when logging starts, and never records entered prompt values.
148
+ Root help, version output, unknown commands, and errors raised before
149
+ configuration can be resolved do not create transcripts.
150
+
151
+ ## Credentials
152
+
153
+ Secrets are stored through the operating system keyring and are never written
154
+ to `config.toml` or a backup. For a dashboard named `my-company`, the default
155
+ identifiers are:
156
+
157
+ | Service name | Username | Stored value |
158
+ |---|---|---|
159
+ | `csw-tools:my-company` | `csw:api_key` | CSW API key |
160
+ | `csw-tools:my-company` | `csw:api_secret` | CSW API secret |
161
+
162
+ Inspect or replace the credential pair interactively:
163
+
164
+ ```console
165
+ csw-tools -d my-company configure-credentials
166
+ ```
167
+
168
+ (If using a CSW Dashboard that is not `.tetrationcloud.com`, then the full HTTPS url is used instead as part of the service name)
169
+
170
+ ## Safe Change Workflow
171
+
172
+ Mutating commands default to `--dry-run`; review the complete plan before using
173
+ `--apply`. Supported commands create a timestamped JSON backup before the first
174
+ API mutation in the common output directory and update it around each attempted
175
+ operation. Keep backups until the results have been validated.
176
+
177
+ Rollback support and limitations differ by command. Read the individual command
178
+ guide before applying or recovering changes. Agent decommissioning has no true
179
+ rollback.
180
+
181
+ ## Development
182
+
183
+ See [DEV-GUIDELINES.md](DEV-GUIDELINES.md) for architecture, shared APIs,
184
+ contributor workflow, and project checks.