cmd

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PKG_CMD  = "cmd"
	APP_NAME = "keycloak-cli"
)

Variables

This section is empty.

Functions

func Run

func Run(version string, args []string) error

Run executes the CLI with the given version

Types

type AdminTokenCmd

type AdminTokenCmd struct {
	Username        string `help:"Admin username" default:"admin" env:"KEYCLOAK_USERNAME,KC_BOOTSTRAP_ADMIN_USERNAME"`
	Password        string `help:"Admin password" default:"admin" env:"KEYCLOAK_PASSWORD,KC_BOOTSTRAP_ADMIN_PASSWORD"`
	Realm           string `help:"Keycloak realm" default:"master" env:"KEYCLOAK_REALM"`
	SetEnv          bool   `help:"Set tokens to environment variables" default:"true"`
	AccessTokenEnv  string `help:"Set access token to this environment variable" default:"KEYCLOAK_ACCESS_TOKEN"`
	RefreshTokenEnv string `help:"Set refresh token to this environment variable" default:"KEYCLOAK_REFRESH_TOKEN"`
}

AdminTokenCmd gets Keycloak administrator access token

func (*AdminTokenCmd) Run

func (c *AdminTokenCmd) Run(ctx *kong.Context, cli *CLI) error

type CLI

type CLI struct {
	Globals    `kong:"embed"`
	Version    VersionCmd    `cmd:"" help:"Show version information"`
	Fetch      FetchCmd      `cmd:"" help:"Fetch object"`
	Compare    CompareCmd    `cmd:"" help:"Compare local manifests with fetched realm state"`
	Upload     UploadCmd     `cmd:"" help:"Upload objects"`
	Generate   GenerateCmd   `cmd:"" help:"Generate test data"`
	AdminToken AdminTokenCmd `cmd:"" help:"Get administrative access token from current instance"`
}

CLI represents the main CLI structure

func (*CLI) AfterApply

func (cli *CLI) AfterApply(ctx *kong.Context) error

AfterApply is called after Kong parses the CLI but before the command runs

type CompareCmd

type CompareCmd struct {
	InputFiles []string `arg:"" help:"Input JSON/YAML files to compare against Keycloak state"`
	Realm      string   `short:"r" help:"Realm to compare. If not provided, infer it from the manifests."`
	Format     string   `short:"f" default:"table" enum:"table,json,yaml" help:"Output format"`
	Output     string   `short:"o" help:"Output file or directory for comparison report (ends with / for directory)"`
	Force      bool     `help:"Force overwrite of output file" default:"false"`
}

func (*CompareCmd) Run

func (c *CompareCmd) Run(ctx *kong.Context, cli *CLI) error

type FetchCmd

type FetchCmd struct {
	Long          bool     `short:"l" help:"Show detailed information about objects" default:"false"`
	Format        string   `short:"f" default:"table" enum:"table,json,yaml,toml" help:"Output format"`
	Output        string   `short:"o" help:"Output file or directory for fetched resources (ends with / for directory)"`
	Force         bool     `help:"Force overwrite of output file if it exists" default:"false"`
	ExcludeFields []string `short:"e" help:"Comma-separated list of fields to exclude from output" default:"containerId"`
	Realm         string   `short:"r" help:"Realm to scope the resource fetch to. If not provided, all realms will be used."`
	Resources     string   `` /* 144-byte string literal not displayed */
	Filter        string   `arg:"" optional:"" name:"filter" help:"Filter fetched resources by exact name or id (case-insensitive)"`
	Search        string   `short:"s" help:"Search parameter for filtering resources"`
	Max           int      `help:"Maximum number of results to return"`
	Depth         int      `help:"Fetch child resources up to N levels deep" default:"1"`
	Parent        string   `short:"p" help:"Parent resource identifier for nested resources (e.g. authentication flow alias for executions)"`
	Relationships bool     `help:"Fetch supported relationship state in addition to resources" default:"false"`
	Canonicalize  bool     `help:"Strip server-managed fields and write a clean manifest suitable for re-apply" default:"false"`
}

FetchCmd gets objects

func (*FetchCmd) Run

func (c *FetchCmd) Run(ctx *kong.Context, cli *CLI) error

type GenerateCmd

type GenerateCmd struct {
	Output                  string `short:"o" help:"Output file or directory (ends with / for directory)"`
	Format                  string `short:"f" default:"json" enum:"json,yaml,toml" help:"Output format"`
	Realm                   string `short:"r" help:"Name of the realm to generate" default:"test-realm"`
	WithUsers               int    `help:"Number of users to generate" default:"1"`
	WithClients             int    `help:"Number of clients to generate" default:"1"`
	WithRoles               int    `help:"Number of roles to generate" default:"1"`
	WithGroups              int    `help:"Number of groups to generate" default:"1"`
	WithOrganizations       int    `help:"Number of organizations to generate" default:"1"`
	WithIdentityProviders   int    `help:"Number of identity providers to generate" default:"1"`
	WithClientScopes        int    `help:"Number of client scopes to generate" default:"1"`
	WithAuthenticationFlows int    `help:"Number of authentication flows to generate" default:"1"`
	WithPasswordPolicies    int    `help:"Number of password policies to generate" default:"1"`
	WithSecurityDefenses    int    `help:"Generate security defenses configuration" default:"1"`
	Summary                 bool   `help:"Generate summary" default:"false"`
	Overwrite               bool   `help:"Overwrite existing files" default:"false"`
}

GenerateCmd generates a complete Keycloak realm configuration with all resources

func (*GenerateCmd) Run

func (c *GenerateCmd) Run(_ *kong.Context, cli *CLI) error

Run executes the generate command

func (*GenerateCmd) Validate

func (c *GenerateCmd) Validate() error

Validate validates the command options

type Globals

type Globals struct {
	LogLevel        string        `help:"Log level (trace,debug,info,warn,error)" default:"info"`
	LogFormat       string        `help:"Log format (console,json)" default:"console"`
	KeycloakBaseURL string        `short:"u" help:"Keycloak base URL" default:"http://localhost:8080"`
	Timeout         time.Duration `short:"t" help:"Request timeout duration" default:"5s"`
	SpecPath        string        `help:"Path to the Keycloak OpenAPI specification file" default:"keycloak-oapi/26.6.2.spec.json"`
}

func (*Globals) CreateContextWithTimeout

func (g *Globals) CreateContextWithTimeout() (context.Context, context.CancelFunc)

CreateContextWithTimeout creates a context with the configured timeout

type UploadCmd

type UploadCmd struct {
	InputFiles      []string `arg:"" help:"Input JSON/YAML files to upload"`
	DryRun          bool     `help:"Show what would be uploaded without actually doing it" default:"false"`
	ContinueOnError bool     `help:"Continue uploading other resources if one fails" default:"false"`
	Format          string   `short:"f" default:"table" enum:"table,json,yaml" help:"Output format"`
	Output          string   `short:"o" help:"Output file or directory for upload results (ends with / for directory)"`
	Force           bool     `help:"Force overwrite of output file" default:"false"`
	Delete          bool     `help:"Delete resources regardless if they are marked for deletion or not" default:"false"`
}

UploadCmd uploads objects to Keycloak

func (*UploadCmd) Run

func (c *UploadCmd) Run(ctx *kong.Context, cli *CLI) error

type VersionCmd

type VersionCmd struct{}

VersionCmd shows version information

func (*VersionCmd) Run

func (v *VersionCmd) Run(name, version string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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