The user wants to know how to create a CLI (Command Line Interface) for a developer platform intake process.
This involves several key components:
- Command Structure: How the CLI commands look and feel.
- Authentication Patterns: How the user logs in and authenticates requests.
- Request Validation: Ensuring the input data is correct before sending it to the backend.
- Workflow Orchestration Hooks: How the CLI triggers and tracks the backend workflow.
- Audit Logging: Recording who did what and when.
- Release Strategy: How to version and distribute the CLI.
1. Command Structure:
- Needs to be intuitive. Usually follows a
noun verb or verb noun pattern.
- Examples:
intake project create, intake request list.
- I should suggest using a framework like
click (Python), cobra (Go), or oclif (Node.js). Go is very popular for CLIs, so I'll lean towards a Go-like structure but keep concepts general.
2. Authentication Patterns:
- CLIs usually don't handle passwords directly.
- Best practice: OAuth2 Device Authorization Grant (Device Flow) for human users.
- Alternative: API Keys/Service Tokens for CI/CD.
- Storage: Need to store tokens securely (keyring access, encrypted files).
3. Request Validation:
- Client-side validation (schema validation) before hitting the API to save time.
- Types: Required fields, formats (email, domain), enum values.
- Tools: JSON Schema, validation libraries.
4. Workflow Orchestration Hooks:
- The CLI is just a client. It needs to talk to an "Intake API" which then triggers a workflow (e.g., Temporal, Airflow, Argo).
- The CLI needs to handle:
- Synchronous vs. Asynchronous responses.
- Polling or WebSocket connections for status updates.
- Webhook triggers (if the CLI is used in automation).
5. Audit Logging:
- What needs to be logged?
- Timestamp, User ID, Command run, Parameters (mask secrets!), Outcome (Success/Fail).
- Where? Stdout (for piping), local file (debug), and API (centralized).
6. Release Strategy:
- Versioning: SemVer (Semantic Versioning).
- Distribution: Homebrew, Chocolatey, Docker, raw binaries via GitHub Releases.
- Auto-updates: The CLI should check if it's outdated.
Drafting the Content:
- Introduction: Brief overview of the goal (standardizing resource creation).
- Technology Stack Recommendation: I'll use Go with Cobra as the mental model because it's the industry standard for robust CLIs, but I'll keep the architectural advice general.
- Section 1: Command Structure:
- Focus on context-based grouping (e.g.,
platform project, platform db).
- Global flags vs local flags.
- Interactive vs. Non-interactive modes (crucial for CI).
- Section 2: Authentication:
- Detail the OAuth Device Flow (User) vs. Token (CI).
- Mention secure storage (OS Keychain).
- Section 3: Validation:
- Schema-based validation.
- "Dry-run" modes are helpful here.
- Section 4: Orchestration:
- The "Controller" pattern. CLI submits spec -> API returns ID -> CLI polls status.
- Section 5: Audit Logging:
- Structured logging (JSON).
- Centralized forwarding (sending logs to the platform itself).
- Section 6: Release Strategy:
- Goreleaser equivalent concepts.
- Homebrew/Scoop/Docker.
Refining the "Intake" aspect:
The specific use case is "Intake". This means requesting new resources (repos, infra, access).
So the core command might be platform request create --type aws-s3 --spec config.yaml.
Self-Correction/Review during drafting:
- Initial thought: Show code snippets.
- Correction: Too much code might be specific to one language. Better to show structure and interaction diagrams or pseudo-code/configs to remain language-agnostic but actionable. I will provide some Go/Python logic examples where specific implementation details matter (like auth).
Structuring the output:
I will organize this as a technical design document or "Blueprint".
- Architecture Overview
- Command Structure (UX)
- Authentication & Security
- Validation Logic
- Orchestration & State
- Auditability
- Distribution & Releases
Let's write this out. I'll ensure the distinction between "Interactive" (Human) and "Headless" (CI) is clear, as that's a common friction point in developer platforms. I will also emphasize the separation of concerns: CLI handles input/display, API handles logic.
Key detail on Orchestration Hooks:
The user asked for "hooks". In a CLI context, this usually means:
- Pre-flight checks (hooks before sending).
- Post-execution triggers (webhooks).
- Or, the CLI triggering a webhook in the platform. I will interpret this as the interface between the CLI and the Workflow Engine (e.g., Temporal).
Let's assemble.
This is a blueprint for building a robust Internal Developer Platform (IDP) intake CLI. This tool acts as the "front door" for developers to request infrastructure, services, or permissions.
I will use Go (Cobra) or TypeScript (Oclif) as the mental model, as these are the industry standards for CLI tools.
1. Command Structure (The UX)
The structure should follow the Noun-Verb pattern and separate "one-time actions" from "lifecycle management."
Recommended Tree Structure:
platform
├── request (or 'intake')
│ ├── create [interactive] # Starts a wizard
│ ├── create -f spec.yaml # Declarative input
│ ├── list # View user requests
│ └── status <request-id> # Check lifecycle
├── template
│ ├── list # Discover available golden paths
│ └── show <template-name> # Show required fields
└── auth
├── login # Interactive auth
└── status # Check token validity
Interactive vs. Headless:
- Interactive: Run
platform request create to prompt for fields (e.g., "Which language?", "How many replicas?").
- Headless (CI/CD): The CLI must accept a
-f/--file flag to ingest a standard YAML/JSON manifest for automation.
2. Authentication Patterns
Since this is an internal tool, do not build custom auth. Use OIDC (Okta/Auth0/Google) with Device Authorization Flow.
The Pattern:
- Login Command: User runs
platform auth login.
- Device Code: CLI calls the Identity Provider (IdP) and gets a
device_code and user_code.
- Prompt: CLI prints: "Please visit https://idp.com/activate and enter code: ABC-123".
- Polling: CLI polls the IdP token endpoint.
- Exchange: Once the user authenticates in the browser, the CLI receives an
access_token (JWT) and a refresh_token.
- Storage: Store these tokens securely in the local OS keychain (Keychain on macOS, Credential Manager on Windows, Secret Service on Linux).
- Do not store tokens in plain text config files.
API Calls:
For every request to the Platform API, attach the token:
Authorization: Bearer <access_token>
3. Request Validation
Validation happens at two layers: Client-Side (fast feedback) and Server-Side (source of truth).
Client-Side (Local Validation):
Before sending a request, the CLI should validate the user's input against a schema.
- Mechanism: Fetch JSON schemas from the platform API on startup (e.g.,
GET /schemas/service-create.json).
- Execution: Use a library like
ajv (JS) or gojsonschema (Go) to validate the user's YAML/Inputs locally.
- Benefit: Users don't wait for an API round-trip to find out they misspelled "production".
Server-Side (Admission Control):
The CLI sends the payload to the platform API. The API performs business logic validation (e.g., "Does this user have permission to create Postgres DBs?").
4. Workflow Orchestration Hooks
The CLI shouldn't do the work (provisioning DBs, creating repos); it should trigger a workflow engine (Temporal, Airflow, or a generic CI pipeline runner) and get out of the way.
The Handshake Pattern:
- Submit: CLI
POST /requests with the payload.
- Ack: API returns a
request_id and a websocket_url / log_stream_url.
- The Hook:
- Async Mode: CLI prints "Request submitted. Track it here: https://portal/req/123".
- Sync/Watch Mode: CLI upgrades the connection to a WebSocket or polls a status endpoint, streaming logs from the orchestrator back to the user's terminal in real-time.
// Pseudo-code for the Watch Hook
func WatchRequest(id string) {
conn := ConnectWebSocket(wsUrl)
for {
msg := conn.Read()
if msg.Status == "COMPLETED" {
print("Success! URL: " + msg.Output.Url)
return
}
if msg.Status == "FAILED" {
print("Error: " + msg.Error)
return
}
print(msg.LogLine) // Stream orchestration logs
}
}
5. Audit Logging
Security and compliance are critical for internal platforms.
The Middleware Approach:
The CLI itself does not write audit logs (clients can be tampered with). The Platform API writes the logs. The CLI simply sends metadata to help the API.
What to log:
- Who: The subject DN or User ID from the JWT.
- What: The specific command run (e.g.,
request create --type=postgres).
- When: Timestamp.
- Source: The IP address and the CLI version (User-Agent header).
CLI Specific Strategy:
The CLI should generate a unique correlation_id (UUID) for every execution. This ID is sent in the HTTP Headers (X-Request-ID).
If something goes wrong in the orchestration engine, the user can give support the correlation_id, and support can trace it from the API Gateway -> Orchestrator -> Terraform logs.
6. Release Strategy
You cannot force developers to update software easily. You need a "Self-Updating" strategy.
Distribution:
- Package Managers: Distribute via Homebrew (Mac), Chocolatey (Windows), and Snap/Apt (Linux).
- Binary Distribution: GitHub Releases for raw binaries.
Versioning Strategy:
- Semantic Versioning: Strictly adhere to
Major.Minor.Patch.
- API Versioning: The CLI should call versioned API endpoints (e.g.,
/v1/requests).
The Update Pattern:
On every run, the CLI (in a background thread) checks GET /latest-version.
- If the server version > local version:
- Soft Warning: Print a warning message in yellow text: "A new version (v2.0) is available. You are on v1.0."
- Hard Block: (Optional) If the API version is incompatible, refuse to run and demand an update.
Implementation Tip:
Build the CLI so that help text and command definitions can be generated dynamically or easily updated. The logic should live in the backend (the Platform API), keeping the CLI "thin" and acting mostly as a renderer. This minimizes the need for users to update the binary just to see a new field in a form.