cli

package
v1.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cli is the cobra command surface for the `iam` administrative CLI. main.go is a thin wrapper around Execute(); external consumers (e.g. liquidityio/cli's `liquid iam ...`) can import the package and mount NewRootCmd() under their own root command via cobra.AddCommand.

Index

Constants

This section is empty.

Variables

View Source
var Version = "(dev)"

Version is overridden at link time by -ldflags "-X .../cli.Version=...". Falls back to "(dev)" when built without flags.

Functions

func Execute

func Execute() error

Execute runs the root command. main() calls this; library consumers usually want NewRootCmd() instead.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd returns a fresh root command containing the entire `iam` surface. Each call returns a new tree so it's safe to mount under a different parent without worrying about cobra's global state.

Usage from an external Go consumer:

import iamcli "github.com/hanzoai/iam/cmd/iam/cli"

root := &cobra.Command{Use: "liquid"}
root.AddCommand(iamcli.NewRootCmd())   // mounts the whole tree
// — or to remount under a different name:
iam := iamcli.NewRootCmd()
iam.Use = "iam"   // already "iam", but you can rename here
root.AddCommand(iam)

All subcommands honour --addr and --token; the persistent flags declared here are inherited by every leaf.

Types

type APIError

type APIError struct {
	Status     int
	StatusText string
	Message    string
	Body       []byte
}

APIError is the error returned when IAM responds with a non-2xx, or when its status="error" envelope flags a logical failure. Mirrors the TypeScript HanzoAPIError shape used by @hanzo/sdk so callers can pattern- match on Status (HTTP) and Message (server msg) the same way.

func (*APIError) Error

func (e *APIError) Error() string

type Application

type Application struct {
	Owner        string   `json:"owner"`
	Name         string   `json:"name"`
	Organization string   `json:"organization"`
	DisplayName  string   `json:"displayName"`
	ClientId     string   `json:"clientId"`
	ClientSecret string   `json:"clientSecret,omitempty"`
	GrantTypes   []string `json:"grantTypes,omitempty"`
	RedirectUris []string `json:"redirectUris"`
}

Application is a minimal projection of object.Application — only the fields the CLI prints / round-trips. Decode is permissive: extra fields in the JSON are preserved when we feed a raw upsert body back to the server (see appUpsert), but the projection here keeps the CLI independent of every new column added to the server-side row.

type Config

type Config struct {
	Addr  string
	Token string
}

Config carries the IAM server address + bearer token resolved from the environment and/or top-level flags. One instance is built in cli.go and shared by every subcommand.

func (*Config) RequireToken

func (cfg *Config) RequireToken() error

RequireToken returns an error pointing the operator at how to find a service token if IAM_TOKEN is unset. Every authenticated subcommand calls this before issuing a request.

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient wraps a *http.Client with the IAM-specific Bearer token, envelope handling, and URL builder.

func NewHTTPClient

func NewHTTPClient(cfg *Config) *HTTPClient

func (*HTTPClient) Addr

func (h *HTTPClient) Addr() string

func (*HTTPClient) Get

func (h *HTTPClient) Get(path string, query url.Values, out any) error

Get issues a GET, unwraps the IAM envelope, and decodes data into out. Pass out=nil to discard the body.

func (*HTTPClient) PostJSON

func (h *HTTPClient) PostJSON(path string, query url.Values, body any, out any) error

PostJSON issues a POST with JSON body, unwraps the envelope, decodes data into out (nil to discard).

func (*HTTPClient) PostRaw

func (h *HTTPClient) PostRaw(path string, query url.Values, body []byte, out any) error

PostRaw issues a POST with raw bytes (caller-controlled JSON file).

type Organization

type Organization struct {
	Owner       string `json:"owner"`
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	WebsiteUrl  string `json:"websiteUrl"`
}

Organization is the CLI projection of object.Organization.

type User

type User struct {
	Owner       string `json:"owner"`
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
	Phone       string `json:"phone"`
	IsAdmin     bool   `json:"isAdmin"`
	Type        string `json:"type"`
}

User is the CLI projection of object.User — enough to print a useful table and let the operator confirm a row exists. Anything richer should go through the JSON path (`--json` or `user get`).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL