feat(cli): add tower create-join-token command#75
Closed
brandonrjacobs wants to merge 6 commits into
Closed
Conversation
1d49ca9 to
2dcfb30
Compare
Add `cwsandbox tower create-join-token` to create join tokens and store them in Kubernetes secrets for tower registration. Features: - Calls the sandbox platform API to generate a single-use join token - Stores the token in a K8s secret (default: sandbox-tower-join-token) - Supports --json flag for API-compatible JSON payloads (inline or stdin) - Supports --generate-only to print token without K8s storage - Configurable via flags and env vars (BOX_API_KEY, BOX_ATC_SERVER) - Kubeconfig resolution via flag, KUBECONFIG env, or in-cluster config Adds httpx and kubernetes as optional [cli] dependencies. Closes #69
2dcfb30 to
d7ae8e3
Compare
- Fix mypy config regression: `follow_imports = "skip"` was accidentally moved from the `wandb.*` override to `kubernetes.*` during insertion of the new TOML block - Align auth with SDK conventions: use `CWSANDBOX_API_KEY` and `CWSANDBOX_BASE_URL` env vars instead of `BOX_API_KEY`/`BOX_ATC_SERVER` - Fix truthiness bug: use `is not None` checks in `_apply_json_payload` and body-building so that `ttl_seconds=0` and empty strings are not silently dropped - Reuse `DEFAULT_BASE_URL` from `_defaults.py` instead of duplicating the server URL constant - Handle missing `token` field in API response with a clean error message instead of a raw KeyError traceback
Add 21 tests covering the tower create-join-token CLI command: - Input validation (missing API key, missing tower ID, invalid JSON) - CWSANDBOX_API_KEY env var resolution - --generate-only output and secret creation bypass - Normal flow with token creation and K8s secret storage - Custom K8s options (namespace, secret name, kubeconfig) - JSON payload parsing, stdin reading, and flag precedence - Edge cases: ttl_seconds=0 and empty string description not dropped - Missing token field in API response - httpx error handling (HTTP status errors, connection errors) - K8s secret 409 conflict triggers update instead of failure
Move `from cwsandbox._defaults import DEFAULT_BASE_URL` above the module-level constants to satisfy ruff E402 (module-level import not at top of file).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
cwsandbox tower create-join-tokenCLI command for creating join tokens and storing them in Kubernetes secretsPOST /v1beta1/towers/tokensto generate a single-use tower join tokensandbox-tower-join-token, key:token) matching the sandbox-tower Helm chart expectations--jsonflag for passing an API-compatible JSON payload (inline string or-for stdin)--generate-onlyto print token details without creating a K8s secrethttpxandkubernetesas optional[cli]dependenciesUsage
Test plan
cwsandbox tower create-join-token --helpdisplays all options--generate-onlyagainst a running ATC instance--kubeconfigpointing to a target cluster--jsonwith inline payload and stdin pipe--api-key, missing--tower-id, bad server, invalid JSONCloses #69