Building a Developer Platform Intake CLI
As Sherlock from Trailblazer Labs, I'll guide you through architecting a robust Developer Platform Intake CLI (let's call it dp-intake). This CLI enables developers to submit "intakes" (e.g., service blueprints, infra requests, or code deploys) to an Internal Developer Platform (IDP) backend. It handles submission, validation, and orchestration while ensuring security and observability.
We'll use Go with Cobra for the CLI framework—it's performant, cross-platform, and battle-tested (e.g., like Kubernetes CLI). Alternatives: Rust/Clap or Python/Click.
Prerequisites
- Go 1.21+
- Backend API (assumed REST/gRPC with endpoints like
/intakes).
- Tools:
cobra-cli for scaffolding, github.com/spf13/cobra, github.com/spf13/viper (config), github.com/go-resty/resty (HTTP client).
Init project:
mkdir dp-intake && cd dp-intake
go mod init github.com/yourorg/dp-intake
go install github.com/spf13/cobra-cli@latest
cobra-cli init --pkg-name cmd
1. Command Structure
Organize as a tree of subcommands for discoverability. Root: dp-intake. Key commands:
dp-intake
├── create # Submit new intake (e.g., service, infra)
│ ├── service # Intake a microservice blueprint
│ └── infra # Intake infra (e.g., DB, queue)
├── validate # Dry-run validation
├── list # List user intakes
├── get <id> # Get intake details
├── logs <id> # Tail logs
├── version # CLI version
└── config # Manage local config
└── init # Bootstrap auth/config
Implementation (in cmd/root.go and subdirs):
// cmd/root.go
var rootCmd = &cobra.Command{
Use: "dp-intake",
Short: "Developer Platform Intake CLI",
// ...
}
var createCmd = &cobra.Command{
Use: "create [type]",
Short: "Create intake",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Dispatch to subcommands or use args[0]
},
}
rootCmd.AddCommand(createCmd)
YAML/JSON Input: Use stdin or --file flag for declarative payloads (e.g., OpenAPI-like schemas for services).
Tab Completion: Cobra auto-generates shells (bash/zsh/fish).
2. Authentication Patterns
Support multiple flows: prioritize secure, short-lived tokens.
- Primary: OIDC/OAuth2 Device Flow (interactive, no secrets stored).
- Fallback: API Key (from IDP dashboard, stored encrypted).
- Service Accounts: JWT assertion for CI/CD.
Config (~/.dp-intake/config.yaml via Viper):
auth:
issuer: https://auth.youridp.com
client-id: dp-intake-cli
api-key: ENC:... # Encrypted with keyring or age
Code (auth handler):
// pkg/auth/auth.go
type Auth struct {
Token string
Expires time.Time
}
func (a *Auth) GetToken(ctx context.Context) (string, error) {
if a.IsValid() {
return a.Token, nil
}
// Refresh via OIDC or key
token, err := oidc.Exchange(ctx, /* device code */)
if err != nil {
return fetchWithAPIKey()
}
return token.AccessToken, nil
}
Use golang.org/x/oauth2 + golang.org/x/exp/slices for keyring (cross-platform secrets: macOS Keychain, Windows Credential Manager, Linux Secret Service).
MFA/SSO: Detect browser launch for OIDC.
3. Request Validation
Validate before API submission to fail fast. Use JSON Schema or OpenAPI for payloads.
- Local Schema Check: Embed schemas in binary.
- Dry-Run Mode:
--dry-run calls backend /validate endpoint.
- Common Validations: Required fields, semver, resource limits, security scans (e.g., integrate
trivy for images).
Code (using github.com/xeipuuv/gojsonschema):
// pkg/validate/validate.go
func ValidatePayload(schema []byte, payload []byte) error {
sl := gojsonschema.NewBytesLoader(schema)
dl := gojsonschema.NewBytesLoader(payload)
result, err := gojsonschema.Validate(sl, dl)
if err != nil || !result.Valid() {
// Pretty print errors
return fmt.Errorf("validation failed: %v", result.Errors())
}
return nil
}
In create command:
if err := validate.ValidatePayload(schemaBytes, input); err != nil {
return err
}
if dryRun {
fmt.Println("✅ Valid!")
return nil
}
4. Workflow Orchestration Hooks
Trigger backend workflows (e.g., ArgoCD, Tekton, Temporal) post-submission.
- Polling/Webhooks: CLI polls
/intakes/{id}/status or listens via WebSocket.
- Hooks:
--hook-url for custom webhooks (e.g., notify Slack).
- Callbacks: Backend posts to CLI via ngrok/tunnel for long-running.
Code (orchestrator):
// pkg/orchestrate/orchestrate.go
func SubmitAndWatch(ctx context.Context, payload []byte) (string, error) {
id, err := resty.R().SetBody(payload).Post("/intakes")
if err != nil { return "", err }
ticker := time.NewTicker(5 * time.Second)
for {
select {
case <-ctx.Done(): return "", ctx.Err()
case <-ticker.C:
status := resty.R().Get("/intakes/" + id + "/status")
if status.IsComplete() { return id, nil }
}
}
}
Integrate with github.com/argoproj/argo-cd client for GitOps sync.
5. Audit Logging
Log everything immutably. CLI-side for local audits, backend for central.
- Format: Structured JSON (OpenTelemetry compatible).
- Fields:
user_id, action, resource_id, payload_hash, timestamp, outcome.
- Storage: Local (
~/.dp-intake/audit.jsonl), forward to backend /audit.
Code (using go.uber.org/zap):
logger, _ := zap.NewProduction()
defer logger.Sync()
func Audit(ctx context.Context, event map[string]interface{}) {
event["user_id"] = auth.GetUserID(ctx)
event["trace_id"] = trace.ID(ctx)
logger.Info("audit", zap.Any("event", event))
// POST to backend
}
Call in every command: Audit(ctx, map{"action": "create_service", "id": id}).
6. Release Strategy
Semantic versioning with automation.
Install: go install github.com/yourorg/dp-intake@latest or brew.
Next Steps
- Scaffold full repo: Clone a template like this example.
- Test:
go test ./... + golden files for validation.
- Backend Integration: Ensure API supports CORS, rate-limiting.
- Observability: Add Prometheus metrics export.
This gives you a production-ready CLI in ~1-2 weeks. Ping me for code repos or tweaks! 🕵️♂️