Skip to content

Token Management CLI Commands#77

Merged
Furisto merged 5 commits into
mainfrom
token-cmds
Jan 3, 2026
Merged

Token Management CLI Commands#77
Furisto merged 5 commits into
mainfrom
token-cmds

Conversation

@Furisto
Copy link
Copy Markdown
Owner

@Furisto Furisto commented Jan 3, 2026

Summary

Implements construct daemon token command group with create, list, and revoke subcommands for managing authentication tokens. Completes the CLI interface for the token-based authentication system.

Context

With the authentication backend merged, administrators need CLI tools to manage tokens for remote daemon access. These commands provide the full lifecycle: creation, auditing, and revocation.

Changes

Commands Added

  • construct daemon token create <name> - Generate authentication tokens
  • construct daemon token create-setup <name> - Generate single-use setup codes
  • construct daemon token list - Display token metadata
  • construct daemon token revoke <id> - Invalidate tokens by UUID

Utilities

  • duration.go - Custom parser supporting day notation (30d, 90d) with validation
  • time_format.go - Relative time formatting ("2 days ago", "in 88 days")

Key Features

  • Token creation with configurable expiry (default 90d, max 365d)
  • Setup codes for secure distribution (default 5m expiry, max 72h)
  • Security warnings when displaying tokens
  • Confirmation prompts before revocation
  • Multiple output formats (table, card, json, yaml)
  • Relative timestamps in list view

Examples

Create token for developer

# Admin generates setup code on server
construct daemon token create-setup dev-laptop --code-expires 30m

# Output: ABCD-1234 (expires in 30 minutes)

# Developer uses code on their machine
construct context add my-server \
  --endpoint https://construct.example.com:8443 \
  --setup-code ABCD-1234

CI/CD token management

# Create long-lived token for CI
construct daemon token create github-actions \
  --description "GitHub Actions deployment" \
  --expires 365d \
  --output json > token.json

# Token saved to CI secrets

Audit and rotate tokens

# Review all tokens
construct daemon token list

# Filter by environment
construct daemon token list --name-prefix prod

# Revoke old token
construct daemon token revoke a1b2c3d4-5678-90ab-cdef-123456789012

# Create replacement
construct daemon token create laptop-token-new --expires 90d

Testing

Manual verification

# Build and test help output
cd frontend/cli && go build
./construct daemon token --help

# Test each command
./construct daemon token create test-token --expires 30d
./construct daemon token list
./construct daemon token revoke <id-from-list> --force

Key scenarios to verify

  • Token creation with valid/invalid expiry durations
  • Setup code generation with custom expiry
  • List filtering by name prefix
  • Revoke with/without confirmation prompt
  • Output format switching (json, yaml, table, card)

Furisto and others added 5 commits January 3, 2026 14:42
Implement ParseDuration to extend standard time.ParseDuration with
day notation support (e.g., 30d for 30 days). Includes validation
functions for token and setup code expiry limits.

Add FormatRelativeTime for human-readable relative timestamps.
Uses appropriate granularity based on duration: minutes for under
1 hour, hours for under 1 day, days otherwise.

Co-authored-by: construct-agent <noreply@construct.sh>
Create daemon token command group with display types for token
listing and creation output. Define TokenDisplay for table output
with relative time formatting, TokenCreateDisplay for create command
output, and SetupCodeDisplay for setup code generation output.

Wire token command group into daemon parent command.

Co-authored-by: construct-agent <noreply@construct.sh>
Add daemon token create command to generate authentication tokens with
configurable expiry and optional description. Displays token once in
card format with security warning to save it securely.

Add daemon token create-setup command to generate short-lived setup
codes for secure token distribution. Outputs setup code with usage
instructions for clients to exchange it.

Both commands use custom duration parser for day notation and validate
expiry limits before making API calls.

Co-authored-by: construct-agent <noreply@construct.sh>
Add daemon token list command to display all tokens with metadata
including ID, name, creation time, expiration, and status. Supports
filtering by name prefix and including expired tokens. Converts
timestamps to relative time format for readability.

Add daemon token revoke command to invalidate tokens by UUID. Validates
UUID format and prompts for confirmation before revoking. Uses force
flag to skip confirmation prompt.

Co-authored-by: construct-agent <noreply@construct.sh>
@Furisto Furisto marked this pull request as ready for review January 3, 2026 13:49
@Furisto Furisto merged commit 51364b4 into main Jan 3, 2026
1 check passed
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.

1 participant