-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add whole-group export/import for worker groups and edge fleets #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9beae9
fix: correct 8 group-scoped resource API paths
JacobPEvans-personal 9d899e3
feat: add whole-group export/import for worker groups and edge fleets
JacobPEvans-personal 013904d
fix: address Copilot review on group export/import
JacobPEvans-personal 6d75f82
feat(groups): drop built-in and pack-owned resources from export
werd-drew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """Whole-group config export/import for worker groups and edge fleets.""" | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import sys | ||
|
|
||
| import click | ||
|
|
||
| from cribl_cli.api.client import get_client | ||
| from cribl_cli.api.endpoints.version import commit_version | ||
| from cribl_cli.api.endpoints.workers import deploy_group | ||
| from cribl_cli.output.formatter import format_output | ||
| from cribl_cli.utils.errors import handle_error | ||
| from cribl_cli.utils.group_resolver import resolve_group | ||
| from cribl_cli.utils.group_transfer import ( | ||
| apply, | ||
| collect, | ||
| format_caveat, | ||
| read_input, | ||
| write_dir, | ||
| ) | ||
|
|
||
|
|
||
| @click.group("groups", help="Export and import all config for a worker group or edge fleet.") | ||
| def groups_group(): | ||
| pass | ||
|
|
||
|
|
||
| @groups_group.command("export", help="Pull all config for one worker group or edge fleet.") | ||
| @click.argument("group") | ||
| @click.option("--out-dir", default=None, help="Write one file per resource type under <out-dir>/<group>/.") | ||
| @click.option("--include-sensitive", is_flag=True, help="Include secrets, credentials, and certificates.") | ||
| @click.option("--include-packs", is_flag=True, help="Include pack configurations (definitions only).") | ||
| @click.option("--include-lookups", is_flag=True, help="Include lookup configurations (definitions only).") | ||
| @click.option("--table", "use_table", is_flag=True, help="Table output (stdout mode only).") | ||
| def groups_export(group, out_dir, include_sensitive, include_packs, include_lookups, use_table): | ||
| """Export every group-scoped resource for GROUP (a worker group or edge fleet). | ||
|
|
||
| Outputs one aggregated JSON object to stdout, or use --out-dir to write a | ||
| file per resource type. Sensitive resources are excluded unless | ||
| --include-sensitive is passed; a caveat of everything skipped or failed is | ||
| always printed to stderr. | ||
| """ | ||
| try: | ||
| client = get_client() | ||
| g = resolve_group(client, group) | ||
| result = collect( | ||
| client, g, include_sensitive=include_sensitive, | ||
| include_packs=include_packs, include_lookups=include_lookups | ||
| ) | ||
|
|
||
| if out_dir: | ||
| base = write_dir(result, out_dir) | ||
| click.echo(format_output({"written": str(base), "resource_types": len(result["resources"])})) | ||
| else: | ||
| click.echo(format_output(result, table=use_table)) | ||
|
|
||
| click.echo(format_caveat(result), err=True) | ||
| except Exception as e: | ||
| handle_error(e) | ||
|
|
||
|
|
||
| @groups_group.command("import", help="Push exported config into a worker group or edge fleet.") | ||
| @click.argument("group") | ||
| @click.option("--in", "in_path", default=None, help="Read payload from a JSON file or an --out-dir directory.") | ||
| @click.option("--with-routes", is_flag=True, help="Also replace the route table (wholesale; off by default).") | ||
| @click.option("--with-packs", is_flag=True, help="Also import packs (off by default).") | ||
| @click.option("--with-lookups", is_flag=True, help="Also import lookups (off by default).") | ||
| @click.option("--commit", "commit_message", default=None, help="Commit staged changes with this message.") | ||
| @click.option("--deploy", is_flag=True, help="Commit and deploy to live workers (requires --yes).") | ||
| @click.option("--yes", is_flag=True, help="Confirm deployment.") | ||
| def groups_import(group, in_path, with_routes, with_packs, with_lookups, commit_message, deploy, yes): | ||
| """Import config into GROUP (a worker group or edge fleet). | ||
|
|
||
| Reads an export payload from --in (a file or an --out-dir directory) or from | ||
| stdin, then upserts each resource. The route table is left untouched unless | ||
| --with-routes is passed. Nothing is deployed: changes stay staged until you | ||
| review them and deploy explicitly, or pass --deploy --yes. | ||
| """ | ||
| try: | ||
| if in_path: | ||
| payload = read_input(in_path) | ||
| else: | ||
| raw = sys.stdin.read() | ||
| if not raw.strip(): | ||
| raise ValueError("No input. Pass --in FILE|DIR or pipe an export JSON on stdin.") | ||
| payload = json.loads(raw) | ||
|
|
||
| client = get_client() | ||
| target = resolve_group(client, group) | ||
|
|
||
| if deploy and not yes: | ||
| click.echo( | ||
| "WARNING: --deploy commits and pushes config to live workers. Pass --yes to confirm.", | ||
| err=True, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| report = apply( | ||
| client, target, payload, | ||
| with_routes=with_routes, with_packs=with_packs, with_lookups=with_lookups | ||
| ) | ||
| click.echo(format_output(report)) | ||
|
|
||
| if commit_message or deploy: | ||
| message = commit_message or "Import group config" | ||
| commit_version(client, target, message) | ||
| click.echo(f"Committed: {message}", err=True) | ||
|
|
||
| if deploy: | ||
| deploy_group(client, target) | ||
| click.echo(f"Deployed to {target}.", err=True) | ||
| else: | ||
| click.echo( | ||
| f"Config staged (not deployed). Review with " | ||
| f"`cribl version status -g {target}` / `cribl version diff -g {target}`, " | ||
| f"then `cribl version deploy -g {target} --yes`.", | ||
| err=True, | ||
| ) | ||
| except Exception as e: | ||
| handle_error(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.