Skip to content

feat(cli): add tower create-join-token command#75

Closed
brandonrjacobs wants to merge 6 commits into
mainfrom
feat/box-tower-join-token
Closed

feat(cli): add tower create-join-token command#75
brandonrjacobs wants to merge 6 commits into
mainfrom
feat/box-tower-join-token

Conversation

@brandonrjacobs

@brandonrjacobs brandonrjacobs commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds cwsandbox tower create-join-token CLI command for creating join tokens and storing them in Kubernetes secrets
  • Calls POST /v1beta1/towers/tokens to generate a single-use tower join token
  • Stores the token in a K8s Opaque secret (default name: sandbox-tower-join-token, key: token) matching the sandbox-tower Helm chart expectations
  • Supports --json flag for passing an API-compatible JSON payload (inline string or - for stdin)
  • Supports --generate-only to print token details without creating a K8s secret
  • Adds httpx and kubernetes as optional [cli] dependencies

Usage

# Basic usage
cwsandbox tower create-join-token --tower-id=my-tower --api-key=<key>

# With JSON payload
cwsandbox tower create-join-token --json='{"tower_id":"my-tower","ttl_seconds":3600}'

# Generate only (no K8s secret)
cwsandbox tower create-join-token --tower-id=my-tower --generate-only

# Custom K8s target
cwsandbox tower create-join-token --tower-id=my-tower --namespace=sandbox-system --secret-name=my-token

Test plan

  • Verify cwsandbox tower create-join-token --help displays all options
  • Test --generate-only against a running ATC instance
  • Test K8s secret creation with --kubeconfig pointing to a target cluster
  • Test --json with inline payload and stdin pipe
  • Test flag precedence over JSON values
  • Verify error handling for missing --api-key, missing --tower-id, bad server, invalid JSON

Closes #69

@brandonrjacobs brandonrjacobs requested a review from a team as a code owner March 10, 2026 14:03
@brandonrjacobs brandonrjacobs force-pushed the feat/box-tower-join-token branch 3 times, most recently from 1d49ca9 to 2dcfb30 Compare March 10, 2026 14:08
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
@brandonrjacobs brandonrjacobs force-pushed the feat/box-tower-join-token branch from 2dcfb30 to d7ae8e3 Compare March 17, 2026 14:26
- 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add join-token CLI command

1 participant