diff --git a/.adder.yaml b/.adder.yaml new file mode 100644 index 00000000..d24196cc --- /dev/null +++ b/.adder.yaml @@ -0,0 +1,10 @@ +# Adder configuration file +# See https://github.com/jrschumacher/adder for documentation + +binary_name: otdfctl +input: docs/man +output: cmd/generated +package: generated +generated_file_suffix: _generated.go +index_format: _index +package_strategy: directory diff --git a/Makefile b/Makefile index b9191ae9..87c88c7c 100644 --- a/Makefile +++ b/Makefile @@ -93,3 +93,33 @@ test-bats: build-test .PHONY: clean clean: rm -rf $(TARGET_DIR) + +# Target for generating CLI commands from documentation +# NOTE: Generated files require manual implementation of handler interfaces +# and should be committed to the repository after implementation +.PHONY: generate +generate: + go run github.com/jrschumacher/adder/cmd/adder@v0.1.1 generate -o cmd/generated + +# Target for cleaning generated files +.PHONY: clean-generated +clean-generated: + rm -rf cmd/generated/ + +# Target for regenerating (clean + generate) +# WARNING: This will remove existing generated files - ensure handlers are implemented elsewhere +.PHONY: regenerate +regenerate: clean-generated generate + +# Target for checking required tools are available +.PHONY: toolcheck +toolcheck: + @echo "Checking required tools..." + @command -v go >/dev/null 2>&1 || { echo >&2 "go is required but not installed. Visit https://golang.org/dl/"; exit 1; } + @echo "✓ go is available" + @go version 2>/dev/null | grep -q "go1\." || { echo >&2 "go version check failed"; exit 1; } + @echo "✓ go version is compatible" + @go run github.com/jrschumacher/adder/cmd/adder@v0.1.1 version >/dev/null 2>&1 || { echo >&2 "adder tool check failed. Run 'go mod download' to ensure dependencies are available."; exit 1; } + @echo "✓ adder is available" + @command -v bats >/dev/null 2>&1 || echo "⚠ bats is not installed (required for e2e tests). Install with: brew install bats-core" + @echo "All required tools are available!" diff --git a/cmd/config.go b/cmd/config.go index 7f0c35d6..56c78989 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -3,18 +3,19 @@ package cmd import ( "fmt" + configgenerated "github.com/opentdf/otdfctl/cmd/generated/config" "github.com/opentdf/otdfctl/pkg/cli" "github.com/opentdf/otdfctl/pkg/config" - "github.com/opentdf/otdfctl/pkg/man" "github.com/spf13/cobra" ) -func config_updateOutput(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) +// handleConfigOutput implements the business logic for the config output command +func handleConfigOutput(cmd *cobra.Command, req *configgenerated.OutputRequest) error { + c := cli.New(cmd, []string{}) h := NewHandler(c) defer h.Close() - format := c.Flags.GetRequiredString("format") + format := req.Flags.Format err := config.UpdateOutputFormat(cfgKey, format) if err != nil { @@ -22,20 +23,22 @@ func config_updateOutput(cmd *cobra.Command, args []string) { } c.Println(cli.SuccessMessage(fmt.Sprintf("Output format updated to %s", format))) + return nil +} + +// handleConfig implements the parent config command (shows help if called without subcommands) +func handleConfig(cmd *cobra.Command, req *configgenerated.ConfigRequest) error { + return cmd.Help() } func init() { - outputCmd := man.Docs.GetCommand("config/output", - man.WithRun(config_updateOutput), - ) - outputCmd.Flags().String( - outputCmd.GetDocFlag("format").Name, - outputCmd.GetDocFlag("format").Default, - outputCmd.GetDocFlag("format").Description, - ) - - cmd := man.Docs.GetCommand("config", - man.WithSubcommands(outputCmd), - ) - RootCmd.AddCommand(&cmd.Command) + // Create commands using generated constructors with handler functions + configCmd := configgenerated.NewConfigCommand(handleConfig) + outputCmd := configgenerated.NewOutputCommand(handleConfigOutput) + + // Add subcommand to parent + configCmd.AddCommand(outputCmd) + + // Add to root command + RootCmd.AddCommand(configCmd) } diff --git a/cmd/dev-selectors.go b/cmd/dev-selectors.go index 1b949a1f..d129602e 100644 --- a/cmd/dev-selectors.go +++ b/cmd/dev-selectors.go @@ -2,19 +2,21 @@ package cmd import ( "fmt" + "strings" + selectorsgenerated "github.com/opentdf/otdfctl/cmd/generated/dev/selectors" "github.com/opentdf/otdfctl/pkg/cli" "github.com/opentdf/otdfctl/pkg/handlers" - "github.com/opentdf/otdfctl/pkg/man" "github.com/spf13/cobra" ) var selectors []string -func dev_selectorsGen(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - h := NewHandler(c) - defer h.Close() +// handleDevSelectorsGenerate implements the business logic for the generate command +func handleDevSelectorsGenerate(cmd *cobra.Command, req *selectorsgenerated.GenerateRequest) error { + c := cli.New(cmd, []string{}) + handler := NewHandler(c) + defer handler.Close() subject := c.Flags.GetRequiredString("subject") @@ -30,15 +32,26 @@ func dev_selectorsGen(cmd *cobra.Command, args []string) { t := cli.NewTabular(rows...) cli.PrintSuccessTable(cmd, "", t) + return nil } -func dev_selectorsTest(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - h := NewHandler(c) - defer h.Close() +// handleDevSelectorsTest implements the business logic for the test command +func handleDevSelectorsTest(cmd *cobra.Command, req *selectorsgenerated.TestRequest) error { + c := cli.New(cmd, []string{}) + handler := NewHandler(c) + defer handler.Close() subject := c.Flags.GetRequiredString("subject") - selectors = c.Flags.GetStringSlice("selector", selectors, cli.FlagsStringSliceOptions{Min: 1}) + + // Convert single selector string to slice for compatibility with existing logic + var selectorsList []string + if req.Flags.Selector != "" { + selectorsList = strings.Split(req.Flags.Selector, ",") + } + + if len(selectorsList) == 0 { + cli.ExitWithError("Must provide at least one selector", nil) + } flattened, err := handlers.FlattenSubjectContext(subject) if err != nil { @@ -47,7 +60,8 @@ func dev_selectorsTest(cmd *cobra.Command, args []string) { rows := [][]string{} for _, item := range flattened { - for _, selector := range selectors { + for _, selector := range selectorsList { + selector = strings.TrimSpace(selector) if selector == item.Key { rows = append(rows, []string{item.Key, fmt.Sprintf("%v", item.Value)}) } @@ -56,40 +70,31 @@ func dev_selectorsTest(cmd *cobra.Command, args []string) { t := cli.NewTabular(rows...) cli.PrintSuccessTable(cmd, "", t) + return nil } func init() { - genCmd := man.Docs.GetCommand("dev/selectors/generate", - man.WithRun(dev_selectorsGen), - ) - genCmd.Flags().StringP( - genCmd.GetDocFlag("subject").Name, - genCmd.GetDocFlag("subject").Shorthand, - genCmd.GetDocFlag("subject").Default, - genCmd.GetDocFlag("subject").Description, - ) - - testCmd := man.Docs.GetCommand("dev/selectors/test", - man.WithRun(dev_selectorsTest), - ) - testCmd.Flags().StringP( - testCmd.GetDocFlag("subject").Name, - testCmd.GetDocFlag("subject").Shorthand, - testCmd.GetDocFlag("subject").Default, - testCmd.GetDocFlag("subject").Description, - ) - testCmd.Flags().StringSliceVarP( - &selectors, - testCmd.GetDocFlag("selector").Name, - testCmd.GetDocFlag("selector").Shorthand, - []string{}, - testCmd.GetDocFlag("selector").Description, - ) - - doc := man.Docs.GetCommand("dev/selectors", - man.WithSubcommands(genCmd, testCmd), - ) - - dev_selectorsCmd := &doc.Command - devCmd.AddCommand(dev_selectorsCmd) + // Create commands using generated code with handler functions + genCmd := selectorsgenerated.NewGenerateCommand(handleDevSelectorsGenerate) + testCmd := selectorsgenerated.NewTestCommand(handleDevSelectorsTest) + + // Create selectors parent command + selectorsCmd := &cobra.Command{ + Use: "selectors", + Aliases: []string{"sel"}, + Short: "Selectors", + RunE: func(cmd *cobra.Command, args []string) error { + return cmd.Help() + }, + } + + // Add subcommands + selectorsCmd.AddCommand(genCmd) + selectorsCmd.AddCommand(testCmd) + + // Export for use by dev.go + DevSelectorsCmd = selectorsCmd } + +// DevSelectorsCmd exports the selectors command for use by dev.go +var DevSelectorsCmd *cobra.Command diff --git a/cmd/dev.go b/cmd/dev.go index 82abcbe0..da3c8008 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -15,9 +15,6 @@ import ( "github.com/spf13/cobra" ) -// devCmd is the command for playground-style development -var devCmd = man.Docs.GetCommand("dev") - var ( metadataLabels []string defaultListFlagLimit int32 = 300 @@ -153,9 +150,24 @@ func readPipedStdin() []byte { } func init() { + // Create dev command + devCmd := &cobra.Command{ + Use: "dev", + Short: "Development Tools", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return cmd.Help() + }, + } + + // Create design-system subcommand using manual approach (complex UI logic) designCmd := man.Docs.GetCommand("dev/design-system", man.WithRun(dev_designSystem), ) devCmd.AddCommand(&designCmd.Command) - RootCmd.AddCommand(&devCmd.Command) + + // Add selectors subcommand (from dev-selectors.go) + devCmd.AddCommand(DevSelectorsCmd) + + RootCmd.AddCommand(devCmd) } diff --git a/cmd/generated/_index_generated.go b/cmd/generated/_index_generated.go new file mode 100644 index 00000000..6bd9a217 --- /dev/null +++ b/cmd/generated/_index_generated.go @@ -0,0 +1,109 @@ +// Code generated by adder. DO NOT EDIT. + +package generated + +import ( + + "github.com/spf13/cobra" +) + +// OtdfctlRequestFlags represents the flags for the otdfctl command +type OtdfctlRequestFlags struct { + Version bool `json:"version"` // show version +} +// OtdfctlRequestPersistentFlags represents the persistent flags for the otdfctl command +type OtdfctlRequestPersistentFlags struct { + Profile string `json:"profile"` // profile to use for interacting with the platform + Host string `json:"host"` // Hostname of the platform (i.e. https://localhost) + TlsNoVerify bool `json:"tlsNoVerify"` // disable verification of the server's TLS certificate + LogLevel string `json:"logLevel" validate:"oneof=debug info warn error fatal panic"` // log level + WithAccessToken string `json:"withAccessToken"` // access token for authentication via bearer token + WithClientCredsFile string `json:"withClientCredsFile"` // path to a JSON file containing a 'clientId' and 'clientSecret' for auth via client-credentials flow + WithClientCreds string `json:"withClientCreds"` // JSON string containing a 'clientId' and 'clientSecret' for auth via client-credentials flow + Json bool `json:"json"` // output in JSON format + Debug bool `json:"debug"` // enable debug output +} + +// OtdfctlRequest represents the parameters for the otdfctl command +type OtdfctlRequest struct { + Flags OtdfctlRequestFlags `json:"flags"` + PersistentFlags OtdfctlRequestPersistentFlags `json:"persistent_flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// OtdfctlHandler defines the function type for handling otdfctl commands +type OtdfctlHandler func(cmd *cobra.Command, req *OtdfctlRequest) error + +// NewOtdfctlCommand creates a new otdfctl command with the provided handler function +func NewOtdfctlCommand(handler OtdfctlHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "otdfctl", + Short: "otdfctl - OpenTDF Control Tool", + RunE: func(cmd *cobra.Command, args []string) error { + return runOtdfctl(cmd, args, handler) + }, + } + + // Register persistent flags + cmd.PersistentFlags().String("profile", "", "profile to use for interacting with the platform") + cmd.PersistentFlags().String("host", "", "Hostname of the platform (i.e. https://localhost)") + cmd.PersistentFlags().Bool("tls-no-verify", false, "disable verification of the server's TLS certificate") + cmd.PersistentFlags().String("log-level", "info", "log level") + cmd.PersistentFlags().String("with-access-token", "", "access token for authentication via bearer token") + cmd.PersistentFlags().String("with-client-creds-file", "", "path to a JSON file containing a 'clientId' and 'clientSecret' for auth via client-credentials flow") + cmd.PersistentFlags().String("with-client-creds", "", "JSON string containing a 'clientId' and 'clientSecret' for auth via client-credentials flow") + cmd.PersistentFlags().Bool("json", false, "output in JSON format") + cmd.PersistentFlags().Bool("debug", false, "enable debug output") + + // Register flags + cmd.Flags().Bool("version", false, "show version") + + return cmd +} + +// runOtdfctl handles argument and flag extraction +func runOtdfctl(cmd *cobra.Command, args []string, handler OtdfctlHandler) error { + version, _ := cmd.Flags().GetBool("version") + profile, _ := cmd.PersistentFlags().GetString("profile") + host, _ := cmd.PersistentFlags().GetString("host") + tlsNoVerify, _ := cmd.PersistentFlags().GetBool("tls-no-verify") + logLevel, _ := cmd.PersistentFlags().GetString("log-level") + withAccessToken, _ := cmd.PersistentFlags().GetString("with-access-token") + withClientCredsFile, _ := cmd.PersistentFlags().GetString("with-client-creds-file") + withClientCreds, _ := cmd.PersistentFlags().GetString("with-client-creds") + json, _ := cmd.PersistentFlags().GetBool("json") + debug, _ := cmd.PersistentFlags().GetBool("debug") + // Validate enum for log-level + logLevelValid := false + for _, validValue := range []string{"debug", "info", "warn", "error", "fatal", "panic"} { + if logLevel == validValue { + logLevelValid = true + break + } + } + if !logLevelValid { + return fmt.Errorf("invalid log-level: %s (must be debug, info, warn, error, fatal, or panic)", logLevel) + } + + // Create request + req := &OtdfctlRequest{ + Flags: OtdfctlRequestFlags{ + Version: version, + }, + PersistentFlags: OtdfctlRequestPersistentFlags{ + Profile: profile, + Host: host, + TlsNoVerify: tlsNoVerify, + LogLevel: logLevel, + WithAccessToken: withAccessToken, + WithClientCredsFile: withClientCredsFile, + WithClientCreds: withClientCreds, + Json: json, + Debug: debug, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/_index_generated.go b/cmd/generated/auth/_index_generated.go new file mode 100644 index 00000000..bcfbf25c --- /dev/null +++ b/cmd/generated/auth/_index_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + + +// AuthRequest represents the parameters for the auth command +type AuthRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AuthHandler defines the function type for handling auth commands +type AuthHandler func(cmd *cobra.Command, req *AuthRequest) error + +// NewAuthCommand creates a new auth command with the provided handler function +func NewAuthCommand(handler AuthHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "auth", + Short: "Manage local authentication session", + RunE: func(cmd *cobra.Command, args []string) error { + return runAuth(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runAuth handles argument and flag extraction +func runAuth(cmd *cobra.Command, args []string, handler AuthHandler) error { + + // Create request + req := &AuthRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/clear-client-credentials_generated.go b/cmd/generated/auth/clear-client-credentials_generated.go new file mode 100644 index 00000000..7b19968a --- /dev/null +++ b/cmd/generated/auth/clear-client-credentials_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + +// ClearClientCredentialsRequestFlags represents the flags for the clear-client-credentials command +type ClearClientCredentialsRequestFlags struct { + All string `json:"all"` // Deprecated -- see the `profile` subcommand +} + +// ClearClientCredentialsRequest represents the parameters for the clear-client-credentials command +type ClearClientCredentialsRequest struct { + Flags ClearClientCredentialsRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ClearClientCredentialsHandler defines the function type for handling clear-client-credentials commands +type ClearClientCredentialsHandler func(cmd *cobra.Command, req *ClearClientCredentialsRequest) error + +// NewClearClientCredentialsCommand creates a new clear-client-credentials command with the provided handler function +func NewClearClientCredentialsCommand(handler ClearClientCredentialsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "clear-client-credentials", + Short: "Clear the cached client credentials", + RunE: func(cmd *cobra.Command, args []string) error { + return runClearClientCredentials(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("all", "%!s(bool=false)", "Deprecated -- see the `profile` subcommand") + + return cmd +} + +// runClearClientCredentials handles argument and flag extraction +func runClearClientCredentials(cmd *cobra.Command, args []string, handler ClearClientCredentialsHandler) error { + all, _ := cmd.Flags().GetString("all") + + // Create request + req := &ClearClientCredentialsRequest{ + Flags: ClearClientCredentialsRequestFlags{ + All: all, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/client-credentials_generated.go b/cmd/generated/auth/client-credentials_generated.go new file mode 100644 index 00000000..0c7eca81 --- /dev/null +++ b/cmd/generated/auth/client-credentials_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + + +// ClientCredentialsRequest represents the parameters for the client-credentials command +type ClientCredentialsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ClientCredentialsHandler defines the function type for handling client-credentials commands +type ClientCredentialsHandler func(cmd *cobra.Command, req *ClientCredentialsRequest) error + +// NewClientCredentialsCommand creates a new client-credentials command with the provided handler function +func NewClientCredentialsCommand(handler ClientCredentialsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "client-credentials", + Short: "Authenticate to the platform with the client-credentials flow", + RunE: func(cmd *cobra.Command, args []string) error { + return runClientCredentials(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runClientCredentials handles argument and flag extraction +func runClientCredentials(cmd *cobra.Command, args []string, handler ClientCredentialsHandler) error { + + // Create request + req := &ClientCredentialsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/login_generated.go b/cmd/generated/auth/login_generated.go new file mode 100644 index 00000000..b91f02d9 --- /dev/null +++ b/cmd/generated/auth/login_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + +// LoginRequestFlags represents the flags for the login command +type LoginRequestFlags struct { + ClientId string `json:"clientId"` // A clientId for use in auth code flow (default = platform well-known public_client_id) +} + +// LoginRequest represents the parameters for the login command +type LoginRequest struct { + Flags LoginRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// LoginHandler defines the function type for handling login commands +type LoginHandler func(cmd *cobra.Command, req *LoginRequest) error + +// NewLoginCommand creates a new login command with the provided handler function +func NewLoginCommand(handler LoginHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "login", + Short: "Open a browser and login", + RunE: func(cmd *cobra.Command, args []string) error { + return runLogin(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("client-id", "i", "", "A clientId for use in auth code flow (default = platform well-known public_client_id)") + cmd.MarkFlagRequired("client-id") + + return cmd +} + +// runLogin handles argument and flag extraction +func runLogin(cmd *cobra.Command, args []string, handler LoginHandler) error { + clientId, _ := cmd.Flags().GetString("client-id") + + // Create request + req := &LoginRequest{ + Flags: LoginRequestFlags{ + ClientId: clientId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/logout_generated.go b/cmd/generated/auth/logout_generated.go new file mode 100644 index 00000000..bdfa64d4 --- /dev/null +++ b/cmd/generated/auth/logout_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + + +// LogoutRequest represents the parameters for the logout command +type LogoutRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// LogoutHandler defines the function type for handling logout commands +type LogoutHandler func(cmd *cobra.Command, req *LogoutRequest) error + +// NewLogoutCommand creates a new logout command with the provided handler function +func NewLogoutCommand(handler LogoutHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "logout", + Short: "Clear credentials from profile", + RunE: func(cmd *cobra.Command, args []string) error { + return runLogout(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runLogout handles argument and flag extraction +func runLogout(cmd *cobra.Command, args []string, handler LogoutHandler) error { + + // Create request + req := &LogoutRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/auth/print-access-token_generated.go b/cmd/generated/auth/print-access-token_generated.go new file mode 100644 index 00000000..821b64df --- /dev/null +++ b/cmd/generated/auth/print-access-token_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package auth + +import ( + + "github.com/spf13/cobra" +) + +// PrintAccessTokenRequestFlags represents the flags for the print-access-token command +type PrintAccessTokenRequestFlags struct { + Json string `json:"json"` // Print the full token in JSON format +} + +// PrintAccessTokenRequest represents the parameters for the print-access-token command +type PrintAccessTokenRequest struct { + Flags PrintAccessTokenRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// PrintAccessTokenHandler defines the function type for handling print-access-token commands +type PrintAccessTokenHandler func(cmd *cobra.Command, req *PrintAccessTokenRequest) error + +// NewPrintAccessTokenCommand creates a new print-access-token command with the provided handler function +func NewPrintAccessTokenCommand(handler PrintAccessTokenHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "print-access-token", + Short: "Print the cached OIDC access token (if found)", + RunE: func(cmd *cobra.Command, args []string) error { + return runPrintAccessToken(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("json", "%!s(bool=false)", "Print the full token in JSON format") + + return cmd +} + +// runPrintAccessToken handles argument and flag extraction +func runPrintAccessToken(cmd *cobra.Command, args []string, handler PrintAccessTokenHandler) error { + json, _ := cmd.Flags().GetString("json") + + // Create request + req := &PrintAccessTokenRequest{ + Flags: PrintAccessTokenRequestFlags{ + Json: json, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/config/_index_generated.go b/cmd/generated/config/_index_generated.go new file mode 100644 index 00000000..10dffcdd --- /dev/null +++ b/cmd/generated/config/_index_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package config + +import ( + + "github.com/spf13/cobra" +) + + +// ConfigRequest represents the parameters for the config command +type ConfigRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ConfigHandler defines the function type for handling config commands +type ConfigHandler func(cmd *cobra.Command, req *ConfigRequest) error + +// NewConfigCommand creates a new config command with the provided handler function +func NewConfigCommand(handler ConfigHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "config", + Short: "Manage Configuration", + RunE: func(cmd *cobra.Command, args []string) error { + return runConfig(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runConfig handles argument and flag extraction +func runConfig(cmd *cobra.Command, args []string, handler ConfigHandler) error { + + // Create request + req := &ConfigRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/config/config_generated.go b/cmd/generated/config/config_generated.go new file mode 100644 index 00000000..5ba7f1d1 --- /dev/null +++ b/cmd/generated/config/config_generated.go @@ -0,0 +1,42 @@ +// Code generated by adder. DO NOT EDIT. + +package config + +import ( + + "github.com/spf13/cobra" +) + + +// ConfigRequest represents the parameters for the config command +type ConfigRequest struct { +} + +// ConfigHandler defines the function type for handling config commands +type ConfigHandler func(cmd *cobra.Command, req *ConfigRequest) error + +// NewConfigCommand creates a new config command with the provided handler function +func NewConfigCommand(handler ConfigHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "config", + Short: "Manage Configuration", + RunE: func(cmd *cobra.Command, args []string) error { + return runConfig(cmd, args, handler) + }, + } + + // Register flags + + return cmd +} + +// runConfig handles argument and flag extraction +func runConfig(cmd *cobra.Command, args []string, handler ConfigHandler) error { + + // Create request + req := &ConfigRequest{ + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/config/output_generated.go b/cmd/generated/config/output_generated.go new file mode 100644 index 00000000..d6dedf8b --- /dev/null +++ b/cmd/generated/config/output_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package config + +import ( + + "github.com/spf13/cobra" +) + +// OutputRequestFlags represents the flags for the output command +type OutputRequestFlags struct { + Format string `json:"format"` // 'json' or 'styled' as the configured output format +} + +// OutputRequest represents the parameters for the output command +type OutputRequest struct { + Flags OutputRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// OutputHandler defines the function type for handling output commands +type OutputHandler func(cmd *cobra.Command, req *OutputRequest) error + +// NewOutputCommand creates a new output command with the provided handler function +func NewOutputCommand(handler OutputHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "output", + Short: "Define the configured output format", + RunE: func(cmd *cobra.Command, args []string) error { + return runOutput(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("format", "styled", "'json' or 'styled' as the configured output format") + + return cmd +} + +// runOutput handles argument and flag extraction +func runOutput(cmd *cobra.Command, args []string, handler OutputHandler) error { + format, _ := cmd.Flags().GetString("format") + + // Create request + req := &OutputRequest{ + Flags: OutputRequestFlags{ + Format: format, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/decrypt/_index_generated.go b/cmd/generated/decrypt/_index_generated.go new file mode 100644 index 00000000..f7909e83 --- /dev/null +++ b/cmd/generated/decrypt/_index_generated.go @@ -0,0 +1,92 @@ +// Code generated by adder. DO NOT EDIT. + +package decrypt + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// DecryptRequestFlags represents the flags for the decrypt [file] command +type DecryptRequestFlags struct { + Out string `json:"out"` // The file destination for decrypted content to be written instead of stdout. + TdfType string `json:"tdfType"` // Deprecated. TDF type is now auto-detected. + NoVerifyAssertions string `json:"noVerifyAssertions"` // disable verification of assertions + SessionKeyAlgorithm string `json:"sessionKeyAlgorithm" validate:"oneof=rsa:2048 ec:secp256r1 ec:secp384r1 ec:secp521r1"` // EXPERIMENTAL: The type of session key algorithm to use for decryption + + WithAssertionVerificationKeys string `json:"withAssertionVerificationKeys"` // EXPERIMENTAL: path to JSON file of keys to verify signed assertions. See examples for more information. + + KasAllowlist string `json:"kasAllowlist"` // A custom allowlist of comma-separated KAS Urls, e.g. `https://example.com/kas,http://localhost:8080`. If none specified, the platform will use the list of KASes in the KAS registry. To ignore the allowlist, use a quoted wildcard e.g. `--kas-allowlist '*'` **WARNING:** Bypassing the allowlist may expose you to potential security risks, as untrusted KAS URLs could be used. +} + +// DecryptRequest represents the parameters for the decrypt [file] command +type DecryptRequest struct { + Flags DecryptRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DecryptHandler defines the function type for handling decrypt [file] commands +type DecryptHandler func(cmd *cobra.Command, req *DecryptRequest) error + +// NewDecryptCommand creates a new decrypt [file] command with the provided handler function +func NewDecryptCommand(handler DecryptHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "decrypt", + Short: "Decrypt a TDF file", + RunE: func(cmd *cobra.Command, args []string) error { + return runDecrypt(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("out", "o", "", "The file destination for decrypted content to be written instead of stdout.") + cmd.Flags().StringP("tdf-type", "t", "", "Deprecated. TDF type is now auto-detected.") + cmd.Flags().String("no-verify-assertions", "%!s(bool=false)", "disable verification of assertions") + cmd.Flags().String("session-key-algorithm", "rsa:2048", "EXPERIMENTAL: The type of session key algorithm to use for decryption +") + cmd.Flags().String("with-assertion-verification-keys", "", "EXPERIMENTAL: path to JSON file of keys to verify signed assertions. See examples for more information. +") + cmd.Flags().String("kas-allowlist", "", "A custom allowlist of comma-separated KAS Urls, e.g. `https://example.com/kas,http://localhost:8080`. If none specified, the platform will use the list of KASes in the KAS registry. To ignore the allowlist, use a quoted wildcard e.g. `--kas-allowlist '*'` **WARNING:** Bypassing the allowlist may expose you to potential security risks, as untrusted KAS URLs could be used.") + + return cmd +} + +// runDecrypt handles argument and flag extraction +func runDecrypt(cmd *cobra.Command, args []string, handler DecryptHandler) error { + out, _ := cmd.Flags().GetString("out") + tdfType, _ := cmd.Flags().GetString("tdf-type") + noVerifyAssertions, _ := cmd.Flags().GetString("no-verify-assertions") + sessionKeyAlgorithm, _ := cmd.Flags().GetString("session-key-algorithm") + withAssertionVerificationKeys, _ := cmd.Flags().GetString("with-assertion-verification-keys") + kasAllowlist, _ := cmd.Flags().GetString("kas-allowlist") + // Validate enum for session-key-algorithm + sessionKeyAlgorithmValid := false + for _, validValue := range []string{"rsa:2048", "ec:secp256r1", "ec:secp384r1", "ec:secp521r1"} { + if sessionKeyAlgorithm == validValue { + sessionKeyAlgorithmValid = true + break + } + } + if !sessionKeyAlgorithmValid { + return fmt.Errorf("invalid session-key-algorithm: %s (must be rsa:2048, ec:secp256r1, ec:secp384r1, or ec:secp521r1)", sessionKeyAlgorithm) + } + + // Create request + req := &DecryptRequest{ + Flags: DecryptRequestFlags{ + Out: out, + TdfType: tdfType, + NoVerifyAssertions: noVerifyAssertions, + SessionKeyAlgorithm: sessionKeyAlgorithm, + WithAssertionVerificationKeys: withAssertionVerificationKeys, + KasAllowlist: kasAllowlist, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/decrypt/decrypt_generated.go b/cmd/generated/decrypt/decrypt_generated.go new file mode 100644 index 00000000..b4283d99 --- /dev/null +++ b/cmd/generated/decrypt/decrypt_generated.go @@ -0,0 +1,88 @@ +// Code generated by adder. DO NOT EDIT. + +package decrypt + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// DecryptRequestFlags represents the flags for the decrypt [file] command +type DecryptRequestFlags struct { + Out string `json:"out"` // The file destination for decrypted content to be written instead of stdout. + TdfType string `json:"tdfType"` // Deprecated. TDF type is now auto-detected. + NoVerifyAssertions string `json:"noVerifyAssertions"` // disable verification of assertions + SessionKeyAlgorithm string `json:"sessionKeyAlgorithm" validate:"oneof=rsa:2048 ec:secp256r1 ec:secp384r1 ec:secp521r1"` // EXPERIMENTAL: The type of session key algorithm to use for decryption + + WithAssertionVerificationKeys string `json:"withAssertionVerificationKeys"` // EXPERIMENTAL: path to JSON file of keys to verify signed assertions. See examples for more information. + + KasAllowlist string `json:"kasAllowlist"` // A custom allowlist of comma-separated KAS Urls, e.g. `https://example.com/kas,http://localhost:8080`. If none specified, the platform will use the list of KASes in the KAS registry. To ignore the allowlist, use a quoted wildcard e.g. `--kas-allowlist '*'` **WARNING:** Bypassing the allowlist may expose you to potential security risks, as untrusted KAS URLs could be used. +} + +// DecryptRequest represents the parameters for the decrypt [file] command +type DecryptRequest struct { + Flags DecryptRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` +} + +// DecryptHandler defines the function type for handling decrypt [file] commands +type DecryptHandler func(cmd *cobra.Command, req *DecryptRequest) error + +// NewDecryptCommand creates a new decrypt [file] command with the provided handler function +func NewDecryptCommand(handler DecryptHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "decrypt [file]", + Short: "Decrypt a TDF file", + RunE: func(cmd *cobra.Command, args []string) error { + return runDecrypt(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("out", "o", "", "The file destination for decrypted content to be written instead of stdout.") + cmd.Flags().StringP("tdf-type", "t", "", "Deprecated. TDF type is now auto-detected.") + cmd.Flags().String("no-verify-assertions", "%!s(bool=false)", "disable verification of assertions") + cmd.Flags().String("session-key-algorithm", "rsa:2048", "EXPERIMENTAL: The type of session key algorithm to use for decryption") + cmd.Flags().String("with-assertion-verification-keys", "", "EXPERIMENTAL: path to JSON file of keys to verify signed assertions. See examples for more information.") + cmd.Flags().String("kas-allowlist", "", "A custom allowlist of comma-separated KAS Urls, e.g. `https://example.com/kas,http://localhost:8080`. If none specified, the platform will use the list of KASes in the KAS registry. To ignore the allowlist, use a quoted wildcard e.g. `--kas-allowlist '*'` **WARNING:** Bypassing the allowlist may expose you to potential security risks, as untrusted KAS URLs could be used.") + + return cmd +} + +// runDecrypt handles argument and flag extraction +func runDecrypt(cmd *cobra.Command, args []string, handler DecryptHandler) error { + out, _ := cmd.Flags().GetString("out") + tdfType, _ := cmd.Flags().GetString("tdf-type") + noVerifyAssertions, _ := cmd.Flags().GetString("no-verify-assertions") + sessionKeyAlgorithm, _ := cmd.Flags().GetString("session-key-algorithm") + withAssertionVerificationKeys, _ := cmd.Flags().GetString("with-assertion-verification-keys") + kasAllowlist, _ := cmd.Flags().GetString("kas-allowlist") + // Validate enum for session-key-algorithm + sessionKeyAlgorithmValid := false + for _, validValue := range []string{"rsa:2048", "ec:secp256r1", "ec:secp384r1", "ec:secp521r1"} { + if sessionKeyAlgorithm == validValue { + sessionKeyAlgorithmValid = true + break + } + } + if !sessionKeyAlgorithmValid { + return fmt.Errorf("invalid session-key-algorithm: %s (must be rsa:2048, ec:secp256r1, ec:secp384r1, or ec:secp521r1)", sessionKeyAlgorithm) + } + + // Create request + req := &DecryptRequest{ + Flags: DecryptRequestFlags{ + Out: out, + TdfType: tdfType, + NoVerifyAssertions: noVerifyAssertions, + SessionKeyAlgorithm: sessionKeyAlgorithm, + WithAssertionVerificationKeys: withAssertionVerificationKeys, + KasAllowlist: kasAllowlist, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/dev/_index_generated.go b/cmd/generated/dev/_index_generated.go new file mode 100644 index 00000000..a4085556 --- /dev/null +++ b/cmd/generated/dev/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package dev + +import ( + + "github.com/spf13/cobra" +) + + +// DevRequest represents the parameters for the dev command +type DevRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DevHandler defines the function type for handling dev commands +type DevHandler func(cmd *cobra.Command, req *DevRequest) error + +// NewDevCommand creates a new dev command with the provided handler function +func NewDevCommand(handler DevHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "dev", + Short: "Development Tools", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runDev(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runDev handles argument and flag extraction +func runDev(cmd *cobra.Command, args []string, handler DevHandler) error { + + // Create request + req := &DevRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/dev/design-system_generated.go b/cmd/generated/dev/design-system_generated.go new file mode 100644 index 00000000..4af202dc --- /dev/null +++ b/cmd/generated/dev/design-system_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package dev + +import ( + + "github.com/spf13/cobra" +) + + +// DesignSystemRequest represents the parameters for the design-system command +type DesignSystemRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DesignSystemHandler defines the function type for handling design-system commands +type DesignSystemHandler func(cmd *cobra.Command, req *DesignSystemRequest) error + +// NewDesignSystemCommand creates a new design-system command with the provided handler function +func NewDesignSystemCommand(handler DesignSystemHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "design-system", + Short: "Design System", + RunE: func(cmd *cobra.Command, args []string) error { + return runDesignSystem(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runDesignSystem handles argument and flag extraction +func runDesignSystem(cmd *cobra.Command, args []string, handler DesignSystemHandler) error { + + // Create request + req := &DesignSystemRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/dev/selectors/_index_generated.go b/cmd/generated/dev/selectors/_index_generated.go new file mode 100644 index 00000000..8ce790db --- /dev/null +++ b/cmd/generated/dev/selectors/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package dev_selectors + +import ( + + "github.com/spf13/cobra" +) + + +// SelectorsRequest represents the parameters for the selectors command +type SelectorsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SelectorsHandler defines the function type for handling selectors commands +type SelectorsHandler func(cmd *cobra.Command, req *SelectorsRequest) error + +// NewSelectorsCommand creates a new selectors command with the provided handler function +func NewSelectorsCommand(handler SelectorsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "selectors", + Aliases: []string{"sel"}, + Short: "Selectors", + RunE: func(cmd *cobra.Command, args []string) error { + return runSelectors(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runSelectors handles argument and flag extraction +func runSelectors(cmd *cobra.Command, args []string, handler SelectorsHandler) error { + + // Create request + req := &SelectorsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/dev/selectors/generate_generated.go b/cmd/generated/dev/selectors/generate_generated.go new file mode 100644 index 00000000..d6948938 --- /dev/null +++ b/cmd/generated/dev/selectors/generate_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package dev_selectors + +import ( + + "github.com/spf13/cobra" +) + +// GenerateRequestFlags represents the flags for the generate command +type GenerateRequestFlags struct { + Subject string `json:"subject"` // A Subject Context string (JSON or JWT, default JSON) +} + +// GenerateRequest represents the parameters for the generate command +type GenerateRequest struct { + Flags GenerateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GenerateHandler defines the function type for handling generate commands +type GenerateHandler func(cmd *cobra.Command, req *GenerateRequest) error + +// NewGenerateCommand creates a new generate command with the provided handler function +func NewGenerateCommand(handler GenerateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "generate", + Aliases: []string{"gen"}, + Short: "Generate a set of selector expressions for keys and values of a Subject Context", + RunE: func(cmd *cobra.Command, args []string) error { + return runGenerate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("subject", "s", "", "A Subject Context string (JSON or JWT, default JSON)") + + return cmd +} + +// runGenerate handles argument and flag extraction +func runGenerate(cmd *cobra.Command, args []string, handler GenerateHandler) error { + subject, _ := cmd.Flags().GetString("subject") + + // Create request + req := &GenerateRequest{ + Flags: GenerateRequestFlags{ + Subject: subject, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/dev/selectors/test_generated.go b/cmd/generated/dev/selectors/test_generated.go new file mode 100644 index 00000000..6abcc23c --- /dev/null +++ b/cmd/generated/dev/selectors/test_generated.go @@ -0,0 +1,60 @@ +// Code generated by adder. DO NOT EDIT. + +package dev_selectors + +import ( + + "github.com/spf13/cobra" +) + +// TestRequestFlags represents the flags for the test command +type TestRequestFlags struct { + Subject string `json:"subject"` // A Subject Context string (JSON or JWT, auto-detected) + Selector string `json:"selector"` // Individual selectors to test against the Subject Context (i.e. '.key,.realm_access.roles[]') +} + +// TestRequest represents the parameters for the test command +type TestRequest struct { + Flags TestRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// TestHandler defines the function type for handling test commands +type TestHandler func(cmd *cobra.Command, req *TestRequest) error + +// NewTestCommand creates a new test command with the provided handler function +func NewTestCommand(handler TestHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "test", + Short: "Test resolution of a set of selector expressions for keys and values of a Subject Context.", + RunE: func(cmd *cobra.Command, args []string) error { + return runTest(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("subject", "s", "", "A Subject Context string (JSON or JWT, auto-detected)") + cmd.Flags().StringP("selector", "x", "", "Individual selectors to test against the Subject Context (i.e. '.key,.realm_access.roles[]')") + + return cmd +} + +// runTest handles argument and flag extraction +func runTest(cmd *cobra.Command, args []string, handler TestHandler) error { + subject, _ := cmd.Flags().GetString("subject") + selector, _ := cmd.Flags().GetString("selector") + + // Create request + req := &TestRequest{ + Flags: TestRequestFlags{ + Subject: subject, + Selector: selector, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/encrypt/_index_generated.go b/cmd/generated/encrypt/_index_generated.go new file mode 100644 index 00000000..f46a38ff --- /dev/null +++ b/cmd/generated/encrypt/_index_generated.go @@ -0,0 +1,113 @@ +// Code generated by adder. DO NOT EDIT. + +package encrypt + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// EncryptRequestFlags represents the flags for the encrypt [file] command +type EncryptRequestFlags struct { + Out string `json:"out"` // The output file TDF in the current working directory instead of stdout ('-o file.txt' and '-o file.txt.tdf' both write the TDF as file.txt.tdf). + Attr string `json:"attr"` // Attribute value Fully Qualified Names (FQNs, i.e. 'https://example.com/attr/attr1/value/value1') to apply to the encrypted data. + WrappingKeyAlgorithm string `json:"wrappingKeyAlgorithm" validate:"oneof=rsa:2048 ec:secp256r1 ec:secp384r1 ec:secp521r1"` // EXPERIMENTAL: The algorithm to use for the wrapping key + + MimeType string `json:"mimeType"` // The MIME type of the input data. If not provided, the MIME type is inferred from the input data. + TdfType string `json:"tdfType" validate:"oneof=ztdf tdf3 nano"` // The type of tdf to encrypt as. ZTDF supports structured manifests and larger payloads. NanoTDF has a smaller footprint and more performant, but does not support structured manifests or large payloads. (tdf3 is an alias for ztdf) + EcdsaBinding string `json:"ecdsaBinding"` // For nano type containers only, enables ECDSA policy binding + KasUrlPath string `json:"kasUrlPath"` // URL path to the KAS service at the platform endpoint domain. Leading slash is required if needed. + TargetMode string `json:"targetMode"` // The target TDF spec version (e.g., \"4.3.0\"); intended for legacy compatibility and subject to removal. + WithAssertions string `json:"withAssertions"` // EXPERIMENTAL: JSON string or path to a JSON file of assertions to bind metadata to the TDF. See examples for more information. WARNING: Providing keys in a JSON string is strongly discouraged. If including sensitive keys, instead provide a path to a JSON file containing that information. +} + +// EncryptRequest represents the parameters for the encrypt [file] command +type EncryptRequest struct { + Flags EncryptRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// EncryptHandler defines the function type for handling encrypt [file] commands +type EncryptHandler func(cmd *cobra.Command, req *EncryptRequest) error + +// NewEncryptCommand creates a new encrypt [file] command with the provided handler function +func NewEncryptCommand(handler EncryptHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "encrypt", + Short: "Encrypt file or stdin as a TDF", + RunE: func(cmd *cobra.Command, args []string) error { + return runEncrypt(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("out", "o", "", "The output file TDF in the current working directory instead of stdout ('-o file.txt' and '-o file.txt.tdf' both write the TDF as file.txt.tdf).") + cmd.Flags().StringP("attr", "a", "", "Attribute value Fully Qualified Names (FQNs, i.e. 'https://example.com/attr/attr1/value/value1') to apply to the encrypted data.") + cmd.Flags().String("wrapping-key-algorithm", "rsa:2048", "EXPERIMENTAL: The algorithm to use for the wrapping key +") + cmd.Flags().String("mime-type", "", "The MIME type of the input data. If not provided, the MIME type is inferred from the input data.") + cmd.Flags().StringP("tdf-type", "t", "ztdf", "The type of tdf to encrypt as. ZTDF supports structured manifests and larger payloads. NanoTDF has a smaller footprint and more performant, but does not support structured manifests or large payloads. (tdf3 is an alias for ztdf)") + cmd.Flags().String("ecdsa-binding", "", "For nano type containers only, enables ECDSA policy binding") + cmd.Flags().String("kas-url-path", "/kas", "URL path to the KAS service at the platform endpoint domain. Leading slash is required if needed.") + cmd.Flags().String("target-mode", "", "The target TDF spec version (e.g., \"4.3.0\"); intended for legacy compatibility and subject to removal.") + cmd.Flags().String("with-assertions", "", "EXPERIMENTAL: JSON string or path to a JSON file of assertions to bind metadata to the TDF. See examples for more information. WARNING: Providing keys in a JSON string is strongly discouraged. If including sensitive keys, instead provide a path to a JSON file containing that information.") + + return cmd +} + +// runEncrypt handles argument and flag extraction +func runEncrypt(cmd *cobra.Command, args []string, handler EncryptHandler) error { + out, _ := cmd.Flags().GetString("out") + attr, _ := cmd.Flags().GetString("attr") + wrappingKeyAlgorithm, _ := cmd.Flags().GetString("wrapping-key-algorithm") + mimeType, _ := cmd.Flags().GetString("mime-type") + tdfType, _ := cmd.Flags().GetString("tdf-type") + ecdsaBinding, _ := cmd.Flags().GetString("ecdsa-binding") + kasUrlPath, _ := cmd.Flags().GetString("kas-url-path") + targetMode, _ := cmd.Flags().GetString("target-mode") + withAssertions, _ := cmd.Flags().GetString("with-assertions") + // Validate enum for wrapping-key-algorithm + wrappingKeyAlgorithmValid := false + for _, validValue := range []string{"rsa:2048", "ec:secp256r1", "ec:secp384r1", "ec:secp521r1"} { + if wrappingKeyAlgorithm == validValue { + wrappingKeyAlgorithmValid = true + break + } + } + if !wrappingKeyAlgorithmValid { + return fmt.Errorf("invalid wrapping-key-algorithm: %s (must be rsa:2048, ec:secp256r1, ec:secp384r1, or ec:secp521r1)", wrappingKeyAlgorithm) + } + // Validate enum for tdf-type + tdfTypeValid := false + for _, validValue := range []string{"ztdf", "tdf3", "nano"} { + if tdfType == validValue { + tdfTypeValid = true + break + } + } + if !tdfTypeValid { + return fmt.Errorf("invalid tdf-type: %s (must be ztdf, tdf3, or nano)", tdfType) + } + + // Create request + req := &EncryptRequest{ + Flags: EncryptRequestFlags{ + Out: out, + Attr: attr, + WrappingKeyAlgorithm: wrappingKeyAlgorithm, + MimeType: mimeType, + TdfType: tdfType, + EcdsaBinding: ecdsaBinding, + KasUrlPath: kasUrlPath, + TargetMode: targetMode, + WithAssertions: withAssertions, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/encrypt/encrypt_generated.go b/cmd/generated/encrypt/encrypt_generated.go new file mode 100644 index 00000000..0e70c7d5 --- /dev/null +++ b/cmd/generated/encrypt/encrypt_generated.go @@ -0,0 +1,110 @@ +// Code generated by adder. DO NOT EDIT. + +package encrypt + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// EncryptRequestFlags represents the flags for the encrypt [file] command +type EncryptRequestFlags struct { + Out string `json:"out"` // The output file TDF in the current working directory instead of stdout ('-o file.txt' and '-o file.txt.tdf' both write the TDF as file.txt.tdf). + Attr string `json:"attr"` // Attribute value Fully Qualified Names (FQNs, i.e. 'https://example.com/attr/attr1/value/value1') to apply to the encrypted data. + WrappingKeyAlgorithm string `json:"wrappingKeyAlgorithm" validate:"oneof=rsa:2048 ec:secp256r1 ec:secp384r1 ec:secp521r1"` // EXPERIMENTAL: The algorithm to use for the wrapping key + + MimeType string `json:"mimeType"` // The MIME type of the input data. If not provided, the MIME type is inferred from the input data. + TdfType string `json:"tdfType" validate:"oneof=ztdf tdf3 nano"` // The type of tdf to encrypt as. ZTDF supports structured manifests and larger payloads. NanoTDF has a smaller footprint and more performant, but does not support structured manifests or large payloads. (tdf3 is an alias for ztdf) + EcdsaBinding string `json:"ecdsaBinding"` // For nano type containers only, enables ECDSA policy binding + KasUrlPath string `json:"kasUrlPath"` // URL path to the KAS service at the platform endpoint domain. Leading slash is required if needed. + TargetMode string `json:"targetMode"` // The target TDF spec version (e.g., \"4.3.0\"); intended for legacy compatibility and subject to removal. + WithAssertions string `json:"withAssertions"` // EXPERIMENTAL: JSON string or path to a JSON file of assertions to bind metadata to the TDF. See examples for more information. WARNING: Providing keys in a JSON string is strongly discouraged. If including sensitive keys, instead provide a path to a JSON file containing that information. +} + +// EncryptRequest represents the parameters for the encrypt [file] command +type EncryptRequest struct { + Flags EncryptRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` +} + +// EncryptHandler defines the function type for handling encrypt [file] commands +type EncryptHandler func(cmd *cobra.Command, req *EncryptRequest) error + +// NewEncryptCommand creates a new encrypt [file] command with the provided handler function +func NewEncryptCommand(handler EncryptHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "encrypt [file]", + Short: "Encrypt file or stdin as a TDF", + RunE: func(cmd *cobra.Command, args []string) error { + return runEncrypt(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("out", "o", "", "The output file TDF in the current working directory instead of stdout ('-o file.txt' and '-o file.txt.tdf' both write the TDF as file.txt.tdf).") + cmd.Flags().StringP("attr", "a", "", "Attribute value Fully Qualified Names (FQNs, i.e. 'https://example.com/attr/attr1/value/value1') to apply to the encrypted data.") + cmd.Flags().String("wrapping-key-algorithm", "rsa:2048", "EXPERIMENTAL: The algorithm to use for the wrapping key") + cmd.Flags().String("mime-type", "", "The MIME type of the input data. If not provided, the MIME type is inferred from the input data.") + cmd.Flags().StringP("tdf-type", "t", "ztdf", "The type of tdf to encrypt as. ZTDF supports structured manifests and larger payloads. NanoTDF has a smaller footprint and more performant, but does not support structured manifests or large payloads. (tdf3 is an alias for ztdf)") + cmd.Flags().String("ecdsa-binding", "", "For nano type containers only, enables ECDSA policy binding") + cmd.Flags().String("kas-url-path", "/kas", "URL path to the KAS service at the platform endpoint domain. Leading slash is required if needed.") + cmd.Flags().String("target-mode", "", "The target TDF spec version (e.g., \"4.3.0\"); intended for legacy compatibility and subject to removal.") + cmd.Flags().String("with-assertions", "", "EXPERIMENTAL: JSON string or path to a JSON file of assertions to bind metadata to the TDF. See examples for more information. WARNING: Providing keys in a JSON string is strongly discouraged. If including sensitive keys, instead provide a path to a JSON file containing that information.") + + return cmd +} + +// runEncrypt handles argument and flag extraction +func runEncrypt(cmd *cobra.Command, args []string, handler EncryptHandler) error { + out, _ := cmd.Flags().GetString("out") + attr, _ := cmd.Flags().GetString("attr") + wrappingKeyAlgorithm, _ := cmd.Flags().GetString("wrapping-key-algorithm") + mimeType, _ := cmd.Flags().GetString("mime-type") + tdfType, _ := cmd.Flags().GetString("tdf-type") + ecdsaBinding, _ := cmd.Flags().GetString("ecdsa-binding") + kasUrlPath, _ := cmd.Flags().GetString("kas-url-path") + targetMode, _ := cmd.Flags().GetString("target-mode") + withAssertions, _ := cmd.Flags().GetString("with-assertions") + // Validate enum for wrapping-key-algorithm + wrappingKeyAlgorithmValid := false + for _, validValue := range []string{"rsa:2048", "ec:secp256r1", "ec:secp384r1", "ec:secp521r1"} { + if wrappingKeyAlgorithm == validValue { + wrappingKeyAlgorithmValid = true + break + } + } + if !wrappingKeyAlgorithmValid { + return fmt.Errorf("invalid wrapping-key-algorithm: %s (must be rsa:2048, ec:secp256r1, ec:secp384r1, or ec:secp521r1)", wrappingKeyAlgorithm) + } + // Validate enum for tdf-type + tdfTypeValid := false + for _, validValue := range []string{"ztdf", "tdf3", "nano"} { + if tdfType == validValue { + tdfTypeValid = true + break + } + } + if !tdfTypeValid { + return fmt.Errorf("invalid tdf-type: %s (must be ztdf, tdf3, or nano)", tdfType) + } + + // Create request + req := &EncryptRequest{ + Flags: EncryptRequestFlags{ + Out: out, + Attr: attr, + WrappingKeyAlgorithm: wrappingKeyAlgorithm, + MimeType: mimeType, + TdfType: tdfType, + EcdsaBinding: ecdsaBinding, + KasUrlPath: kasUrlPath, + TargetMode: targetMode, + WithAssertions: withAssertions, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/inspect/_index_generated.go b/cmd/generated/inspect/_index_generated.go new file mode 100644 index 00000000..fc1ec4f5 --- /dev/null +++ b/cmd/generated/inspect/_index_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package inspect + +import ( + + "github.com/spf13/cobra" +) + +// InspectRequestArguments represents the arguments for the inspect command +type InspectRequestArguments struct { + File string `json:"file" validate:"required"` // Path to the TDF file to inspect +} + +// InspectRequest represents the parameters for the inspect command +type InspectRequest struct { + Arguments InspectRequestArguments `json:"arguments"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// InspectHandler defines the function type for handling inspect commands +type InspectHandler func(cmd *cobra.Command, req *InspectRequest) error + +// NewInspectCommand creates a new inspect command with the provided handler function +func NewInspectCommand(handler InspectHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "inspect [file]", + Short: "Inspect a TDF file", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return runInspect(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runInspect handles argument and flag extraction +func runInspect(cmd *cobra.Command, args []string, handler InspectHandler) error { + file := args[0] + + // Create request + req := &InspectRequest{ + Arguments: InspectRequestArguments{ + File: file, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/inspect/inspect_generated.go b/cmd/generated/inspect/inspect_generated.go new file mode 100644 index 00000000..4ccd4104 --- /dev/null +++ b/cmd/generated/inspect/inspect_generated.go @@ -0,0 +1,52 @@ +// Code generated by adder. DO NOT EDIT. + +package inspect + +import ( + + "github.com/spf13/cobra" +) + +// InspectRequestArguments represents the arguments for the inspect command +type InspectRequestArguments struct { + File string `json:"file" validate:"required"` // Path to the TDF file to inspect +} + +// InspectRequest represents the parameters for the inspect command +type InspectRequest struct { + Arguments InspectRequestArguments `json:"arguments"` +} + +// InspectHandler defines the function type for handling inspect commands +type InspectHandler func(cmd *cobra.Command, req *InspectRequest) error + +// NewInspectCommand creates a new inspect command with the provided handler function +func NewInspectCommand(handler InspectHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "inspect [file]", + Short: "Inspect a TDF file", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return runInspect(cmd, args, handler) + }, + } + + // Register flags + + return cmd +} + +// runInspect handles argument and flag extraction +func runInspect(cmd *cobra.Command, args []string, handler InspectHandler) error { + file := args[0] + + // Create request + req := &InspectRequest{ + Arguments: InspectRequestArguments{ + File: file, + }, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/interactive_generated.go b/cmd/generated/interactive_generated.go new file mode 100644 index 00000000..3e577257 --- /dev/null +++ b/cmd/generated/interactive_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package generated + +import ( + + "github.com/spf13/cobra" +) + + +// InteractiveRequest represents the parameters for the interactive command +type InteractiveRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// InteractiveHandler defines the function type for handling interactive commands +type InteractiveHandler func(cmd *cobra.Command, req *InteractiveRequest) error + +// NewInteractiveCommand creates a new interactive command with the provided handler function +func NewInteractiveCommand(handler InteractiveHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "interactive", + Aliases: []string{"i"}, + Short: "Interactive Mode (experimental)", + RunE: func(cmd *cobra.Command, args []string) error { + return runInteractive(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runInteractive handles argument and flag extraction +func runInteractive(cmd *cobra.Command, args []string, handler InteractiveHandler) error { + + // Create request + req := &InteractiveRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/_index_generated.go b/cmd/generated/key-management/_index_generated.go new file mode 100644 index 00000000..c3f588c8 --- /dev/null +++ b/cmd/generated/key-management/_index_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management + +import ( + + "github.com/spf13/cobra" +) + +// KeymanagementRequestFlags represents the flags for the keymanagement command +type KeymanagementRequestFlags struct { + Json string `json:"json"` // output single command in JSON (overrides configured output format) +} + +// KeymanagementRequest represents the parameters for the keymanagement command +type KeymanagementRequest struct { + Flags KeymanagementRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KeymanagementHandler defines the function type for handling keymanagement commands +type KeymanagementHandler func(cmd *cobra.Command, req *KeymanagementRequest) error + +// NewKeymanagementCommand creates a new keymanagement command with the provided handler function +func NewKeymanagementCommand(handler KeymanagementHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "keymanagement", + Aliases: []string{"k"}, + Short: "Key management", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runKeymanagement(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("json", "false", "output single command in JSON (overrides configured output format)") + + return cmd +} + +// runKeymanagement handles argument and flag extraction +func runKeymanagement(cmd *cobra.Command, args []string, handler KeymanagementHandler) error { + json, _ := cmd.Flags().GetString("json") + + // Create request + req := &KeymanagementRequest{ + Flags: KeymanagementRequestFlags{ + Json: json, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/_index_generated.go b/cmd/generated/key-management/provider/_index_generated.go new file mode 100644 index 00000000..04160bf1 --- /dev/null +++ b/cmd/generated/key-management/provider/_index_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// ProviderRequestFlags represents the flags for the provider command +type ProviderRequestFlags struct { + Json string `json:"json"` // output single command in JSON (overrides configured output format) +} + +// ProviderRequest represents the parameters for the provider command +type ProviderRequest struct { + Flags ProviderRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ProviderHandler defines the function type for handling provider commands +type ProviderHandler func(cmd *cobra.Command, req *ProviderRequest) error + +// NewProviderCommand creates a new provider command with the provided handler function +func NewProviderCommand(handler ProviderHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "provider", + Aliases: []string{"p"}, + Short: "Provider configuration for Key Management", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runProvider(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("json", "false", "output single command in JSON (overrides configured output format)") + + return cmd +} + +// runProvider handles argument and flag extraction +func runProvider(cmd *cobra.Command, args []string, handler ProviderHandler) error { + json, _ := cmd.Flags().GetString("json") + + // Create request + req := &ProviderRequest{ + Flags: ProviderRequestFlags{ + Json: json, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/create_generated.go b/cmd/generated/key-management/provider/create_generated.go new file mode 100644 index 00000000..ba5f467c --- /dev/null +++ b/cmd/generated/key-management/provider/create_generated.go @@ -0,0 +1,67 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the provider config to create + Config string `json:"config"` // JSON configuration for the provider + Label string `json:"label"` // Metadata labels for the provider config +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c"}, + Short: "Create a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("name", "", "Name of the provider config to create") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("config", "c", "", "JSON configuration for the provider") + cmd.MarkFlagRequired("config") + cmd.Flags().StringP("label", "l", "", "Metadata labels for the provider config") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + config, _ := cmd.Flags().GetString("config") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Config: config, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/delete_generated.go b/cmd/generated/key-management/provider/delete_generated.go new file mode 100644 index 00000000..59f60dc0 --- /dev/null +++ b/cmd/generated/key-management/provider/delete_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the provider config to delete +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Aliases: []string{"d", "remove"}, + Short: "Delete a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the provider config to delete") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/get_generated.go b/cmd/generated/key-management/provider/get_generated.go new file mode 100644 index 00000000..420c1d46 --- /dev/null +++ b/cmd/generated/key-management/provider/get_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the provider config to retrieve + Name string `json:"name"` // Name of the provider config to retrieve +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the provider config to retrieve") + cmd.Flags().String("name", "", "Name of the provider config to retrieve") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + Name: name, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/list_generated.go b/cmd/generated/key-management/provider/list_generated.go new file mode 100644 index 00000000..c089ffe8 --- /dev/null +++ b/cmd/generated/key-management/provider/list_generated.go @@ -0,0 +1,63 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Maximum number of results to return + Offset string `json:"offset"` // Offset for pagination +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Provider Configs", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "L", "", "Maximum number of results to return") + cmd.MarkFlagRequired("limit") + cmd.Flags().StringP("offset", "o", "", "Offset for pagination") + cmd.MarkFlagRequired("offset") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/key-management/provider/update_generated.go b/cmd/generated/key-management/provider/update_generated.go new file mode 100644 index 00000000..412832c4 --- /dev/null +++ b/cmd/generated/key-management/provider/update_generated.go @@ -0,0 +1,70 @@ +// Code generated by adder. DO NOT EDIT. + +package key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the provider config to update + Name string `json:"name"` // New name for the provider config + Config string `json:"config"` // New JSON configuration for the provider + Label string `json:"label"` // Metadata labels for the provider config +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the provider config to update") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "New name for the provider config") + cmd.Flags().StringP("config", "c", "", "New JSON configuration for the provider") + cmd.Flags().StringP("label", "l", "", "Metadata labels for the provider config") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + config, _ := cmd.Flags().GetString("config") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + Config: config, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/otdfctl_generated.go b/cmd/generated/otdfctl_generated.go new file mode 100644 index 00000000..a70b2d81 --- /dev/null +++ b/cmd/generated/otdfctl_generated.go @@ -0,0 +1,110 @@ +// Code generated by adder. DO NOT EDIT. + +package generated + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// OtdfctlRequestFlags represents the flags for the otdfctl command +type OtdfctlRequestFlags struct { + Version bool `json:"version"` // show version +} +// OtdfctlRequestPersistentFlags represents the persistent flags for the otdfctl command +type OtdfctlRequestPersistentFlags struct { + Profile string `json:"profile"` // profile to use for interacting with the platform + Host string `json:"host"` // Hostname of the platform (i.e. https://localhost) + TlsNoVerify bool `json:"tlsNoVerify"` // disable verification of the server's TLS certificate + LogLevel string `json:"logLevel" validate:"oneof=debug info warn error fatal panic"` // log level + WithAccessToken string `json:"withAccessToken"` // access token for authentication via bearer token + WithClientCredsFile string `json:"withClientCredsFile"` // path to a JSON file containing a 'clientId' and 'clientSecret' for auth via client-credentials flow + WithClientCreds string `json:"withClientCreds"` // JSON string containing a 'clientId' and 'clientSecret' for auth via client-credentials flow + Json bool `json:"json"` // output in JSON format + Debug bool `json:"debug"` // enable debug output +} + +// OtdfctlRequest represents the parameters for the otdfctl command +type OtdfctlRequest struct { + Flags OtdfctlRequestFlags `json:"flags"` + PersistentFlags OtdfctlRequestPersistentFlags `json:"persistent_flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// OtdfctlHandler defines the function type for handling otdfctl commands +type OtdfctlHandler func(cmd *cobra.Command, req *OtdfctlRequest) error + +// NewOtdfctlCommand creates a new otdfctl command with the provided handler function +func NewOtdfctlCommand(handler OtdfctlHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "otdfctl", + Short: "otdfctl - OpenTDF Control Tool", + RunE: func(cmd *cobra.Command, args []string) error { + return runOtdfctl(cmd, args, handler) + }, + } + + // Register persistent flags + cmd.PersistentFlags().String("profile", "", "profile to use for interacting with the platform") + cmd.PersistentFlags().String("host", "", "Hostname of the platform (i.e. https://localhost)") + cmd.PersistentFlags().Bool("tls-no-verify", false, "disable verification of the server's TLS certificate") + cmd.PersistentFlags().String("log-level", "info", "log level") + cmd.PersistentFlags().String("with-access-token", "", "access token for authentication via bearer token") + cmd.PersistentFlags().String("with-client-creds-file", "", "path to a JSON file containing a 'clientId' and 'clientSecret' for auth via client-credentials flow") + cmd.PersistentFlags().String("with-client-creds", "", "JSON string containing a 'clientId' and 'clientSecret' for auth via client-credentials flow") + cmd.PersistentFlags().Bool("json", false, "output in JSON format") + cmd.PersistentFlags().Bool("debug", false, "enable debug output") + + // Register flags + cmd.Flags().Bool("version", false, "show version") + + return cmd +} + +// runOtdfctl handles argument and flag extraction +func runOtdfctl(cmd *cobra.Command, args []string, handler OtdfctlHandler) error { + version, _ := cmd.Flags().GetBool("version") + profile, _ := cmd.PersistentFlags().GetString("profile") + host, _ := cmd.PersistentFlags().GetString("host") + tlsNoVerify, _ := cmd.PersistentFlags().GetBool("tls-no-verify") + logLevel, _ := cmd.PersistentFlags().GetString("log-level") + withAccessToken, _ := cmd.PersistentFlags().GetString("with-access-token") + withClientCredsFile, _ := cmd.PersistentFlags().GetString("with-client-creds-file") + withClientCreds, _ := cmd.PersistentFlags().GetString("with-client-creds") + json, _ := cmd.PersistentFlags().GetBool("json") + debug, _ := cmd.PersistentFlags().GetBool("debug") + // Validate enum for log-level + logLevelValid := false + for _, validValue := range []string{"debug", "info", "warn", "error", "fatal", "panic"} { + if logLevel == validValue { + logLevelValid = true + break + } + } + if !logLevelValid { + return fmt.Errorf("invalid log-level: %s (must be debug, info, warn, error, fatal, or panic)", logLevel) + } + + // Create request + req := &OtdfctlRequest{ + Flags: OtdfctlRequestFlags{ + Version: version, + }, + PersistentFlags: OtdfctlRequestPersistentFlags{ + Profile: profile, + Host: host, + TlsNoVerify: tlsNoVerify, + LogLevel: logLevel, + WithAccessToken: withAccessToken, + WithClientCredsFile: withClientCredsFile, + WithClientCreds: withClientCreds, + Json: json, + Debug: debug, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/_index_generated.go b/cmd/generated/policy/_index_generated.go new file mode 100644 index 00000000..45d5b68b --- /dev/null +++ b/cmd/generated/policy/_index_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy + +import ( + + "github.com/spf13/cobra" +) + +// PolicyRequestFlags represents the flags for the policy command +type PolicyRequestFlags struct { + Json string `json:"json"` // output single command in JSON (overrides configured output format) +} + +// PolicyRequest represents the parameters for the policy command +type PolicyRequest struct { + Flags PolicyRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// PolicyHandler defines the function type for handling policy commands +type PolicyHandler func(cmd *cobra.Command, req *PolicyRequest) error + +// NewPolicyCommand creates a new policy command with the provided handler function +func NewPolicyCommand(handler PolicyHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "policy", + Aliases: []string{"pol", "policies"}, + Short: "Manage policy", + RunE: func(cmd *cobra.Command, args []string) error { + return runPolicy(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("json", "false", "output single command in JSON (overrides configured output format)") + + return cmd +} + +// runPolicy handles argument and flag extraction +func runPolicy(cmd *cobra.Command, args []string, handler PolicyHandler) error { + json, _ := cmd.Flags().GetString("json") + + // Create request + req := &PolicyRequest{ + Flags: PolicyRequestFlags{ + Json: json, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/_index_generated.go b/cmd/generated/policy/actions/_index_generated.go new file mode 100644 index 00000000..a819966b --- /dev/null +++ b/cmd/generated/policy/actions/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + + +// ActionsRequest represents the parameters for the actions command +type ActionsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ActionsHandler defines the function type for handling actions commands +type ActionsHandler func(cmd *cobra.Command, req *ActionsRequest) error + +// NewActionsCommand creates a new actions command with the provided handler function +func NewActionsCommand(handler ActionsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "actions", + Aliases: []string{"action"}, + Short: "Manage Actions", + RunE: func(cmd *cobra.Command, args []string) error { + return runActions(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runActions handles argument and flag extraction +func runActions(cmd *cobra.Command, args []string, handler ActionsHandler) error { + + // Create request + req := &ActionsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/create_generated.go b/cmd/generated/policy/actions/create_generated.go new file mode 100644 index 00000000..90452306 --- /dev/null +++ b/cmd/generated/policy/actions/create_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the custom action (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create a Custom Action", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("name", "", "Name of the custom action (must be unique within Policy)") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/delete_generated.go b/cmd/generated/policy/actions/delete_generated.go new file mode 100644 index 00000000..c57934fe --- /dev/null +++ b/cmd/generated/policy/actions/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the custom action + Force string `json:"force"` // Force deletion without interactive confirmation +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a Custom Action", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the custom action") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/get_generated.go b/cmd/generated/policy/actions/get_generated.go new file mode 100644 index 00000000..f434794f --- /dev/null +++ b/cmd/generated/policy/actions/get_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the action + Name string `json:"name"` // Name of the action +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Standard or Custom Action", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the action") + cmd.Flags().String("name", "", "Name of the action") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + Name: name, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/list_generated.go b/cmd/generated/policy/actions/list_generated.go new file mode 100644 index 00000000..493a1792 --- /dev/null +++ b/cmd/generated/policy/actions/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Actions", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/actions/update_generated.go b/cmd/generated/policy/actions/update_generated.go new file mode 100644 index 00000000..1da42209 --- /dev/null +++ b/cmd/generated/policy/actions/update_generated.go @@ -0,0 +1,70 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_actions + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the action to update + Name string `json:"name"` // Optional updated name of the custom action (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Custom Action", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the action to update") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "Optional updated name of the custom action (must be unique within Policy)") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/_index_generated.go b/cmd/generated/policy/attributes/_index_generated.go new file mode 100644 index 00000000..161bf7c7 --- /dev/null +++ b/cmd/generated/policy/attributes/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + + "github.com/spf13/cobra" +) + + +// AttributesRequest represents the parameters for the attributes command +type AttributesRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AttributesHandler defines the function type for handling attributes commands +type AttributesHandler func(cmd *cobra.Command, req *AttributesRequest) error + +// NewAttributesCommand creates a new attributes command with the provided handler function +func NewAttributesCommand(handler AttributesHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "attributes", + Aliases: []string{"attr", "attribute"}, + Short: "Manage attributes", + RunE: func(cmd *cobra.Command, args []string) error { + return runAttributes(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runAttributes handles argument and flag extraction +func runAttributes(cmd *cobra.Command, args []string, handler AttributesHandler) error { + + // Create request + req := &AttributesRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/create_generated.go b/cmd/generated/policy/attributes/create_generated.go new file mode 100644 index 00000000..5c79c333 --- /dev/null +++ b/cmd/generated/policy/attributes/create_generated.go @@ -0,0 +1,89 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the attribute + Rule string `json:"rule" validate:"oneof=ANY_OF ALL_OF HIERARCHY"` // Rule of the attribute + Value string `json:"value"` // Value of the attribute (i.e. 'value1') + Namespace string `json:"namespace"` // Namespace ID of the attribute + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"new", "add", "c"}, + Short: "Create an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("name", "", "Name of the attribute") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("rule", "r", "", "Rule of the attribute") + cmd.MarkFlagRequired("rule") + cmd.Flags().StringP("value", "v", "", "Value of the attribute (i.e. 'value1')") + cmd.MarkFlagRequired("value") + cmd.Flags().StringP("namespace", "s", "", "Namespace ID of the attribute") + cmd.MarkFlagRequired("namespace") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + rule, _ := cmd.Flags().GetString("rule") + value, _ := cmd.Flags().GetString("value") + namespace, _ := cmd.Flags().GetString("namespace") + label, _ := cmd.Flags().GetString("label") + // Validate enum for rule + ruleValid := false + for _, validValue := range []string{"ANY_OF", "ALL_OF", "HIERARCHY"} { + if rule == validValue { + ruleValid = true + break + } + } + if !ruleValid { + return fmt.Errorf("invalid rule: %s (must be ANY_OF, ALL_OF, or HIERARCHY)", rule) + } + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Rule: rule, + Value: value, + Namespace: namespace, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/deactivate_generated.go b/cmd/generated/policy/attributes/deactivate_generated.go new file mode 100644 index 00000000..9956aa68 --- /dev/null +++ b/cmd/generated/policy/attributes/deactivate_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + + "github.com/spf13/cobra" +) + +// DeactivateRequestFlags represents the flags for the deactivate command +type DeactivateRequestFlags struct { + Id string `json:"id"` // ID of the attribute + Force string `json:"force"` // Force deactivation without interactive confirmation (dangerous) +} + +// DeactivateRequest represents the parameters for the deactivate command +type DeactivateRequest struct { + Flags DeactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeactivateHandler defines the function type for handling deactivate commands +type DeactivateHandler func(cmd *cobra.Command, req *DeactivateRequest) error + +// NewDeactivateCommand creates a new deactivate command with the provided handler function +func NewDeactivateCommand(handler DeactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "deactivate", + Short: "Deactivate an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runDeactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deactivation without interactive confirmation (dangerous)") + + return cmd +} + +// runDeactivate handles argument and flag extraction +func runDeactivate(cmd *cobra.Command, args []string, handler DeactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeactivateRequest{ + Flags: DeactivateRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/get_generated.go b/cmd/generated/policy/attributes/get_generated.go new file mode 100644 index 00000000..d84324fe --- /dev/null +++ b/cmd/generated/policy/attributes/get_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the attribute +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/key/_index_generated.go b/cmd/generated/policy/attributes/key/_index_generated.go new file mode 100644 index 00000000..7e514dfc --- /dev/null +++ b/cmd/generated/policy/attributes/key/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_key + +import ( + + "github.com/spf13/cobra" +) + + +// KeyRequest represents the parameters for the key command +type KeyRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KeyHandler defines the function type for handling key commands +type KeyHandler func(cmd *cobra.Command, req *KeyRequest) error + +// NewKeyCommand creates a new key command with the provided handler function +func NewKeyCommand(handler KeyHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "key", + Short: "Key Management changes to attribute definition", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runKey(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKey handles argument and flag extraction +func runKey(cmd *cobra.Command, args []string, handler KeyHandler) error { + + // Create request + req := &KeyRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/key/assign_generated.go b/cmd/generated/policy/attributes/key/assign_generated.go new file mode 100644 index 00000000..4c8ceac6 --- /dev/null +++ b/cmd/generated/policy/attributes/key/assign_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_key + +import ( + + "github.com/spf13/cobra" +) + +// AssignRequestFlags represents the flags for the assign command +type AssignRequestFlags struct { + Attribute string `json:"attribute"` // URI or ID of the attribute definition + KeyId string `json:"keyId"` // ID of the KAS key to assign +} + +// AssignRequest represents the parameters for the assign command +type AssignRequest struct { + Flags AssignRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AssignHandler defines the function type for handling assign commands +type AssignHandler func(cmd *cobra.Command, req *AssignRequest) error + +// NewAssignCommand creates a new assign command with the provided handler function +func NewAssignCommand(handler AssignHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "assign", + Short: "Assign a KAS key to an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runAssign(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("attribute", "a", "", "URI or ID of the attribute definition") + cmd.MarkFlagRequired("attribute") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to assign") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runAssign handles argument and flag extraction +func runAssign(cmd *cobra.Command, args []string, handler AssignHandler) error { + attribute, _ := cmd.Flags().GetString("attribute") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &AssignRequest{ + Flags: AssignRequestFlags{ + Attribute: attribute, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/key/remove_generated.go b/cmd/generated/policy/attributes/key/remove_generated.go new file mode 100644 index 00000000..a2469291 --- /dev/null +++ b/cmd/generated/policy/attributes/key/remove_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_key + +import ( + + "github.com/spf13/cobra" +) + +// RemoveRequestFlags represents the flags for the remove command +type RemoveRequestFlags struct { + Attribute string `json:"attribute"` // URI or ID of attribute definition + KeyId string `json:"keyId"` // ID of the KAS key to remove +} + +// RemoveRequest represents the parameters for the remove command +type RemoveRequest struct { + Flags RemoveRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// RemoveHandler defines the function type for handling remove commands +type RemoveHandler func(cmd *cobra.Command, req *RemoveRequest) error + +// NewRemoveCommand creates a new remove command with the provided handler function +func NewRemoveCommand(handler RemoveHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "remove", + Short: "Remove a KAS key from an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runRemove(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("attribute", "a", "", "URI or ID of attribute definition") + cmd.MarkFlagRequired("attribute") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to remove") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runRemove handles argument and flag extraction +func runRemove(cmd *cobra.Command, args []string, handler RemoveHandler) error { + attribute, _ := cmd.Flags().GetString("attribute") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &RemoveRequest{ + Flags: RemoveRequestFlags{ + Attribute: attribute, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/list_generated.go b/cmd/generated/policy/attributes/list_generated.go new file mode 100644 index 00000000..26c58938 --- /dev/null +++ b/cmd/generated/policy/attributes/list_generated.go @@ -0,0 +1,77 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + State string `json:"state" validate:"oneof=active inactive any"` // Filter by state + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List attribute definitions", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("state", "s", "active", "Filter by state") + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + state, _ := cmd.Flags().GetString("state") + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + // Validate enum for state + stateValid := false + for _, validValue := range []string{"active", "inactive", "any"} { + if state == validValue { + stateValid = true + break + } + } + if !stateValid { + return fmt.Errorf("invalid state: %s (must be active, inactive, or any)", state) + } + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + State: state, + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/_index_generated.go b/cmd/generated/policy/attributes/namespaces/_index_generated.go new file mode 100644 index 00000000..761e9300 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + + +// NamespacesRequest represents the parameters for the namespaces command +type NamespacesRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// NamespacesHandler defines the function type for handling namespaces commands +type NamespacesHandler func(cmd *cobra.Command, req *NamespacesRequest) error + +// NewNamespacesCommand creates a new namespaces command with the provided handler function +func NewNamespacesCommand(handler NamespacesHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "namespaces", + Aliases: []string{"ns", "namespace"}, + Short: "Manage attribute namespaces", + RunE: func(cmd *cobra.Command, args []string) error { + return runNamespaces(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runNamespaces handles argument and flag extraction +func runNamespaces(cmd *cobra.Command, args []string, handler NamespacesHandler) error { + + // Create request + req := &NamespacesRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/create_generated.go b/cmd/generated/policy/attributes/namespaces/create_generated.go new file mode 100644 index 00000000..87de38eb --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/create_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the attribute namespace (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("name", "", "Name of the attribute namespace (must be unique within Policy)") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/deactivate_generated.go b/cmd/generated/policy/attributes/namespaces/deactivate_generated.go new file mode 100644 index 00000000..d614e519 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/deactivate_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + +// DeactivateRequestFlags represents the flags for the deactivate command +type DeactivateRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace + Force string `json:"force"` // Force deactivation without interactive confirmation (dangerous) +} + +// DeactivateRequest represents the parameters for the deactivate command +type DeactivateRequest struct { + Flags DeactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeactivateHandler defines the function type for handling deactivate commands +type DeactivateHandler func(cmd *cobra.Command, req *DeactivateRequest) error + +// NewDeactivateCommand creates a new deactivate command with the provided handler function +func NewDeactivateCommand(handler DeactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "deactivate", + Short: "Deactivate an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runDeactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deactivation without interactive confirmation (dangerous)") + + return cmd +} + +// runDeactivate handles argument and flag extraction +func runDeactivate(cmd *cobra.Command, args []string, handler DeactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeactivateRequest{ + Flags: DeactivateRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/get_generated.go b/cmd/generated/policy/attributes/namespaces/get_generated.go new file mode 100644 index 00000000..bc45e766 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/get_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/key/_index_generated.go b/cmd/generated/policy/attributes/namespaces/key/_index_generated.go new file mode 100644 index 00000000..2e98d98b --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/key/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_key + +import ( + + "github.com/spf13/cobra" +) + + +// KeyRequest represents the parameters for the key command +type KeyRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KeyHandler defines the function type for handling key commands +type KeyHandler func(cmd *cobra.Command, req *KeyRequest) error + +// NewKeyCommand creates a new key command with the provided handler function +func NewKeyCommand(handler KeyHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "key", + Short: "Key Management changes to attribute namespaces", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runKey(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKey handles argument and flag extraction +func runKey(cmd *cobra.Command, args []string, handler KeyHandler) error { + + // Create request + req := &KeyRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/key/assign_generated.go b/cmd/generated/policy/attributes/namespaces/key/assign_generated.go new file mode 100644 index 00000000..47d132d1 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/key/assign_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_key + +import ( + + "github.com/spf13/cobra" +) + +// AssignRequestFlags represents the flags for the assign command +type AssignRequestFlags struct { + Namespace string `json:"namespace"` // Can be URI or ID of namespace + KeyId string `json:"keyId"` // ID of the KAS key to assign +} + +// AssignRequest represents the parameters for the assign command +type AssignRequest struct { + Flags AssignRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AssignHandler defines the function type for handling assign commands +type AssignHandler func(cmd *cobra.Command, req *AssignRequest) error + +// NewAssignCommand creates a new assign command with the provided handler function +func NewAssignCommand(handler AssignHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "assign", + Short: "Assign a KAS key to an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runAssign(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("namespace", "", "Can be URI or ID of namespace") + cmd.MarkFlagRequired("namespace") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to assign") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runAssign handles argument and flag extraction +func runAssign(cmd *cobra.Command, args []string, handler AssignHandler) error { + namespace, _ := cmd.Flags().GetString("namespace") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &AssignRequest{ + Flags: AssignRequestFlags{ + Namespace: namespace, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/key/remove_generated.go b/cmd/generated/policy/attributes/namespaces/key/remove_generated.go new file mode 100644 index 00000000..3eab6d26 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/key/remove_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_key + +import ( + + "github.com/spf13/cobra" +) + +// RemoveRequestFlags represents the flags for the remove command +type RemoveRequestFlags struct { + Namespace string `json:"namespace"` // Can be URI or ID of namespace + KeyId string `json:"keyId"` // ID of the KAS key to remove +} + +// RemoveRequest represents the parameters for the remove command +type RemoveRequest struct { + Flags RemoveRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// RemoveHandler defines the function type for handling remove commands +type RemoveHandler func(cmd *cobra.Command, req *RemoveRequest) error + +// NewRemoveCommand creates a new remove command with the provided handler function +func NewRemoveCommand(handler RemoveHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "remove", + Short: "Remove a KAS key from an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runRemove(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("namespace", "", "Can be URI or ID of namespace") + cmd.MarkFlagRequired("namespace") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to remove") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runRemove handles argument and flag extraction +func runRemove(cmd *cobra.Command, args []string, handler RemoveHandler) error { + namespace, _ := cmd.Flags().GetString("namespace") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &RemoveRequest{ + Flags: RemoveRequestFlags{ + Namespace: namespace, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/list_generated.go b/cmd/generated/policy/attributes/namespaces/list_generated.go new file mode 100644 index 00000000..e91cfd30 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/list_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + State string `json:"state"` // Filter by state [active, inactive, any] + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"ls", "l"}, + Short: "List attribute namespaces", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("state", "s", "", "Filter by state [active, inactive, any]") + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + state, _ := cmd.Flags().GetString("state") + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + State: state, + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/unsafe/_index_generated.go b/cmd/generated/policy/attributes/namespaces/unsafe/_index_generated.go new file mode 100644 index 00000000..9bcb2c53 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/unsafe/_index_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// UnsafeRequestFlags represents the flags for the unsafe command +type UnsafeRequestFlags struct { + Force string `json:"force"` // Force unsafe change without confirmation +} + +// UnsafeRequest represents the parameters for the unsafe command +type UnsafeRequest struct { + Flags UnsafeRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UnsafeHandler defines the function type for handling unsafe commands +type UnsafeHandler func(cmd *cobra.Command, req *UnsafeRequest) error + +// NewUnsafeCommand creates a new unsafe command with the provided handler function +func NewUnsafeCommand(handler UnsafeHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "unsafe", + Short: "Unsafe changes to attribute namespaces", + RunE: func(cmd *cobra.Command, args []string) error { + return runUnsafe(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("force", "", "Force unsafe change without confirmation") + + return cmd +} + +// runUnsafe handles argument and flag extraction +func runUnsafe(cmd *cobra.Command, args []string, handler UnsafeHandler) error { + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &UnsafeRequest{ + Flags: UnsafeRequestFlags{ + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/unsafe/delete_generated.go b/cmd/generated/policy/attributes/namespaces/unsafe/delete_generated.go new file mode 100644 index 00000000..a7181336 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/unsafe/delete_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/unsafe/reactivate_generated.go b/cmd/generated/policy/attributes/namespaces/unsafe/reactivate_generated.go new file mode 100644 index 00000000..b474830f --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/unsafe/reactivate_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// ReactivateRequestFlags represents the flags for the reactivate command +type ReactivateRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace +} + +// ReactivateRequest represents the parameters for the reactivate command +type ReactivateRequest struct { + Flags ReactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ReactivateHandler defines the function type for handling reactivate commands +type ReactivateHandler func(cmd *cobra.Command, req *ReactivateRequest) error + +// NewReactivateCommand creates a new reactivate command with the provided handler function +func NewReactivateCommand(handler ReactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "reactivate", + Short: "Reactivate an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runReactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runReactivate handles argument and flag extraction +func runReactivate(cmd *cobra.Command, args []string, handler ReactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &ReactivateRequest{ + Flags: ReactivateRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/unsafe/update_generated.go b/cmd/generated/policy/attributes/namespaces/unsafe/update_generated.go new file mode 100644 index 00000000..41676fb5 --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/unsafe/update_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace + Name string `json:"name"` // Name of the attribute namespace (new) +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Short: "Update an attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "Name of the attribute namespace (new)") + cmd.MarkFlagRequired("name") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/namespaces/update_generated.go b/cmd/generated/policy/attributes/namespaces/update_generated.go new file mode 100644 index 00000000..37136e4c --- /dev/null +++ b/cmd/generated/policy/attributes/namespaces/update_generated.go @@ -0,0 +1,66 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_namespaces + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the attribute namespace + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a attribute namespace", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute namespace") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/unsafe/_index_generated.go b/cmd/generated/policy/attributes/unsafe/_index_generated.go new file mode 100644 index 00000000..11d59f85 --- /dev/null +++ b/cmd/generated/policy/attributes/unsafe/_index_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// UnsafeRequestFlags represents the flags for the unsafe command +type UnsafeRequestFlags struct { + Force string `json:"force"` // Force unsafe change without confirmation +} + +// UnsafeRequest represents the parameters for the unsafe command +type UnsafeRequest struct { + Flags UnsafeRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UnsafeHandler defines the function type for handling unsafe commands +type UnsafeHandler func(cmd *cobra.Command, req *UnsafeRequest) error + +// NewUnsafeCommand creates a new unsafe command with the provided handler function +func NewUnsafeCommand(handler UnsafeHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "unsafe", + Short: "Unsafe changes to attribute definitions", + RunE: func(cmd *cobra.Command, args []string) error { + return runUnsafe(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("force", "", "Force unsafe change without confirmation") + + return cmd +} + +// runUnsafe handles argument and flag extraction +func runUnsafe(cmd *cobra.Command, args []string, handler UnsafeHandler) error { + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &UnsafeRequest{ + Flags: UnsafeRequestFlags{ + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/unsafe/delete_generated.go b/cmd/generated/policy/attributes/unsafe/delete_generated.go new file mode 100644 index 00000000..eb79eef2 --- /dev/null +++ b/cmd/generated/policy/attributes/unsafe/delete_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the attribute definition +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute definition") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/unsafe/reactivate_generated.go b/cmd/generated/policy/attributes/unsafe/reactivate_generated.go new file mode 100644 index 00000000..12156a0c --- /dev/null +++ b/cmd/generated/policy/attributes/unsafe/reactivate_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// ReactivateRequestFlags represents the flags for the reactivate command +type ReactivateRequestFlags struct { + Id string `json:"id"` // ID of the attribute definition +} + +// ReactivateRequest represents the parameters for the reactivate command +type ReactivateRequest struct { + Flags ReactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ReactivateHandler defines the function type for handling reactivate commands +type ReactivateHandler func(cmd *cobra.Command, req *ReactivateRequest) error + +// NewReactivateCommand creates a new reactivate command with the provided handler function +func NewReactivateCommand(handler ReactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "reactivate", + Short: "Reactivate an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runReactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute definition") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runReactivate handles argument and flag extraction +func runReactivate(cmd *cobra.Command, args []string, handler ReactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &ReactivateRequest{ + Flags: ReactivateRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/unsafe/update_generated.go b/cmd/generated/policy/attributes/unsafe/update_generated.go new file mode 100644 index 00000000..9aa97899 --- /dev/null +++ b/cmd/generated/policy/attributes/unsafe/update_generated.go @@ -0,0 +1,81 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_unsafe + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the attribute definition + Name string `json:"name"` // Name of the attribute definition + Rule string `json:"rule" validate:"oneof=ANY_OF ALL_OF HIERARCHY"` // Rule of the attribute definition + ValuesOrder string `json:"valuesOrder"` // Order of the attribute values (IDs) +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Short: "Update an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute definition") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "Name of the attribute definition") + cmd.Flags().StringP("rule", "r", "", "Rule of the attribute definition") + cmd.Flags().StringP("values-order", "o", "", "Order of the attribute values (IDs)") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + rule, _ := cmd.Flags().GetString("rule") + valuesOrder, _ := cmd.Flags().GetString("values-order") + // Validate enum for rule + ruleValid := false + for _, validValue := range []string{"ANY_OF", "ALL_OF", "HIERARCHY"} { + if rule == validValue { + ruleValid = true + break + } + } + if !ruleValid { + return fmt.Errorf("invalid rule: %s (must be ANY_OF, ALL_OF, or HIERARCHY)", rule) + } + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + Rule: rule, + ValuesOrder: valuesOrder, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/update_generated.go b/cmd/generated/policy/attributes/update_generated.go new file mode 100644 index 00000000..c561183d --- /dev/null +++ b/cmd/generated/policy/attributes/update_generated.go @@ -0,0 +1,66 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the attribute + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update an attribute definition", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/_index_generated.go b/cmd/generated/policy/attributes/values/_index_generated.go new file mode 100644 index 00000000..86e99cd3 --- /dev/null +++ b/cmd/generated/policy/attributes/values/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + + "github.com/spf13/cobra" +) + + +// ValuesRequest represents the parameters for the values command +type ValuesRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ValuesHandler defines the function type for handling values commands +type ValuesHandler func(cmd *cobra.Command, req *ValuesRequest) error + +// NewValuesCommand creates a new values command with the provided handler function +func NewValuesCommand(handler ValuesHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "values", + Aliases: []string{"val", "value"}, + Short: "Manage attribute values", + RunE: func(cmd *cobra.Command, args []string) error { + return runValues(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runValues handles argument and flag extraction +func runValues(cmd *cobra.Command, args []string, handler ValuesHandler) error { + + // Create request + req := &ValuesRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/create_generated.go b/cmd/generated/policy/attributes/values/create_generated.go new file mode 100644 index 00000000..b9e7c244 --- /dev/null +++ b/cmd/generated/policy/attributes/values/create_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + AttributeId string `json:"attributeId"` // The ID of the attribute to create a value for + Value string `json:"value"` // The value to create + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"new", "add", "c"}, + Short: "Create an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("attribute-id", "a", "", "The ID of the attribute to create a value for") + cmd.Flags().StringP("value", "v", "", "The value to create") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + attributeId, _ := cmd.Flags().GetString("attribute-id") + value, _ := cmd.Flags().GetString("value") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + AttributeId: attributeId, + Value: value, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/deactivate_generated.go b/cmd/generated/policy/attributes/values/deactivate_generated.go new file mode 100644 index 00000000..570d0aee --- /dev/null +++ b/cmd/generated/policy/attributes/values/deactivate_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + + "github.com/spf13/cobra" +) + +// DeactivateRequestFlags represents the flags for the deactivate command +type DeactivateRequestFlags struct { + Id string `json:"id"` // The ID of the attribute value to deactivate +} + +// DeactivateRequest represents the parameters for the deactivate command +type DeactivateRequest struct { + Flags DeactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeactivateHandler defines the function type for handling deactivate commands +type DeactivateHandler func(cmd *cobra.Command, req *DeactivateRequest) error + +// NewDeactivateCommand creates a new deactivate command with the provided handler function +func NewDeactivateCommand(handler DeactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "deactivate", + Short: "Deactivate an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runDeactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the attribute value to deactivate") + + return cmd +} + +// runDeactivate handles argument and flag extraction +func runDeactivate(cmd *cobra.Command, args []string, handler DeactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeactivateRequest{ + Flags: DeactivateRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/get_generated.go b/cmd/generated/policy/attributes/values/get_generated.go new file mode 100644 index 00000000..8fecb765 --- /dev/null +++ b/cmd/generated/policy/attributes/values/get_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // The ID of the attribute value to get +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the attribute value to get") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/key/_index_generated.go b/cmd/generated/policy/attributes/values/key/_index_generated.go new file mode 100644 index 00000000..310c2d13 --- /dev/null +++ b/cmd/generated/policy/attributes/values/key/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_key + +import ( + + "github.com/spf13/cobra" +) + + +// KeyRequest represents the parameters for the key command +type KeyRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KeyHandler defines the function type for handling key commands +type KeyHandler func(cmd *cobra.Command, req *KeyRequest) error + +// NewKeyCommand creates a new key command with the provided handler function +func NewKeyCommand(handler KeyHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "key", + Short: "Key Management changes to attribute value", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runKey(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKey handles argument and flag extraction +func runKey(cmd *cobra.Command, args []string, handler KeyHandler) error { + + // Create request + req := &KeyRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/key/assign_generated.go b/cmd/generated/policy/attributes/values/key/assign_generated.go new file mode 100644 index 00000000..d712d1b4 --- /dev/null +++ b/cmd/generated/policy/attributes/values/key/assign_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_key + +import ( + + "github.com/spf13/cobra" +) + +// AssignRequestFlags represents the flags for the assign command +type AssignRequestFlags struct { + Value string `json:"value"` // URI or ID of attribute value + KeyId string `json:"keyId"` // ID of the KAS key to assign +} + +// AssignRequest represents the parameters for the assign command +type AssignRequest struct { + Flags AssignRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AssignHandler defines the function type for handling assign commands +type AssignHandler func(cmd *cobra.Command, req *AssignRequest) error + +// NewAssignCommand creates a new assign command with the provided handler function +func NewAssignCommand(handler AssignHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "assign", + Short: "Assign a KAS key to an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runAssign(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("value", "v", "", "URI or ID of attribute value") + cmd.MarkFlagRequired("value") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to assign") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runAssign handles argument and flag extraction +func runAssign(cmd *cobra.Command, args []string, handler AssignHandler) error { + value, _ := cmd.Flags().GetString("value") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &AssignRequest{ + Flags: AssignRequestFlags{ + Value: value, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/key/remove_generated.go b/cmd/generated/policy/attributes/values/key/remove_generated.go new file mode 100644 index 00000000..b1f79a8e --- /dev/null +++ b/cmd/generated/policy/attributes/values/key/remove_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_key + +import ( + + "github.com/spf13/cobra" +) + +// RemoveRequestFlags represents the flags for the remove command +type RemoveRequestFlags struct { + Value string `json:"value"` // URI or ID of attribute value + KeyId string `json:"keyId"` // ID of the KAS key to remove +} + +// RemoveRequest represents the parameters for the remove command +type RemoveRequest struct { + Flags RemoveRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// RemoveHandler defines the function type for handling remove commands +type RemoveHandler func(cmd *cobra.Command, req *RemoveRequest) error + +// NewRemoveCommand creates a new remove command with the provided handler function +func NewRemoveCommand(handler RemoveHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "remove", + Short: "Remove a KAS key from an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runRemove(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("value", "v", "", "URI or ID of attribute value") + cmd.MarkFlagRequired("value") + cmd.Flags().StringP("key-id", "k", "", "ID of the KAS key to remove") + cmd.MarkFlagRequired("key-id") + + return cmd +} + +// runRemove handles argument and flag extraction +func runRemove(cmd *cobra.Command, args []string, handler RemoveHandler) error { + value, _ := cmd.Flags().GetString("value") + keyId, _ := cmd.Flags().GetString("key-id") + + // Create request + req := &RemoveRequest{ + Flags: RemoveRequestFlags{ + Value: value, + KeyId: keyId, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/list_generated.go b/cmd/generated/policy/attributes/values/list_generated.go new file mode 100644 index 00000000..e7f048f9 --- /dev/null +++ b/cmd/generated/policy/attributes/values/list_generated.go @@ -0,0 +1,81 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + AttributeId string `json:"attributeId"` // The ID of the attribute to list values for + State string `json:"state" validate:"oneof=active inactive any"` // Filter by state + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"ls", "l"}, + Short: "List attribute values", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("attribute-id", "a", "", "The ID of the attribute to list values for") + cmd.Flags().StringP("state", "s", "active", "Filter by state") + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + attributeId, _ := cmd.Flags().GetString("attribute-id") + state, _ := cmd.Flags().GetString("state") + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + // Validate enum for state + stateValid := false + for _, validValue := range []string{"active", "inactive", "any"} { + if state == validValue { + stateValid = true + break + } + } + if !stateValid { + return fmt.Errorf("invalid state: %s (must be active, inactive, or any)", state) + } + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + AttributeId: attributeId, + State: state, + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/unsafe/_index_generated.go b/cmd/generated/policy/attributes/values/unsafe/_index_generated.go new file mode 100644 index 00000000..85a6b0eb --- /dev/null +++ b/cmd/generated/policy/attributes/values/unsafe/_index_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// UnsafeRequestFlags represents the flags for the unsafe command +type UnsafeRequestFlags struct { + Force string `json:"force"` // Force unsafe change without confirmation +} + +// UnsafeRequest represents the parameters for the unsafe command +type UnsafeRequest struct { + Flags UnsafeRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UnsafeHandler defines the function type for handling unsafe commands +type UnsafeHandler func(cmd *cobra.Command, req *UnsafeRequest) error + +// NewUnsafeCommand creates a new unsafe command with the provided handler function +func NewUnsafeCommand(handler UnsafeHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "unsafe", + Short: "Unsafe changes to attribute values", + RunE: func(cmd *cobra.Command, args []string) error { + return runUnsafe(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("force", "", "Force unsafe change without confirmation") + + return cmd +} + +// runUnsafe handles argument and flag extraction +func runUnsafe(cmd *cobra.Command, args []string, handler UnsafeHandler) error { + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &UnsafeRequest{ + Flags: UnsafeRequestFlags{ + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/unsafe/delete_generated.go b/cmd/generated/policy/attributes/values/unsafe/delete_generated.go new file mode 100644 index 00000000..c8f292d9 --- /dev/null +++ b/cmd/generated/policy/attributes/values/unsafe/delete_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the attribute value +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute value") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/unsafe/reactivate_generated.go b/cmd/generated/policy/attributes/values/unsafe/reactivate_generated.go new file mode 100644 index 00000000..ef1316c3 --- /dev/null +++ b/cmd/generated/policy/attributes/values/unsafe/reactivate_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// ReactivateRequestFlags represents the flags for the reactivate command +type ReactivateRequestFlags struct { + Id string `json:"id"` // ID of the attribute value +} + +// ReactivateRequest represents the parameters for the reactivate command +type ReactivateRequest struct { + Flags ReactivateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ReactivateHandler defines the function type for handling reactivate commands +type ReactivateHandler func(cmd *cobra.Command, req *ReactivateRequest) error + +// NewReactivateCommand creates a new reactivate command with the provided handler function +func NewReactivateCommand(handler ReactivateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "reactivate", + Short: "Reactivate an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runReactivate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute value") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runReactivate handles argument and flag extraction +func runReactivate(cmd *cobra.Command, args []string, handler ReactivateHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &ReactivateRequest{ + Flags: ReactivateRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/unsafe/update_generated.go b/cmd/generated/policy/attributes/values/unsafe/update_generated.go new file mode 100644 index 00000000..491a362d --- /dev/null +++ b/cmd/generated/policy/attributes/values/unsafe/update_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values_unsafe + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the attribute value + Value string `json:"value"` // The new value replacing the current value +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Short: "Update an attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the attribute value") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("value", "v", "", "The new value replacing the current value") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + value, _ := cmd.Flags().GetString("value") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Value: value, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/attributes/values/update_generated.go b/cmd/generated/policy/attributes/values/update_generated.go new file mode 100644 index 00000000..d50b7157 --- /dev/null +++ b/cmd/generated/policy/attributes/values/update_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_attributes_values + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The ID of the attribute value to update + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update attribute value", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the attribute value to update") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-grants/_index_generated.go b/cmd/generated/policy/kas-grants/_index_generated.go new file mode 100644 index 00000000..56461fb3 --- /dev/null +++ b/cmd/generated/policy/kas-grants/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_grants + +import ( + + "github.com/spf13/cobra" +) + + +// KasGrantsRequest represents the parameters for the kas-grants command +type KasGrantsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KasGrantsHandler defines the function type for handling kas-grants commands +type KasGrantsHandler func(cmd *cobra.Command, req *KasGrantsRequest) error + +// NewKasGrantsCommand creates a new kas-grants command with the provided handler function +func NewKasGrantsCommand(handler KasGrantsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "kas-grants", + Aliases: []string{"kasg", "kas-grant"}, + Short: "Manage Key Access Server grants", + RunE: func(cmd *cobra.Command, args []string) error { + return runKasGrants(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKasGrants handles argument and flag extraction +func runKasGrants(cmd *cobra.Command, args []string, handler KasGrantsHandler) error { + + // Create request + req := &KasGrantsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-grants/assign_generated.go b/cmd/generated/policy/kas-grants/assign_generated.go new file mode 100644 index 00000000..7c8fc189 --- /dev/null +++ b/cmd/generated/policy/kas-grants/assign_generated.go @@ -0,0 +1,80 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_grants + +import ( + + "github.com/spf13/cobra" +) + +// AssignRequestFlags represents the flags for the assign command +type AssignRequestFlags struct { + NamespaceId string `json:"namespaceId"` // The ID of the Namespace being assigned a KAS Grant + AttributeId string `json:"attributeId"` // The ID of the Attribute Definition being assigned a KAS Grant + ValueId string `json:"valueId"` // The ID of the Value being assigned a KAS Grant + KasId string `json:"kasId"` // The ID of the Key Access Server being assigned to the grant + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// AssignRequest represents the parameters for the assign command +type AssignRequest struct { + Flags AssignRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// AssignHandler defines the function type for handling assign commands +type AssignHandler func(cmd *cobra.Command, req *AssignRequest) error + +// NewAssignCommand creates a new assign command with the provided handler function +func NewAssignCommand(handler AssignHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "assign", + Aliases: []string{"u", "update", "create", "add", "new", "upsert"}, + Short: "Assign a grant", + RunE: func(cmd *cobra.Command, args []string) error { + return runAssign(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("namespace-id", "", "The ID of the Namespace being assigned a KAS Grant") + cmd.Flags().StringP("attribute-id", "a", "", "The ID of the Attribute Definition being assigned a KAS Grant") + cmd.MarkFlagRequired("attribute-id") + cmd.Flags().StringP("value-id", "v", "", "The ID of the Value being assigned a KAS Grant") + cmd.MarkFlagRequired("value-id") + cmd.Flags().StringP("kas-id", "k", "", "The ID of the Key Access Server being assigned to the grant") + cmd.MarkFlagRequired("kas-id") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runAssign handles argument and flag extraction +func runAssign(cmd *cobra.Command, args []string, handler AssignHandler) error { + namespaceId, _ := cmd.Flags().GetString("namespace-id") + attributeId, _ := cmd.Flags().GetString("attribute-id") + valueId, _ := cmd.Flags().GetString("value-id") + kasId, _ := cmd.Flags().GetString("kas-id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &AssignRequest{ + Flags: AssignRequestFlags{ + NamespaceId: namespaceId, + AttributeId: attributeId, + ValueId: valueId, + KasId: kasId, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-grants/list_generated.go b/cmd/generated/policy/kas-grants/list_generated.go new file mode 100644 index 00000000..d592792b --- /dev/null +++ b/cmd/generated/policy/kas-grants/list_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_grants + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Kas string `json:"kas"` // The optional ID or URI of a KAS to filter the list + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List KAS Grants", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("kas", "k", "", "The optional ID or URI of a KAS to filter the list") + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + kas, _ := cmd.Flags().GetString("kas") + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Kas: kas, + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-grants/unassign_generated.go b/cmd/generated/policy/kas-grants/unassign_generated.go new file mode 100644 index 00000000..60c62e0f --- /dev/null +++ b/cmd/generated/policy/kas-grants/unassign_generated.go @@ -0,0 +1,76 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_grants + +import ( + + "github.com/spf13/cobra" +) + +// UnassignRequestFlags represents the flags for the unassign command +type UnassignRequestFlags struct { + NamespaceId string `json:"namespaceId"` // The ID of the Namespace being unassigned a KAS Grant + AttributeId string `json:"attributeId"` // The ID of the Attribute Definition being unassigned the KAS grant + ValueId string `json:"valueId"` // The ID of the Value being unassigned the KAS Grant + KasId string `json:"kasId"` // The Key Access Server (KAS) ID being unassigned a grant + Force string `json:"force"` // Force the unassignment with no confirmation +} + +// UnassignRequest represents the parameters for the unassign command +type UnassignRequest struct { + Flags UnassignRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UnassignHandler defines the function type for handling unassign commands +type UnassignHandler func(cmd *cobra.Command, req *UnassignRequest) error + +// NewUnassignCommand creates a new unassign command with the provided handler function +func NewUnassignCommand(handler UnassignHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "unassign", + Aliases: []string{"delete", "remove"}, + Short: "Unassign a grant", + RunE: func(cmd *cobra.Command, args []string) error { + return runUnassign(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("namespace-id", "", "The ID of the Namespace being unassigned a KAS Grant") + cmd.Flags().StringP("attribute-id", "a", "", "The ID of the Attribute Definition being unassigned the KAS grant") + cmd.MarkFlagRequired("attribute-id") + cmd.Flags().StringP("value-id", "v", "", "The ID of the Value being unassigned the KAS Grant") + cmd.MarkFlagRequired("value-id") + cmd.Flags().StringP("kas-id", "k", "", "The Key Access Server (KAS) ID being unassigned a grant") + cmd.MarkFlagRequired("kas-id") + cmd.Flags().String("force", "", "Force the unassignment with no confirmation") + + return cmd +} + +// runUnassign handles argument and flag extraction +func runUnassign(cmd *cobra.Command, args []string, handler UnassignHandler) error { + namespaceId, _ := cmd.Flags().GetString("namespace-id") + attributeId, _ := cmd.Flags().GetString("attribute-id") + valueId, _ := cmd.Flags().GetString("value-id") + kasId, _ := cmd.Flags().GetString("kas-id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &UnassignRequest{ + Flags: UnassignRequestFlags{ + NamespaceId: namespaceId, + AttributeId: attributeId, + ValueId: valueId, + KasId: kasId, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/_index_generated.go b/cmd/generated/policy/kas-registry/_index_generated.go new file mode 100644 index 00000000..ae14c7d4 --- /dev/null +++ b/cmd/generated/policy/kas-registry/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + + +// KasRegistryRequest represents the parameters for the kas-registry command +type KasRegistryRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KasRegistryHandler defines the function type for handling kas-registry commands +type KasRegistryHandler func(cmd *cobra.Command, req *KasRegistryRequest) error + +// NewKasRegistryCommand creates a new kas-registry command with the provided handler function +func NewKasRegistryCommand(handler KasRegistryHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "kas-registry", + Aliases: []string{"kasr", "kas-registries"}, + Short: "Manage KAS registrations", + RunE: func(cmd *cobra.Command, args []string) error { + return runKasRegistry(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKasRegistry handles argument and flag extraction +func runKasRegistry(cmd *cobra.Command, args []string, handler KasRegistryHandler) error { + + // Create request + req := &KasRegistryRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/create_generated.go b/cmd/generated/policy/kas-registry/create_generated.go new file mode 100644 index 00000000..0f090ead --- /dev/null +++ b/cmd/generated/policy/kas-registry/create_generated.go @@ -0,0 +1,74 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Uri string `json:"uri"` // URI of the Key Access Server + PublicKeys string `json:"publicKeys"` // One or more public keys saved for the KAS + PublicKeyRemote string `json:"publicKeyRemote"` // Remote URI where the public key can be retrieved for the KAS + Name string `json:"name"` // Optional name of the registered KAS (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create a Key Access Server registration", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("uri", "u", "", "URI of the Key Access Server") + cmd.MarkFlagRequired("uri") + cmd.Flags().StringP("public-keys", "c", "", "One or more public keys saved for the KAS") + cmd.Flags().StringP("public-key-remote", "r", "", "Remote URI where the public key can be retrieved for the KAS") + cmd.Flags().String("name", "", "Optional name of the registered KAS (must be unique within Policy)") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + uri, _ := cmd.Flags().GetString("uri") + publicKeys, _ := cmd.Flags().GetString("public-keys") + publicKeyRemote, _ := cmd.Flags().GetString("public-key-remote") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Uri: uri, + PublicKeys: publicKeys, + PublicKeyRemote: publicKeyRemote, + Name: name, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/delete_generated.go b/cmd/generated/policy/kas-registry/delete_generated.go new file mode 100644 index 00000000..52bf4150 --- /dev/null +++ b/cmd/generated/policy/kas-registry/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the Key Access Server registration + Force string `json:"force"` // Force deletion without interactive confirmation (dangerous) +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a Key Access Server registration", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the Key Access Server registration") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation (dangerous)") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/get_generated.go b/cmd/generated/policy/kas-registry/get_generated.go new file mode 100644 index 00000000..bd8edb6b --- /dev/null +++ b/cmd/generated/policy/kas-registry/get_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the Key Access Server registration +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a registered Key Access Server", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the Key Access Server registration") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/_index_generated.go b/cmd/generated/policy/kas-registry/key/_index_generated.go new file mode 100644 index 00000000..e3142ea1 --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/_index_generated.go @@ -0,0 +1,48 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + + +// KeyRequest represents the parameters for the key command +type KeyRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// KeyHandler defines the function type for handling key commands +type KeyHandler func(cmd *cobra.Command, req *KeyRequest) error + +// NewKeyCommand creates a new key command with the provided handler function +func NewKeyCommand(handler KeyHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "key", + Aliases: []string{"k"}, + Short: "Key management for KAS Registry", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runKey(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runKey handles argument and flag extraction +func runKey(cmd *cobra.Command, args []string, handler KeyHandler) error { + + // Create request + req := &KeyRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/base/_index_generated.go b/cmd/generated/policy/kas-registry/key/base/_index_generated.go new file mode 100644 index 00000000..17f91a9b --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/base/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key_base + +import ( + + "github.com/spf13/cobra" +) + + +// BaseRequest represents the parameters for the base command +type BaseRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// BaseHandler defines the function type for handling base commands +type BaseHandler func(cmd *cobra.Command, req *BaseRequest) error + +// NewBaseCommand creates a new base command with the provided handler function +func NewBaseCommand(handler BaseHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "base", + Short: "Platform Base Key Management", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runBase(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runBase handles argument and flag extraction +func runBase(cmd *cobra.Command, args []string, handler BaseHandler) error { + + // Create request + req := &BaseRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/base/get_generated.go b/cmd/generated/policy/kas-registry/key/base/get_generated.go new file mode 100644 index 00000000..7f179ab7 --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/base/get_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key_base + +import ( + + "github.com/spf13/cobra" +) + + +// GetRequest represents the parameters for the get command +type GetRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get Base Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + + // Create request + req := &GetRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/base/set_generated.go b/cmd/generated/policy/kas-registry/key/base/set_generated.go new file mode 100644 index 00000000..e6a6940c --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/base/set_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key_base + +import ( + + "github.com/spf13/cobra" +) + +// SetRequestFlags represents the flags for the set command +type SetRequestFlags struct { + Key string `json:"key"` // The KeyID (human-readable identifier) or the internal UUID of an existing key within the specified KAS. This key will be designated as the platform base key. The system will attempt to resolve the provided value as either a UUID or a KeyID. + Kas string `json:"kas"` // Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name. +} + +// SetRequest represents the parameters for the set command +type SetRequest struct { + Flags SetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SetHandler defines the function type for handling set commands +type SetHandler func(cmd *cobra.Command, req *SetRequest) error + +// NewSetCommand creates a new set command with the provided handler function +func NewSetCommand(handler SetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "set", + Aliases: []string{"s"}, + Short: "Set Base Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runSet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("key", "k", "", "The KeyID (human-readable identifier) or the internal UUID of an existing key within the specified KAS. This key will be designated as the platform base key. The system will attempt to resolve the provided value as either a UUID or a KeyID.") + cmd.MarkFlagRequired("key") + cmd.Flags().String("kas", "", "Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name.") + + return cmd +} + +// runSet handles argument and flag extraction +func runSet(cmd *cobra.Command, args []string, handler SetHandler) error { + key, _ := cmd.Flags().GetString("key") + kas, _ := cmd.Flags().GetString("kas") + + // Create request + req := &SetRequest{ + Flags: SetRequestFlags{ + Key: key, + Kas: kas, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/create_generated.go b/cmd/generated/policy/kas-registry/key/create_generated.go new file mode 100644 index 00000000..4dda3d1f --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/create_generated.go @@ -0,0 +1,97 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + KeyId string `json:"keyId"` // A unique, often human-readable, identifier for the new key to be created. + Algorithm string `json:"algorithm"` // Algorithm for the new key (see table below for options). + Mode string `json:"mode"` // Describes how the private key is managed (see table below for options). + Kas string `json:"kas"` // Specify the Key Access Server (KAS) where the new key will be created. The KAS can be identified by its ID, URI, or Name. + WrappingKeyId string `json:"wrappingKeyId"` // Identifier related to the wrapping key. Its meaning depends on the `mode`. For `local` mode, it's a descriptive ID for the `wrappingKey` you provide. For `provider` or `remote` mode, it's the ID of the key within the external provider/system used for wrapping. + WrappingKey string `json:"wrappingKey"` // The symmetric key material (AES cipher, hex encoded) used to wrap the generated private key. Primarily used when `mode` is `local`. + PrivateKeyPem string `json:"privateKeyPem"` // The private key PEM (encrypted by an AES 32-byte key, then base64 encoded). Used when importing an existing key pair, typically with `provider` mode. + ProviderConfigId string `json:"providerConfigId"` // Configuration ID for the key provider. Often required when `mode` is `provider` or `remote` and an external key provider is used. + PublicKeyPem string `json:"publicKeyPem"` // The base64 encoded public key PEM. Required for `remote` and `public_key` modes, and can be used with `provider` mode if importing an existing key pair. + Label string `json:"label"` // Comma-separated key=value pairs for metadata labels to associate with the new key (e.g., \"owner=team-a,env=production\"). +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c"}, + Short: "Create Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("key-id", "", "A unique, often human-readable, identifier for the new key to be created.") + cmd.MarkFlagRequired("key-id") + cmd.Flags().StringP("algorithm", "a", "", "Algorithm for the new key (see table below for options).") + cmd.MarkFlagRequired("algorithm") + cmd.Flags().StringP("mode", "m", "", "Describes how the private key is managed (see table below for options).") + cmd.MarkFlagRequired("mode") + cmd.Flags().String("kas", "", "Specify the Key Access Server (KAS) where the new key will be created. The KAS can be identified by its ID, URI, or Name.") + cmd.MarkFlagRequired("kas") + cmd.Flags().String("wrapping-key-id", "", "Identifier related to the wrapping key. Its meaning depends on the `mode`. For `local` mode, it's a descriptive ID for the `wrappingKey` you provide. For `provider` or `remote` mode, it's the ID of the key within the external provider/system used for wrapping.") + cmd.Flags().StringP("wrapping-key", "w", "", "The symmetric key material (AES cipher, hex encoded) used to wrap the generated private key. Primarily used when `mode` is `local`.") + cmd.Flags().String("private-key-pem", "", "The private key PEM (encrypted by an AES 32-byte key, then base64 encoded). Used when importing an existing key pair, typically with `provider` mode.") + cmd.Flags().StringP("provider-config-id", "p", "", "Configuration ID for the key provider. Often required when `mode` is `provider` or `remote` and an external key provider is used.") + cmd.Flags().StringP("public-key-pem", "e", "", "The base64 encoded public key PEM. Required for `remote` and `public_key` modes, and can be used with `provider` mode if importing an existing key pair.") + cmd.Flags().StringP("label", "l", "", "Comma-separated key=value pairs for metadata labels to associate with the new key (e.g., \"owner=team-a,env=production\").") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + keyId, _ := cmd.Flags().GetString("key-id") + algorithm, _ := cmd.Flags().GetString("algorithm") + mode, _ := cmd.Flags().GetString("mode") + kas, _ := cmd.Flags().GetString("kas") + wrappingKeyId, _ := cmd.Flags().GetString("wrapping-key-id") + wrappingKey, _ := cmd.Flags().GetString("wrapping-key") + privateKeyPem, _ := cmd.Flags().GetString("private-key-pem") + providerConfigId, _ := cmd.Flags().GetString("provider-config-id") + publicKeyPem, _ := cmd.Flags().GetString("public-key-pem") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + KeyId: keyId, + Algorithm: algorithm, + Mode: mode, + Kas: kas, + WrappingKeyId: wrappingKeyId, + WrappingKey: wrappingKey, + PrivateKeyPem: privateKeyPem, + ProviderConfigId: providerConfigId, + PublicKeyPem: publicKeyPem, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/get_generated.go b/cmd/generated/policy/kas-registry/key/get_generated.go new file mode 100644 index 00000000..2314d66c --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/get_generated.go @@ -0,0 +1,63 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Key string `json:"key"` // The KeyID (human-readable identifier) or the internal UUID of the key to retrieve from the specified KAS. The system will attempt to resolve the provided value as either a UUID or a KeyID. + Kas string `json:"kas"` // Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name. +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("key", "k", "", "The KeyID (human-readable identifier) or the internal UUID of the key to retrieve from the specified KAS. The system will attempt to resolve the provided value as either a UUID or a KeyID.") + cmd.MarkFlagRequired("key") + cmd.Flags().String("kas", "", "Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name.") + cmd.MarkFlagRequired("kas") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + key, _ := cmd.Flags().GetString("key") + kas, _ := cmd.Flags().GetString("kas") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Key: key, + Kas: kas, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/list_generated.go b/cmd/generated/policy/kas-registry/key/list_generated.go new file mode 100644 index 00000000..b66f8498 --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/list_generated.go @@ -0,0 +1,72 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Maximum number of keys to return + Offset string `json:"offset"` // Number of keys to skip before starting to return results + Algorithm string `json:"algorithm"` // Key Algorithm to filter for + Kas string `json:"kas"` // Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name. +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Keys", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Maximum number of keys to return") + cmd.MarkFlagRequired("limit") + cmd.Flags().StringP("offset", "o", "", "Number of keys to skip before starting to return results") + cmd.MarkFlagRequired("offset") + cmd.Flags().StringP("algorithm", "a", "", "Key Algorithm to filter for") + cmd.Flags().String("kas", "", "Specify the Key Access Server (KAS) where the key (identified by `--key`) is registered. The KAS can be identified by its ID, URI, or Name.") + cmd.MarkFlagRequired("kas") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + algorithm, _ := cmd.Flags().GetString("algorithm") + kas, _ := cmd.Flags().GetString("kas") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + Algorithm: algorithm, + Kas: kas, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/rotate_generated.go b/cmd/generated/policy/kas-registry/key/rotate_generated.go new file mode 100644 index 00000000..d3de6148 --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/rotate_generated.go @@ -0,0 +1,102 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + +// RotateRequestFlags represents the flags for the rotate command +type RotateRequestFlags struct { + Key string `json:"key"` // The KeyID (human-readable identifier) or the internal UUID of the existing key to rotate from the specified KAS. The system will attempt to resolve the provided value as either a UUID or a KeyID. + Kas string `json:"kas"` // Specify the Key Access Server (KAS) where the key is registered. The KAS can be identified by its ID, URI, or Name. + KeyId string `json:"keyId"` // A unique, often human-readable, identifier for the new key to be created. + Algorithm string `json:"algorithm"` // Algorithm for the new key (see table below for options). + Mode string `json:"mode"` // Describes how the private key is managed (see table below for options). + WrappingKeyId string `json:"wrappingKeyId"` // Identifier related to the wrapping key. Its meaning depends on the `mode`. For `local` mode, it's a descriptive ID for the `wrappingKey` you provide. For `provider` or `remote` mode, it's the ID of the key within the external provider/system used for wrapping. + WrappingKey string `json:"wrappingKey"` // The symmetric key material (AES cipher, base64 encoded) used to wrap the generated private key. Primarily used when `mode` is `local`. + PrivateKeyPem string `json:"privateKeyPem"` // The private key PEM (encrypted by an AES 32-byte key, then base64 encoded). Used when importing an existing key pair, typically with `provider` mode. + ProviderConfigId string `json:"providerConfigId"` // Configuration ID for the key provider. Often required when `mode` is `provider` or `remote` and an external key provider is used. + PublicKeyPem string `json:"publicKeyPem"` // The base64 encoded public key PEM. Required for `remote` and `public_key` modes, and can be used with `provider` mode if importing an existing key pair. + Label string `json:"label"` // Comma-separated key=value pairs for metadata labels to associate with the new key (e.g., \"owner=team-a,env=production\"). +} + +// RotateRequest represents the parameters for the rotate command +type RotateRequest struct { + Flags RotateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// RotateHandler defines the function type for handling rotate commands +type RotateHandler func(cmd *cobra.Command, req *RotateRequest) error + +// NewRotateCommand creates a new rotate command with the provided handler function +func NewRotateCommand(handler RotateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "rotate", + Aliases: []string{"r"}, + Short: "Rotate Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runRotate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("key", "k", "", "The KeyID (human-readable identifier) or the internal UUID of the existing key to rotate from the specified KAS. The system will attempt to resolve the provided value as either a UUID or a KeyID.") + cmd.MarkFlagRequired("key") + cmd.Flags().String("kas", "", "Specify the Key Access Server (KAS) where the key is registered. The KAS can be identified by its ID, URI, or Name.") + cmd.MarkFlagRequired("kas") + cmd.Flags().String("key-id", "", "A unique, often human-readable, identifier for the new key to be created.") + cmd.MarkFlagRequired("key-id") + cmd.Flags().StringP("algorithm", "a", "", "Algorithm for the new key (see table below for options).") + cmd.MarkFlagRequired("algorithm") + cmd.Flags().StringP("mode", "m", "", "Describes how the private key is managed (see table below for options).") + cmd.MarkFlagRequired("mode") + cmd.Flags().String("wrapping-key-id", "", "Identifier related to the wrapping key. Its meaning depends on the `mode`. For `local` mode, it's a descriptive ID for the `wrappingKey` you provide. For `provider` or `remote` mode, it's the ID of the key within the external provider/system used for wrapping.") + cmd.Flags().StringP("wrapping-key", "w", "", "The symmetric key material (AES cipher, base64 encoded) used to wrap the generated private key. Primarily used when `mode` is `local`.") + cmd.Flags().String("private-key-pem", "", "The private key PEM (encrypted by an AES 32-byte key, then base64 encoded). Used when importing an existing key pair, typically with `provider` mode.") + cmd.Flags().StringP("provider-config-id", "p", "", "Configuration ID for the key provider. Often required when `mode` is `provider` or `remote` and an external key provider is used.") + cmd.Flags().StringP("public-key-pem", "e", "", "The base64 encoded public key PEM. Required for `remote` and `public_key` modes, and can be used with `provider` mode if importing an existing key pair.") + cmd.Flags().StringP("label", "l", "", "Comma-separated key=value pairs for metadata labels to associate with the new key (e.g., \"owner=team-a,env=production\").") + + return cmd +} + +// runRotate handles argument and flag extraction +func runRotate(cmd *cobra.Command, args []string, handler RotateHandler) error { + key, _ := cmd.Flags().GetString("key") + kas, _ := cmd.Flags().GetString("kas") + keyId, _ := cmd.Flags().GetString("key-id") + algorithm, _ := cmd.Flags().GetString("algorithm") + mode, _ := cmd.Flags().GetString("mode") + wrappingKeyId, _ := cmd.Flags().GetString("wrapping-key-id") + wrappingKey, _ := cmd.Flags().GetString("wrapping-key") + privateKeyPem, _ := cmd.Flags().GetString("private-key-pem") + providerConfigId, _ := cmd.Flags().GetString("provider-config-id") + publicKeyPem, _ := cmd.Flags().GetString("public-key-pem") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &RotateRequest{ + Flags: RotateRequestFlags{ + Key: key, + Kas: kas, + KeyId: keyId, + Algorithm: algorithm, + Mode: mode, + WrappingKeyId: wrappingKeyId, + WrappingKey: wrappingKey, + PrivateKeyPem: privateKeyPem, + ProviderConfigId: providerConfigId, + PublicKeyPem: publicKeyPem, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/key/update_generated.go b/cmd/generated/policy/kas-registry/key/update_generated.go new file mode 100644 index 00000000..4ceb9f78 --- /dev/null +++ b/cmd/generated/policy/kas-registry/key/update_generated.go @@ -0,0 +1,62 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry_key + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The internal UUID of the key to be updated. + Label string `json:"label"` // Comma-separated key=value pairs for metadata labels (e.g., \"owner=team-a,env=production\"). Providing new labels will replace any existing labels on the key. +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update Key Access Server Key", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The internal UUID of the key to be updated.") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("label", "l", "", "Comma-separated key=value pairs for metadata labels (e.g., \"owner=team-a,env=production\"). Providing new labels will replace any existing labels on the key.") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/list_generated.go b/cmd/generated/policy/kas-registry/list_generated.go new file mode 100644 index 00000000..0388b8c4 --- /dev/null +++ b/cmd/generated/policy/kas-registry/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Key Access Server registrations", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/kas-registry/update_generated.go b/cmd/generated/policy/kas-registry/update_generated.go new file mode 100644 index 00000000..e7d6b7bf --- /dev/null +++ b/cmd/generated/policy/kas-registry/update_generated.go @@ -0,0 +1,82 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_kas_registry + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the Key Access Server registration + Uri string `json:"uri"` // URI of the Key Access Server + PublicKeys string `json:"publicKeys"` // One or more 'cached' public keys saved for the KAS + PublicKeyRemote string `json:"publicKeyRemote"` // URI of the 'remote' public key of the Key Access Server + Name string `json:"name"` // Optional name of the registered KAS (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Key Access Server registration", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the Key Access Server registration") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("uri", "u", "", "URI of the Key Access Server") + cmd.Flags().StringP("public-keys", "c", "", "One or more 'cached' public keys saved for the KAS") + cmd.Flags().StringP("public-key-remote", "r", "", "URI of the 'remote' public key of the Key Access Server") + cmd.Flags().String("name", "", "Optional name of the registered KAS (must be unique within Policy)") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + uri, _ := cmd.Flags().GetString("uri") + publicKeys, _ := cmd.Flags().GetString("public-keys") + publicKeyRemote, _ := cmd.Flags().GetString("public-key-remote") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Uri: uri, + PublicKeys: publicKeys, + PublicKeyRemote: publicKeyRemote, + Name: name, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/key-management/_index_generated.go b/cmd/generated/policy/key-management/_index_generated.go new file mode 100644 index 00000000..92561072 --- /dev/null +++ b/cmd/generated/policy/key-management/_index_generated.go @@ -0,0 +1,55 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management + +import ( + + "github.com/spf13/cobra" +) + +// KeymanagementRequestFlags represents the flags for the keymanagement command +type KeymanagementRequestFlags struct { + Json string `json:"json"` // output single command in JSON (overrides configured output format) +} + +// KeymanagementRequest represents the parameters for the keymanagement command +type KeymanagementRequest struct { + Flags KeymanagementRequestFlags `json:"flags"` +} + +// KeymanagementHandler defines the interface for handling keymanagement commands +type KeymanagementHandler interface { + HandleKeymanagement(cmd *cobra.Command, req *KeymanagementRequest) error +} + +// NewKeymanagementCommand creates a new keymanagement command with the provided handler +func NewKeymanagementCommand(handler KeymanagementHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "keymanagement", + Aliases: []string{"k"}, + Short: "Key management", + RunE: func(cmd *cobra.Command, args []string) error { + return runKeymanagement(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().String("json", "false", "output single command in JSON (overrides configured output format)") + + return cmd +} + +// runKeymanagement handles argument and flag extraction +func runKeymanagement(cmd *cobra.Command, args []string, handler KeymanagementHandler) error { + json, _ := cmd.Flags().GetString("json") + + // Create request + req := &KeymanagementRequest{ + Flags: KeymanagementRequestFlags{ + Json: json, + }, + } + + // Call handler + return handler.HandleKeymanagement(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/_index_generated.go b/cmd/generated/policy/key-management/provider/_index_generated.go new file mode 100644 index 00000000..c3b9ca8a --- /dev/null +++ b/cmd/generated/policy/key-management/provider/_index_generated.go @@ -0,0 +1,45 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + + +// ProviderRequest represents the parameters for the provider command +type ProviderRequest struct { +} + +// ProviderHandler defines the interface for handling provider commands +type ProviderHandler interface { + HandleProvider(cmd *cobra.Command, req *ProviderRequest) error +} + +// NewProviderCommand creates a new provider command with the provided handler +func NewProviderCommand(handler ProviderHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "provider", + Aliases: []string{"p"}, + Short: "Provider configuration for Key Management", + RunE: func(cmd *cobra.Command, args []string) error { + return runProvider(cmd, args, handler) + }, + } + + // Register flags + + return cmd +} + +// runProvider handles argument and flag extraction +func runProvider(cmd *cobra.Command, args []string, handler ProviderHandler) error { + + // Create request + req := &ProviderRequest{ + } + + // Call handler + return handler.HandleProvider(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/create_generated.go b/cmd/generated/policy/key-management/provider/create_generated.go new file mode 100644 index 00000000..558bae68 --- /dev/null +++ b/cmd/generated/policy/key-management/provider/create_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the provider config to create + Config string `json:"config"` // JSON configuration for the provider + Label string `json:"label"` // Metadata labels for the provider config +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` +} + +// CreateHandler defines the interface for handling create commands +type CreateHandler interface { + HandleCreate(cmd *cobra.Command, req *CreateRequest) error +} + +// NewCreateCommand creates a new create command with the provided handler +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c"}, + Short: "Create a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().String("name", "", "Name of the provider config to create") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("config", "c", "", "JSON configuration for the provider") + cmd.MarkFlagRequired("config") + cmd.Flags().StringP("label", "l", "", "Metadata labels for the provider config") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + config, _ := cmd.Flags().GetString("config") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Config: config, + Label: label, + }, + } + + // Call handler + return handler.HandleCreate(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/delete_generated.go b/cmd/generated/policy/key-management/provider/delete_generated.go new file mode 100644 index 00000000..31033c31 --- /dev/null +++ b/cmd/generated/policy/key-management/provider/delete_generated.go @@ -0,0 +1,60 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Force string `json:"force"` // Force the deletion of a provider configuration without confirmation + Id string `json:"id"` // ID of the provider config to delete +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` +} + +// DeleteHandler defines the interface for handling delete commands +type DeleteHandler interface { + HandleDelete(cmd *cobra.Command, req *DeleteRequest) error +} + +// NewDeleteCommand creates a new delete command with the provided handler +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Aliases: []string{"d", "remove"}, + Short: "Delete a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("force", "f", "", "Force the deletion of a provider configuration without confirmation") + cmd.Flags().StringP("id", "i", "", "ID of the provider config to delete") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + force, _ := cmd.Flags().GetString("force") + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Force: force, + Id: id, + }, + } + + // Call handler + return handler.HandleDelete(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/get_generated.go b/cmd/generated/policy/key-management/provider/get_generated.go new file mode 100644 index 00000000..480ef55c --- /dev/null +++ b/cmd/generated/policy/key-management/provider/get_generated.go @@ -0,0 +1,59 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the provider config to retrieve + Name string `json:"name"` // Name of the provider config to retrieve +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` +} + +// GetHandler defines the interface for handling get commands +type GetHandler interface { + HandleGet(cmd *cobra.Command, req *GetRequest) error +} + +// NewGetCommand creates a new get command with the provided handler +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the provider config to retrieve") + cmd.Flags().String("name", "", "Name of the provider config to retrieve") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + Name: name, + }, + } + + // Call handler + return handler.HandleGet(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/list_generated.go b/cmd/generated/policy/key-management/provider/list_generated.go new file mode 100644 index 00000000..90e58f9a --- /dev/null +++ b/cmd/generated/policy/key-management/provider/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Maximum number of results to return + Offset string `json:"offset"` // Offset for pagination +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` +} + +// ListHandler defines the interface for handling list commands +type ListHandler interface { + HandleList(cmd *cobra.Command, req *ListRequest) error +} + +// NewListCommand creates a new list command with the provided handler +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Provider Configs", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Maximum number of results to return") + cmd.MarkFlagRequired("limit") + cmd.Flags().StringP("offset", "o", "", "Offset for pagination") + cmd.MarkFlagRequired("offset") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + } + + // Call handler + return handler.HandleList(cmd, req) +} diff --git a/cmd/generated/policy/key-management/provider/update_generated.go b/cmd/generated/policy/key-management/provider/update_generated.go new file mode 100644 index 00000000..e3a8fbb1 --- /dev/null +++ b/cmd/generated/policy/key-management/provider/update_generated.go @@ -0,0 +1,68 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_key_management_provider + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the provider config to update + Name string `json:"name"` // New name for the provider config + Config string `json:"config"` // New JSON configuration for the provider + Label string `json:"label"` // Metadata labels for the provider config +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` +} + +// UpdateHandler defines the interface for handling update commands +type UpdateHandler interface { + HandleUpdate(cmd *cobra.Command, req *UpdateRequest) error +} + +// NewUpdateCommand creates a new update command with the provided handler +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Provider Config", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the provider config to update") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "New name for the provider config") + cmd.Flags().StringP("config", "c", "", "New JSON configuration for the provider") + cmd.Flags().StringP("label", "l", "", "Metadata labels for the provider config") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + config, _ := cmd.Flags().GetString("config") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + Config: config, + Label: label, + }, + } + + // Call handler + return handler.HandleUpdate(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/_index_generated.go b/cmd/generated/policy/registered-resources/_index_generated.go new file mode 100644 index 00000000..45194eb3 --- /dev/null +++ b/cmd/generated/policy/registered-resources/_index_generated.go @@ -0,0 +1,48 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + + +// RegisteredResourcesRequest represents the parameters for the registered-resources command +type RegisteredResourcesRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// RegisteredResourcesHandler defines the function type for handling registered-resources commands +type RegisteredResourcesHandler func(cmd *cobra.Command, req *RegisteredResourcesRequest) error + +// NewRegisteredResourcesCommand creates a new registered-resources command with the provided handler function +func NewRegisteredResourcesCommand(handler RegisteredResourcesHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "registered-resources", + Aliases: []string{"reg-res"}, + Short: "Manage Registered Resources", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runRegisteredResources(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runRegisteredResources handles argument and flag extraction +func runRegisteredResources(cmd *cobra.Command, args []string, handler RegisteredResourcesHandler) error { + + // Create request + req := &RegisteredResourcesRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/create_generated.go b/cmd/generated/policy/registered-resources/create_generated.go new file mode 100644 index 00000000..3a853d42 --- /dev/null +++ b/cmd/generated/policy/registered-resources/create_generated.go @@ -0,0 +1,66 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Name string `json:"name"` // Name of the registered resource (must be unique within Policy) + Value string `json:"value"` // Value of the registered resource (i.e. 'value1', must be unique within the Registered Resource) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create a Registered Resource", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("name", "", "Name of the registered resource (must be unique within Policy)") + cmd.MarkFlagRequired("name") + cmd.Flags().StringP("value", "v", "", "Value of the registered resource (i.e. 'value1', must be unique within the Registered Resource)") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + name, _ := cmd.Flags().GetString("name") + value, _ := cmd.Flags().GetString("value") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Name: name, + Value: value, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/delete_generated.go b/cmd/generated/policy/registered-resources/delete_generated.go new file mode 100644 index 00000000..a7ed412b --- /dev/null +++ b/cmd/generated/policy/registered-resources/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the registered resource + Force string `json:"force"` // Force deletion without interactive confirmation +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a Registered Resource", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/get_generated.go b/cmd/generated/policy/registered-resources/get_generated.go new file mode 100644 index 00000000..2add6425 --- /dev/null +++ b/cmd/generated/policy/registered-resources/get_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the registered resource + Name string `json:"name"` // Name of the registered resource +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Registered Resource", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource") + cmd.Flags().String("name", "", "Name of the registered resource") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + Name: name, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/list_generated.go b/cmd/generated/policy/registered-resources/list_generated.go new file mode 100644 index 00000000..87797035 --- /dev/null +++ b/cmd/generated/policy/registered-resources/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Registered Resources", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/update_generated.go b/cmd/generated/policy/registered-resources/update_generated.go new file mode 100644 index 00000000..b09873be --- /dev/null +++ b/cmd/generated/policy/registered-resources/update_generated.go @@ -0,0 +1,70 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the registered resource to update + Name string `json:"name"` // Optional updated name of the registered resource (must be unique within Policy) + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Registered Resource", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource to update") + cmd.MarkFlagRequired("id") + cmd.Flags().String("name", "", "Optional updated name of the registered resource (must be unique within Policy)") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Name: name, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/_index_generated.go b/cmd/generated/policy/registered-resources/values/_index_generated.go new file mode 100644 index 00000000..9cf97819 --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/_index_generated.go @@ -0,0 +1,48 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + + +// ValuesRequest represents the parameters for the values command +type ValuesRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ValuesHandler defines the function type for handling values commands +type ValuesHandler func(cmd *cobra.Command, req *ValuesRequest) error + +// NewValuesCommand creates a new values command with the provided handler function +func NewValuesCommand(handler ValuesHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "values", + Aliases: []string{"val", "value"}, + Short: "Manage Registered Resource Values", + Hidden: true, + RunE: func(cmd *cobra.Command, args []string) error { + return runValues(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runValues handles argument and flag extraction +func runValues(cmd *cobra.Command, args []string, handler ValuesHandler) error { + + // Create request + req := &ValuesRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/create_generated.go b/cmd/generated/policy/registered-resources/values/create_generated.go new file mode 100644 index 00000000..46be94db --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/create_generated.go @@ -0,0 +1,71 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + Resource string `json:"resource"` // Identifier of the associated registered resource (ID or name) + Value string `json:"value"` // Value of the registered resource (i.e. 'value1', must be unique within the Registered Resource) + ActionAttributeValue string `json:"actionAttributeValue"` // Optional action attribute values in the format: \";\" + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create Registered Resource Value", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("resource", "r", "", "Identifier of the associated registered resource (ID or name)") + cmd.MarkFlagRequired("resource") + cmd.Flags().StringP("value", "v", "", "Value of the registered resource (i.e. 'value1', must be unique within the Registered Resource)") + cmd.MarkFlagRequired("value") + cmd.Flags().StringP("action-attribute-value", "a", "", "Optional action attribute values in the format: \";\"") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + resource, _ := cmd.Flags().GetString("resource") + value, _ := cmd.Flags().GetString("value") + actionAttributeValue, _ := cmd.Flags().GetString("action-attribute-value") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + Resource: resource, + Value: value, + ActionAttributeValue: actionAttributeValue, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/delete_generated.go b/cmd/generated/policy/registered-resources/values/delete_generated.go new file mode 100644 index 00000000..1c19da40 --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // ID of the registered resource value + Force string `json:"force"` // Force deletion without interactive confirmation +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a Registered Resource Value", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource value") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/get_generated.go b/cmd/generated/policy/registered-resources/values/get_generated.go new file mode 100644 index 00000000..f74031d2 --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/get_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // ID of the registered resource value + Fqn string `json:"fqn"` // FQN of the registered resource value +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Registered Resource Value", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource value") + cmd.Flags().StringP("fqn", "f", "", "FQN of the registered resource value") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + fqn, _ := cmd.Flags().GetString("fqn") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + Fqn: fqn, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/list_generated.go b/cmd/generated/policy/registered-resources/values/list_generated.go new file mode 100644 index 00000000..20e284d7 --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/list_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Resource string `json:"resource"` // Identifier of the associated registered resource (ID or name) + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Registered Resource Values", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("resource", "r", "", "Identifier of the associated registered resource (ID or name)") + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + resource, _ := cmd.Flags().GetString("resource") + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Resource: resource, + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/registered-resources/values/update_generated.go b/cmd/generated/policy/registered-resources/values/update_generated.go new file mode 100644 index 00000000..14d71607 --- /dev/null +++ b/cmd/generated/policy/registered-resources/values/update_generated.go @@ -0,0 +1,69 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_registered_resources_values + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // ID of the registered resource value to update + Value string `json:"value"` // Optional updated value of the registered resource value (must be unique within the Registered Resource) + ActionAttributeValue string `json:"actionAttributeValue"` // Optional action attribute values in the format: \";\" + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Registered Resource Value", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "ID of the registered resource value to update") + cmd.Flags().StringP("value", "v", "", "Optional updated value of the registered resource value (must be unique within the Registered Resource)") + cmd.Flags().StringP("action-attribute-value", "a", "", "Optional action attribute values in the format: \";\"") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + value, _ := cmd.Flags().GetString("value") + actionAttributeValue, _ := cmd.Flags().GetString("action-attribute-value") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Value: value, + ActionAttributeValue: actionAttributeValue, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/_index_generated.go b/cmd/generated/policy/resource-mapping-groups/_index_generated.go new file mode 100644 index 00000000..f1c29c3d --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + + +// ResourceMappingGroupsRequest represents the parameters for the resource-mapping-groups command +type ResourceMappingGroupsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ResourceMappingGroupsHandler defines the function type for handling resource-mapping-groups commands +type ResourceMappingGroupsHandler func(cmd *cobra.Command, req *ResourceMappingGroupsRequest) error + +// NewResourceMappingGroupsCommand creates a new resource-mapping-groups command with the provided handler function +func NewResourceMappingGroupsCommand(handler ResourceMappingGroupsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "resource-mapping-groups", + Aliases: []string{"resmg", "remapgrp", "resource-mapping-group"}, + Short: "Manage resource mapping groups", + RunE: func(cmd *cobra.Command, args []string) error { + return runResourceMappingGroups(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runResourceMappingGroups handles argument and flag extraction +func runResourceMappingGroups(cmd *cobra.Command, args []string, handler ResourceMappingGroupsHandler) error { + + // Create request + req := &ResourceMappingGroupsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/create_generated.go b/cmd/generated/policy/resource-mapping-groups/create_generated.go new file mode 100644 index 00000000..df0cbfe5 --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/create_generated.go @@ -0,0 +1,65 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + NamespaceId string `json:"namespaceId"` // The ID of the namespace of the group + Name string `json:"name"` // The name of the group + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"add", "new", "c"}, + Short: "Create a resource mapping group", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("namespace-id", "", "The ID of the namespace of the group") + cmd.Flags().String("name", "", "The name of the group") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + namespaceId, _ := cmd.Flags().GetString("namespace-id") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + NamespaceId: namespaceId, + Name: name, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/delete_generated.go b/cmd/generated/policy/resource-mapping-groups/delete_generated.go new file mode 100644 index 00000000..218d2f95 --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/delete_generated.go @@ -0,0 +1,60 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping group to delete + Force string `json:"force"` // Force deletion without interactive confirmation (dangerous) +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a resource mapping group", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping group to delete") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation (dangerous)") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/get_generated.go b/cmd/generated/policy/resource-mapping-groups/get_generated.go new file mode 100644 index 00000000..de9a024e --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/get_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping group to get. +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a resource mapping group", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping group to get.") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/list_generated.go b/cmd/generated/policy/resource-mapping-groups/list_generated.go new file mode 100644 index 00000000..6893f218 --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List resource mapping groups", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mapping-groups/update_generated.go b/cmd/generated/policy/resource-mapping-groups/update_generated.go new file mode 100644 index 00000000..8d965361 --- /dev/null +++ b/cmd/generated/policy/resource-mapping-groups/update_generated.go @@ -0,0 +1,73 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mapping_groups + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping group to update. + NamespaceId string `json:"namespaceId"` // The ID of the namespace of the group + Name string `json:"name"` // The name of the group + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a resource mapping group", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping group to update.") + cmd.Flags().String("namespace-id", "", "The ID of the namespace of the group") + cmd.Flags().String("name", "", "The name of the group") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + namespaceId, _ := cmd.Flags().GetString("namespace-id") + name, _ := cmd.Flags().GetString("name") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + NamespaceId: namespaceId, + Name: name, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/_index_generated.go b/cmd/generated/policy/resource-mappings/_index_generated.go new file mode 100644 index 00000000..a83990ef --- /dev/null +++ b/cmd/generated/policy/resource-mappings/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + + +// ResourceMappingsRequest represents the parameters for the resource-mappings command +type ResourceMappingsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ResourceMappingsHandler defines the function type for handling resource-mappings commands +type ResourceMappingsHandler func(cmd *cobra.Command, req *ResourceMappingsRequest) error + +// NewResourceMappingsCommand creates a new resource-mappings command with the provided handler function +func NewResourceMappingsCommand(handler ResourceMappingsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "resource-mappings", + Aliases: []string{"resm", "remap", "resource-mapping"}, + Short: "Manage resource mappings", + RunE: func(cmd *cobra.Command, args []string) error { + return runResourceMappings(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runResourceMappings handles argument and flag extraction +func runResourceMappings(cmd *cobra.Command, args []string, handler ResourceMappingsHandler) error { + + // Create request + req := &ResourceMappingsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/create_generated.go b/cmd/generated/policy/resource-mappings/create_generated.go new file mode 100644 index 00000000..b2301a6e --- /dev/null +++ b/cmd/generated/policy/resource-mappings/create_generated.go @@ -0,0 +1,69 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + AttributeValueId string `json:"attributeValueId"` // The ID of the attribute value to map to the resource. + Terms string `json:"terms"` // The synonym terms to match for the resource mapping. + GroupId string `json:"groupId"` // The ID of the resource mapping group to assign this mapping to + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"add", "new", "c"}, + Short: "Create a resource mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("attribute-value-id", "", "The ID of the attribute value to map to the resource.") + cmd.Flags().String("terms", "", "The synonym terms to match for the resource mapping.") + cmd.Flags().String("group-id", "", "The ID of the resource mapping group to assign this mapping to") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + attributeValueId, _ := cmd.Flags().GetString("attribute-value-id") + terms, _ := cmd.Flags().GetString("terms") + groupId, _ := cmd.Flags().GetString("group-id") + label, _ := cmd.Flags().GetString("label") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + AttributeValueId: attributeValueId, + Terms: terms, + GroupId: groupId, + Label: label, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/delete_generated.go b/cmd/generated/policy/resource-mappings/delete_generated.go new file mode 100644 index 00000000..78d6e5ae --- /dev/null +++ b/cmd/generated/policy/resource-mappings/delete_generated.go @@ -0,0 +1,60 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping to delete + Force string `json:"force"` // Force deletion without interactive confirmation (dangerous) +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a resource mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping to delete") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation (dangerous)") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/get_generated.go b/cmd/generated/policy/resource-mappings/get_generated.go new file mode 100644 index 00000000..1d76e0af --- /dev/null +++ b/cmd/generated/policy/resource-mappings/get_generated.go @@ -0,0 +1,57 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping to get. +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a resource mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping to get.") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/list_generated.go b/cmd/generated/policy/resource-mappings/list_generated.go new file mode 100644 index 00000000..1fee39a4 --- /dev/null +++ b/cmd/generated/policy/resource-mappings/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List resource mappings", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/resource-mappings/update_generated.go b/cmd/generated/policy/resource-mappings/update_generated.go new file mode 100644 index 00000000..addecda6 --- /dev/null +++ b/cmd/generated/policy/resource-mappings/update_generated.go @@ -0,0 +1,77 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_resource_mappings + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The ID of the resource mapping to update. + AttributeValueId string `json:"attributeValueId"` // The ID of the attribute value to map to the resource. + Terms string `json:"terms"` // The synonym terms to match for the resource mapping. + GroupId string `json:"groupId"` // The ID of the resource mapping group to assign this mapping to + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a resource mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("id", "", "The ID of the resource mapping to update.") + cmd.Flags().String("attribute-value-id", "", "The ID of the attribute value to map to the resource.") + cmd.Flags().String("terms", "", "The synonym terms to match for the resource mapping.") + cmd.Flags().String("group-id", "", "The ID of the resource mapping group to assign this mapping to") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + attributeValueId, _ := cmd.Flags().GetString("attribute-value-id") + terms, _ := cmd.Flags().GetString("terms") + groupId, _ := cmd.Flags().GetString("group-id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + AttributeValueId: attributeValueId, + Terms: terms, + GroupId: groupId, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/_index_generated.go b/cmd/generated/policy/subject-condition-sets/_index_generated.go new file mode 100644 index 00000000..91bfa96e --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + + +// SubjectConditionSetsRequest represents the parameters for the subject-condition-sets command +type SubjectConditionSetsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SubjectConditionSetsHandler defines the function type for handling subject-condition-sets commands +type SubjectConditionSetsHandler func(cmd *cobra.Command, req *SubjectConditionSetsRequest) error + +// NewSubjectConditionSetsCommand creates a new subject-condition-sets command with the provided handler function +func NewSubjectConditionSetsCommand(handler SubjectConditionSetsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "subject-condition-sets", + Aliases: []string{"subcs", "scs", "subject-condition-set"}, + Short: "Subject condition sets", + RunE: func(cmd *cobra.Command, args []string) error { + return runSubjectConditionSets(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runSubjectConditionSets handles argument and flag extraction +func runSubjectConditionSets(cmd *cobra.Command, args []string, handler SubjectConditionSetsHandler) error { + + // Create request + req := &SubjectConditionSetsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/create_generated.go b/cmd/generated/policy/subject-condition-sets/create_generated.go new file mode 100644 index 00000000..42bd80ea --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/create_generated.go @@ -0,0 +1,70 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + SubjectSets string `json:"subjectSets"` // A JSON array of subject sets, containing a list of condition groups, each with one or more conditions + SubjectSetsFileJson string `json:"subjectSetsFileJson"` // A JSON file with path from the current working directory containing an array of subject sets + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"c", "add", "new"}, + Short: "Create a Subject Condition Set", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("subject-sets", "s", "", "A JSON array of subject sets, containing a list of condition groups, each with one or more conditions") + cmd.MarkFlagRequired("subject-sets") + cmd.Flags().StringP("subject-sets-file-json", "j", "", "A JSON file with path from the current working directory containing an array of subject sets") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + subjectSets, _ := cmd.Flags().GetString("subject-sets") + subjectSetsFileJson, _ := cmd.Flags().GetString("subject-sets-file-json") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + SubjectSets: subjectSets, + SubjectSetsFileJson: subjectSetsFileJson, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/delete_generated.go b/cmd/generated/policy/subject-condition-sets/delete_generated.go new file mode 100644 index 00000000..d66ebec2 --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // The ID of the subject condition set to delete + Force string `json:"force"` // Force deletion without interactive confirmation (dangerous) +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a Subject Condition Set", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject condition set to delete") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation (dangerous)") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/get_generated.go b/cmd/generated/policy/subject-condition-sets/get_generated.go new file mode 100644 index 00000000..76f98b23 --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/get_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // The ID of the subject condition set to get +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a Subject Condition Set", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject condition set to get") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/list_generated.go b/cmd/generated/policy/subject-condition-sets/list_generated.go new file mode 100644 index 00000000..aad25d7a --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List Subject Condition Set", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/prune_generated.go b/cmd/generated/policy/subject-condition-sets/prune_generated.go new file mode 100644 index 00000000..ed8dbf21 --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/prune_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// PruneRequestFlags represents the flags for the prune command +type PruneRequestFlags struct { + Force string `json:"force"` // Force prune without interactive confirmation (dangerous) +} + +// PruneRequest represents the parameters for the prune command +type PruneRequest struct { + Flags PruneRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// PruneHandler defines the function type for handling prune commands +type PruneHandler func(cmd *cobra.Command, req *PruneRequest) error + +// NewPruneCommand creates a new prune command with the provided handler function +func NewPruneCommand(handler PruneHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "prune", + Short: "Prune (delete all un-mapped Subject Condition Sets)", + RunE: func(cmd *cobra.Command, args []string) error { + return runPrune(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().String("force", "", "Force prune without interactive confirmation (dangerous)") + + return cmd +} + +// runPrune handles argument and flag extraction +func runPrune(cmd *cobra.Command, args []string, handler PruneHandler) error { + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &PruneRequest{ + Flags: PruneRequestFlags{ + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-condition-sets/update_generated.go b/cmd/generated/policy/subject-condition-sets/update_generated.go new file mode 100644 index 00000000..939fcfe8 --- /dev/null +++ b/cmd/generated/policy/subject-condition-sets/update_generated.go @@ -0,0 +1,74 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_condition_sets + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The ID of the subject condition set to update + SubjectSets string `json:"subjectSets"` // A JSON array of subject sets, containing a list of condition groups, each with one or more conditions + SubjectSetsFileJson string `json:"subjectSetsFileJson"` // A JSON file with path from the current working directory containing an array of subject sets + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a Subject Condition Set", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject condition set to update") + cmd.MarkFlagRequired("id") + cmd.Flags().StringP("subject-sets", "s", "", "A JSON array of subject sets, containing a list of condition groups, each with one or more conditions") + cmd.Flags().StringP("subject-sets-file-json", "j", "", "A JSON file with path from the current working directory containing an array of subject sets") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + subjectSets, _ := cmd.Flags().GetString("subject-sets") + subjectSetsFileJson, _ := cmd.Flags().GetString("subject-sets-file-json") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + SubjectSets: subjectSets, + SubjectSetsFileJson: subjectSetsFileJson, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/_index_generated.go b/cmd/generated/policy/subject-mappings/_index_generated.go new file mode 100644 index 00000000..d2588b3c --- /dev/null +++ b/cmd/generated/policy/subject-mappings/_index_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + + +// SubjectMappingsRequest represents the parameters for the subject-mappings command +type SubjectMappingsRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SubjectMappingsHandler defines the function type for handling subject-mappings commands +type SubjectMappingsHandler func(cmd *cobra.Command, req *SubjectMappingsRequest) error + +// NewSubjectMappingsCommand creates a new subject-mappings command with the provided handler function +func NewSubjectMappingsCommand(handler SubjectMappingsHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "subject-mappings", + Aliases: []string{"subm", "sm", "submap", "subject-mapping"}, + Short: "Subject mappings", + RunE: func(cmd *cobra.Command, args []string) error { + return runSubjectMappings(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runSubjectMappings handles argument and flag extraction +func runSubjectMappings(cmd *cobra.Command, args []string, handler SubjectMappingsHandler) error { + + // Create request + req := &SubjectMappingsRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/create_generated.go b/cmd/generated/policy/subject-mappings/create_generated.go new file mode 100644 index 00000000..ab844a2b --- /dev/null +++ b/cmd/generated/policy/subject-mappings/create_generated.go @@ -0,0 +1,82 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + AttributeValueId string `json:"attributeValueId"` // The ID of the attribute value to map to a subject condition set + Action string `json:"action"` // Each 'id' or 'name' of an Action to be entitled (i.e. 'create', 'read', 'update', 'delete') + SubjectConditionSetId string `json:"subjectConditionSetId"` // Known preexisting Subject Condition Set Id + SubjectConditionSetNew string `json:"subjectConditionSetNew"` // JSON array of Subject Sets to create a new Subject Condition Set associated with the created Subject Mapping + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ActionStandard string `json:"actionStandard"` // Deprecated. Migrated to '--action'. + ActionCustom string `json:"actionCustom"` // Deprecated. Migrated to '--action'. +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Aliases: []string{"new", "add", "c"}, + Short: "Create a new subject mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("attribute-value-id", "a", "", "The ID of the attribute value to map to a subject condition set") + cmd.MarkFlagRequired("attribute-value-id") + cmd.Flags().String("action", "", "Each 'id' or 'name' of an Action to be entitled (i.e. 'create', 'read', 'update', 'delete')") + cmd.Flags().String("subject-condition-set-id", "", "Known preexisting Subject Condition Set Id") + cmd.Flags().String("subject-condition-set-new", "", "JSON array of Subject Sets to create a new Subject Condition Set associated with the created Subject Mapping") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().StringP("action-standard", "s", "", "Deprecated. Migrated to '--action'.") + cmd.Flags().StringP("action-custom", "c", "", "Deprecated. Migrated to '--action'.") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + attributeValueId, _ := cmd.Flags().GetString("attribute-value-id") + action, _ := cmd.Flags().GetString("action") + subjectConditionSetId, _ := cmd.Flags().GetString("subject-condition-set-id") + subjectConditionSetNew, _ := cmd.Flags().GetString("subject-condition-set-new") + label, _ := cmd.Flags().GetString("label") + actionStandard, _ := cmd.Flags().GetString("action-standard") + actionCustom, _ := cmd.Flags().GetString("action-custom") + + // Create request + req := &CreateRequest{ + Flags: CreateRequestFlags{ + AttributeValueId: attributeValueId, + Action: action, + SubjectConditionSetId: subjectConditionSetId, + SubjectConditionSetNew: subjectConditionSetNew, + Label: label, + ActionStandard: actionStandard, + ActionCustom: actionCustom, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/delete_generated.go b/cmd/generated/policy/subject-mappings/delete_generated.go new file mode 100644 index 00000000..6470b818 --- /dev/null +++ b/cmd/generated/policy/subject-mappings/delete_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestFlags represents the flags for the delete command +type DeleteRequestFlags struct { + Id string `json:"id"` // The ID of the subject mapping to delete + Force string `json:"force"` // Force deletion without interactive confirmation (dangerous) +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Flags DeleteRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a subject mapping by id", + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject mapping to delete") + cmd.MarkFlagRequired("id") + cmd.Flags().String("force", "", "Force deletion without interactive confirmation (dangerous)") + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + id, _ := cmd.Flags().GetString("id") + force, _ := cmd.Flags().GetString("force") + + // Create request + req := &DeleteRequest{ + Flags: DeleteRequestFlags{ + Id: id, + Force: force, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/get_generated.go b/cmd/generated/policy/subject-mappings/get_generated.go new file mode 100644 index 00000000..5a6ce14d --- /dev/null +++ b/cmd/generated/policy/subject-mappings/get_generated.go @@ -0,0 +1,58 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestFlags represents the flags for the get command +type GetRequestFlags struct { + Id string `json:"id"` // The ID of the subject mapping to get +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Flags GetRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Aliases: []string{"g"}, + Short: "Get a subject mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject mapping to get") + cmd.MarkFlagRequired("id") + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + id, _ := cmd.Flags().GetString("id") + + // Create request + req := &GetRequest{ + Flags: GetRequestFlags{ + Id: id, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/list_generated.go b/cmd/generated/policy/subject-mappings/list_generated.go new file mode 100644 index 00000000..84d86e33 --- /dev/null +++ b/cmd/generated/policy/subject-mappings/list_generated.go @@ -0,0 +1,61 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// ListRequestFlags represents the flags for the list command +type ListRequestFlags struct { + Limit string `json:"limit"` // Limit retrieved count + Offset string `json:"offset"` // Offset (page) quantity from start of the list +} + +// ListRequest represents the parameters for the list command +type ListRequest struct { + Flags ListRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Aliases: []string{"l"}, + Short: "List subject mappings", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("limit", "l", "", "Limit retrieved count") + cmd.Flags().StringP("offset", "o", "", "Offset (page) quantity from start of the list") + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + limit, _ := cmd.Flags().GetString("limit") + offset, _ := cmd.Flags().GetString("offset") + + // Create request + req := &ListRequest{ + Flags: ListRequestFlags{ + Limit: limit, + Offset: offset, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/match_generated.go b/cmd/generated/policy/subject-mappings/match_generated.go new file mode 100644 index 00000000..9897c5d5 --- /dev/null +++ b/cmd/generated/policy/subject-mappings/match_generated.go @@ -0,0 +1,60 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// MatchRequestFlags represents the flags for the match command +type MatchRequestFlags struct { + Subject string `json:"subject"` // A Subject Entity Representation string (JSON or JWT, auto-detected) + Selector string `json:"selector"` // Individual selectors (i.e. '.department' or '.realm_access.roles[]') that may be found in SubjectConditionSets +} + +// MatchRequest represents the parameters for the match command +type MatchRequest struct { + Flags MatchRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// MatchHandler defines the function type for handling match commands +type MatchHandler func(cmd *cobra.Command, req *MatchRequest) error + +// NewMatchCommand creates a new match command with the provided handler function +func NewMatchCommand(handler MatchHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "match", + Short: "Match a subject or set of selectors to relevant subject mappings", + RunE: func(cmd *cobra.Command, args []string) error { + return runMatch(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("subject", "s", "", "A Subject Entity Representation string (JSON or JWT, auto-detected)") + cmd.Flags().StringP("selector", "x", "", "Individual selectors (i.e. '.department' or '.realm_access.roles[]') that may be found in SubjectConditionSets") + + return cmd +} + +// runMatch handles argument and flag extraction +func runMatch(cmd *cobra.Command, args []string, handler MatchHandler) error { + subject, _ := cmd.Flags().GetString("subject") + selector, _ := cmd.Flags().GetString("selector") + + // Create request + req := &MatchRequest{ + Flags: MatchRequestFlags{ + Subject: subject, + Selector: selector, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/policy/subject-mappings/update_generated.go b/cmd/generated/policy/subject-mappings/update_generated.go new file mode 100644 index 00000000..07e901f2 --- /dev/null +++ b/cmd/generated/policy/subject-mappings/update_generated.go @@ -0,0 +1,82 @@ +// Code generated by adder. DO NOT EDIT. + +package policy_subject_mappings + +import ( + + "github.com/spf13/cobra" +) + +// UpdateRequestFlags represents the flags for the update command +type UpdateRequestFlags struct { + Id string `json:"id"` // The ID of the subject mapping to update + Action string `json:"action"` // Each 'id' or 'name' of an Action to be entitled (i.e. 'create', 'read', 'update', 'delete') + ActionStandard string `json:"actionStandard"` // Deprecated. Migrated to '--action'. + ActionCustom string `json:"actionCustom"` // Deprecated. Migrated to '--action'. + SubjectConditionSetId string `json:"subjectConditionSetId"` // Known preexisting Subject Condition Set Id + Label string `json:"label"` // Optional metadata 'labels' in the format: key=value + ForceReplaceLabels string `json:"forceReplaceLabels"` // Destructively replace entire set of existing metadata 'labels' with any provided to this command +} + +// UpdateRequest represents the parameters for the update command +type UpdateRequest struct { + Flags UpdateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// UpdateHandler defines the function type for handling update commands +type UpdateHandler func(cmd *cobra.Command, req *UpdateRequest) error + +// NewUpdateCommand creates a new update command with the provided handler function +func NewUpdateCommand(handler UpdateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Aliases: []string{"u"}, + Short: "Update a subject mapping", + RunE: func(cmd *cobra.Command, args []string) error { + return runUpdate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().StringP("id", "i", "", "The ID of the subject mapping to update") + cmd.MarkFlagRequired("id") + cmd.Flags().String("action", "", "Each 'id' or 'name' of an Action to be entitled (i.e. 'create', 'read', 'update', 'delete')") + cmd.Flags().StringP("action-standard", "s", "", "Deprecated. Migrated to '--action'.") + cmd.Flags().StringP("action-custom", "c", "", "Deprecated. Migrated to '--action'.") + cmd.Flags().String("subject-condition-set-id", "", "Known preexisting Subject Condition Set Id") + cmd.Flags().StringP("label", "l", "", "Optional metadata 'labels' in the format: key=value") + cmd.Flags().String("force-replace-labels", "%!s(bool=false)", "Destructively replace entire set of existing metadata 'labels' with any provided to this command") + + return cmd +} + +// runUpdate handles argument and flag extraction +func runUpdate(cmd *cobra.Command, args []string, handler UpdateHandler) error { + id, _ := cmd.Flags().GetString("id") + action, _ := cmd.Flags().GetString("action") + actionStandard, _ := cmd.Flags().GetString("action-standard") + actionCustom, _ := cmd.Flags().GetString("action-custom") + subjectConditionSetId, _ := cmd.Flags().GetString("subject-condition-set-id") + label, _ := cmd.Flags().GetString("label") + forceReplaceLabels, _ := cmd.Flags().GetString("force-replace-labels") + + // Create request + req := &UpdateRequest{ + Flags: UpdateRequestFlags{ + Id: id, + Action: action, + ActionStandard: actionStandard, + ActionCustom: actionCustom, + SubjectConditionSetId: subjectConditionSetId, + Label: label, + ForceReplaceLabels: forceReplaceLabels, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/create_generated.go b/cmd/generated/profile/create_generated.go new file mode 100644 index 00000000..8f8f6707 --- /dev/null +++ b/cmd/generated/profile/create_generated.go @@ -0,0 +1,74 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + +// CreateRequestArguments represents the arguments for the create command +type CreateRequestArguments struct { + Profile string `json:"profile" validate:"required"` // Name of the profile to create + Endpoint string `json:"endpoint" validate:"required"` // Platform endpoint URL +} +// CreateRequestFlags represents the flags for the create command +type CreateRequestFlags struct { + SetDefault bool `json:"setDefault"` // Set the profile as default + TlsNoVerify bool `json:"tlsNoVerify"` // Disable TLS verification +} + +// CreateRequest represents the parameters for the create command +type CreateRequest struct { + Arguments CreateRequestArguments `json:"arguments"` + Flags CreateRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// CreateHandler defines the function type for handling create commands +type CreateHandler func(cmd *cobra.Command, req *CreateRequest) error + +// NewCreateCommand creates a new create command with the provided handler function +func NewCreateCommand(handler CreateHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "create [profile] [endpoint]", + Aliases: []string{"add"}, + Short: "Create a new profile", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + return runCreate(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().Bool("set-default", false, "Set the profile as default") + cmd.Flags().Bool("tls-no-verify", false, "Disable TLS verification") + + return cmd +} + +// runCreate handles argument and flag extraction +func runCreate(cmd *cobra.Command, args []string, handler CreateHandler) error { + profile := args[0] + endpoint := args[1] + setDefault, _ := cmd.Flags().GetBool("set-default") + tlsNoVerify, _ := cmd.Flags().GetBool("tls-no-verify") + + // Create request + req := &CreateRequest{ + Arguments: CreateRequestArguments{ + Profile: profile, + Endpoint: endpoint, + }, + Flags: CreateRequestFlags{ + SetDefault: setDefault, + TlsNoVerify: tlsNoVerify, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/delete_generated.go b/cmd/generated/profile/delete_generated.go new file mode 100644 index 00000000..868a52b2 --- /dev/null +++ b/cmd/generated/profile/delete_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + +// DeleteRequestArguments represents the arguments for the delete command +type DeleteRequestArguments struct { + Profile string `json:"profile" validate:"required"` // Name of the profile to delete +} + +// DeleteRequest represents the parameters for the delete command +type DeleteRequest struct { + Arguments DeleteRequestArguments `json:"arguments"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// DeleteHandler defines the function type for handling delete commands +type DeleteHandler func(cmd *cobra.Command, req *DeleteRequest) error + +// NewDeleteCommand creates a new delete command with the provided handler function +func NewDeleteCommand(handler DeleteHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "delete [profile]", + Short: "Delete a profile", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return runDelete(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runDelete handles argument and flag extraction +func runDelete(cmd *cobra.Command, args []string, handler DeleteHandler) error { + profile := args[0] + + // Create request + req := &DeleteRequest{ + Arguments: DeleteRequestArguments{ + Profile: profile, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/get_generated.go b/cmd/generated/profile/get_generated.go new file mode 100644 index 00000000..c36d11c2 --- /dev/null +++ b/cmd/generated/profile/get_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + +// GetRequestArguments represents the arguments for the get command +type GetRequestArguments struct { + Profile string `json:"profile" validate:"required"` // Name of the profile to retrieve +} + +// GetRequest represents the parameters for the get command +type GetRequest struct { + Arguments GetRequestArguments `json:"arguments"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// GetHandler defines the function type for handling get commands +type GetHandler func(cmd *cobra.Command, req *GetRequest) error + +// NewGetCommand creates a new get command with the provided handler function +func NewGetCommand(handler GetHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "get [profile]", + Short: "Get a profile value", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return runGet(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runGet handles argument and flag extraction +func runGet(cmd *cobra.Command, args []string, handler GetHandler) error { + profile := args[0] + + // Create request + req := &GetRequest{ + Arguments: GetRequestArguments{ + Profile: profile, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/list_generated.go b/cmd/generated/profile/list_generated.go new file mode 100644 index 00000000..24b2f9c7 --- /dev/null +++ b/cmd/generated/profile/list_generated.go @@ -0,0 +1,46 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + + +// ListRequest represents the parameters for the list command +type ListRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ListHandler defines the function type for handling list commands +type ListHandler func(cmd *cobra.Command, req *ListRequest) error + +// NewListCommand creates a new list command with the provided handler function +func NewListCommand(handler ListHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "List profiles", + RunE: func(cmd *cobra.Command, args []string) error { + return runList(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runList handles argument and flag extraction +func runList(cmd *cobra.Command, args []string, handler ListHandler) error { + + // Create request + req := &ListRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/set-default_generated.go b/cmd/generated/profile/set-default_generated.go new file mode 100644 index 00000000..3f6223da --- /dev/null +++ b/cmd/generated/profile/set-default_generated.go @@ -0,0 +1,56 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + +// SetDefaultRequestArguments represents the arguments for the set-default command +type SetDefaultRequestArguments struct { + Profile string `json:"profile" validate:"required"` // Name of the profile to set as default +} + +// SetDefaultRequest represents the parameters for the set-default command +type SetDefaultRequest struct { + Arguments SetDefaultRequestArguments `json:"arguments"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SetDefaultHandler defines the function type for handling set-default commands +type SetDefaultHandler func(cmd *cobra.Command, req *SetDefaultRequest) error + +// NewSetDefaultCommand creates a new set-default command with the provided handler function +func NewSetDefaultCommand(handler SetDefaultHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "set-default [profile]", + Short: "Set a profile as default", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return runSetDefault(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runSetDefault handles argument and flag extraction +func runSetDefault(cmd *cobra.Command, args []string, handler SetDefaultHandler) error { + profile := args[0] + + // Create request + req := &SetDefaultRequest{ + Arguments: SetDefaultRequestArguments{ + Profile: profile, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile/set-endpoint_generated.go b/cmd/generated/profile/set-endpoint_generated.go new file mode 100644 index 00000000..717fb9f1 --- /dev/null +++ b/cmd/generated/profile/set-endpoint_generated.go @@ -0,0 +1,69 @@ +// Code generated by adder. DO NOT EDIT. + +package profile + +import ( + + "github.com/spf13/cobra" +) + +// SetEndpointRequestArguments represents the arguments for the set-endpoint command +type SetEndpointRequestArguments struct { + Profile string `json:"profile" validate:"required"` // Name of the profile to update + Endpoint string `json:"endpoint" validate:"required"` // New endpoint URL for the profile +} +// SetEndpointRequestFlags represents the flags for the set-endpoint command +type SetEndpointRequestFlags struct { + TlsNoVerify bool `json:"tlsNoVerify"` // Disable TLS verification +} + +// SetEndpointRequest represents the parameters for the set-endpoint command +type SetEndpointRequest struct { + Arguments SetEndpointRequestArguments `json:"arguments"` + Flags SetEndpointRequestFlags `json:"flags"` + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// SetEndpointHandler defines the function type for handling set-endpoint commands +type SetEndpointHandler func(cmd *cobra.Command, req *SetEndpointRequest) error + +// NewSetEndpointCommand creates a new set-endpoint command with the provided handler function +func NewSetEndpointCommand(handler SetEndpointHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "set-endpoint [profile] [endpoint]", + Short: "Set a profile value", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + return runSetEndpoint(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + cmd.Flags().Bool("tls-no-verify", false, "Disable TLS verification") + + return cmd +} + +// runSetEndpoint handles argument and flag extraction +func runSetEndpoint(cmd *cobra.Command, args []string, handler SetEndpointHandler) error { + profile := args[0] + endpoint := args[1] + tlsNoVerify, _ := cmd.Flags().GetBool("tls-no-verify") + + // Create request + req := &SetEndpointRequest{ + Arguments: SetEndpointRequestArguments{ + Profile: profile, + Endpoint: endpoint, + }, + Flags: SetEndpointRequestFlags{ + TlsNoVerify: tlsNoVerify, + }, + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/generated/profile_generated.go b/cmd/generated/profile_generated.go new file mode 100644 index 00000000..9b793126 --- /dev/null +++ b/cmd/generated/profile_generated.go @@ -0,0 +1,47 @@ +// Code generated by adder. DO NOT EDIT. + +package generated + +import ( + + "github.com/spf13/cobra" +) + + +// ProfileRequest represents the parameters for the profile command +type ProfileRequest struct { + RawArguments []string `json:"raw_arguments"` // Raw command line arguments passed to the command +} + +// ProfileHandler defines the function type for handling profile commands +type ProfileHandler func(cmd *cobra.Command, req *ProfileRequest) error + +// NewProfileCommand creates a new profile command with the provided handler function +func NewProfileCommand(handler ProfileHandler) *cobra.Command { + cmd := &cobra.Command{ + Use: "profile", + Aliases: []string{"profiles", "prof"}, + Short: "Manage profiles (experimental)", + RunE: func(cmd *cobra.Command, args []string) error { + return runProfile(cmd, args, handler) + }, + } + + // Register persistent flags + + // Register flags + + return cmd +} + +// runProfile handles argument and flag extraction +func runProfile(cmd *cobra.Command, args []string, handler ProfileHandler) error { + + // Create request + req := &ProfileRequest{ + RawArguments: args, + } + + // Call handler + return handler(cmd, req) +} diff --git a/cmd/profile.go b/cmd/profile.go index 7ce76c15..9a8e6290 100644 --- a/cmd/profile.go +++ b/cmd/profile.go @@ -4,6 +4,8 @@ import ( "errors" "runtime" + generated "github.com/opentdf/otdfctl/cmd/generated" + profilegen "github.com/opentdf/otdfctl/cmd/generated/profile" "github.com/opentdf/otdfctl/pkg/cli" "github.com/opentdf/otdfctl/pkg/config" "github.com/opentdf/otdfctl/pkg/profiles" @@ -15,173 +17,157 @@ var ( runningInTestMode = config.TestMode == "true" ) -var profileCmd = &cobra.Command{ - Use: "profile", - Aliases: []string{"profiles", "prof"}, - Short: "Manage profiles (experimental)", - Hidden: runningInLinux && !runningInTestMode, +func init() { + // Create commands using generated constructors with handler functions + profileCmd := generated.NewProfileCommand(handleProfile) + createCmd := profilegen.NewCreateCommand(handleProfileCreate) + listCmd := profilegen.NewListCommand(handleProfileList) + getCmd := profilegen.NewGetCommand(handleProfileGet) + deleteCmd := profilegen.NewDeleteCommand(handleProfileDelete) + setDefaultCmd := profilegen.NewSetDefaultCommand(handleProfileSetDefault) + setEndpointCmd := profilegen.NewSetEndpointCommand(handleProfileSetEndpoint) + + // Set Linux/test mode visibility + profileCmd.Hidden = runningInLinux && !runningInTestMode + + // Add subcommands + profileCmd.AddCommand(createCmd) + profileCmd.AddCommand(listCmd) + profileCmd.AddCommand(getCmd) + profileCmd.AddCommand(deleteCmd) + profileCmd.AddCommand(setDefaultCmd) + profileCmd.AddCommand(setEndpointCmd) + + // Add to root command + RootCmd.AddCommand(profileCmd) } -var profileCreateCmd = &cobra.Command{ - Use: "create ", - Aliases: []string{"add"}, - Short: "Create a new profile", - //nolint:mnd // two args - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, true) - - profileName := args[0] - endpoint := args[1] - - setDefault := c.FlagHelper.GetOptionalBool("set-default") - tlsNoVerify := c.FlagHelper.GetOptionalBool("tls-no-verify") - - c.Printf("Creating profile %s... ", profileName) - if err := profile.AddProfile(profileName, endpoint, tlsNoVerify, setDefault); err != nil { - c.Println("failed") - c.ExitWithError("Failed to create profile", err) - } - c.Println("ok") - - // suggest the user to set up authentication - }, +// handleProfile implements the parent profile command (if called without subcommands) +func handleProfile(cmd *cobra.Command, req *generated.ProfileRequest) error { + return cmd.Help() } -var profileListCmd = &cobra.Command{ - Use: "list", - Short: "List profiles", - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, false) - - for _, p := range profile.GetGlobalConfig().ListProfiles() { - if p == profile.GetGlobalConfig().GetDefaultProfile() { - c.Printf("* %s\n", p) - continue - } - c.Printf(" %s\n", p) - } - }, -} +// handleProfileCreate implements the business logic for the create command +func handleProfileCreate(cmd *cobra.Command, req *profilegen.CreateRequest) error { + c := cli.New(cmd, []string{req.Arguments.Profile, req.Arguments.Endpoint}) + InitProfile(c, true) -var profileGetCmd = &cobra.Command{ - Use: "get ", - Short: "Get a profile value", - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, false) - - profileName := args[0] - p, err := profile.GetProfile(profileName) - if err != nil { - c.ExitWithError("Failed to load profile", err) - } + profileName := req.Arguments.Profile + endpoint := req.Arguments.Endpoint - isDefault := "false" - if p.GetProfileName() == profile.GetGlobalConfig().GetDefaultProfile() { - isDefault = "true" - } + c.Printf("Creating profile %s... ", profileName) + if err := profile.AddProfile(profileName, endpoint, req.Flags.TlsNoVerify, req.Flags.SetDefault); err != nil { + c.Println("failed") + c.ExitWithError("Failed to create profile", err) + } + c.Println("ok") - var auth string - ac := p.GetAuthCredentials() - if ac.AuthType == profiles.PROFILE_AUTH_TYPE_CLIENT_CREDENTIALS { - maskedSecret := "********" - auth = "client-credentials (" + ac.ClientId + ", " + maskedSecret + ")" - } + return nil +} - t := cli.NewTabular( - []string{"Profile", p.GetProfileName()}, - []string{"Endpoint", p.GetEndpoint()}, - []string{"Is default", isDefault}, - []string{"Auth type", auth}, - ) +// handleProfileList implements the business logic for the list command +func handleProfileList(cmd *cobra.Command, req *profilegen.ListRequest) error { + c := cli.New(cmd, []string{}) + InitProfile(c, false) - c.Print(t.View()) - }, + for _, p := range profile.GetGlobalConfig().ListProfiles() { + if p == profile.GetGlobalConfig().GetDefaultProfile() { + c.Printf("* %s\n", p) + continue + } + c.Printf(" %s\n", p) + } + + return nil } -var profileDeleteCmd = &cobra.Command{ - Use: "delete ", - Short: "Delete a profile", - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, false) +// handleProfileGet implements the business logic for the get command +func handleProfileGet(cmd *cobra.Command, req *profilegen.GetRequest) error { + c := cli.New(cmd, []string{req.Arguments.Profile}) + InitProfile(c, false) + + profileName := req.Arguments.Profile + p, err := profile.GetProfile(profileName) + if err != nil { + c.ExitWithError("Failed to load profile", err) + } + + isDefault := "false" + if p.GetProfileName() == profile.GetGlobalConfig().GetDefaultProfile() { + isDefault = "true" + } + + var auth string + ac := p.GetAuthCredentials() + if ac.AuthType == profiles.PROFILE_AUTH_TYPE_CLIENT_CREDENTIALS { + maskedSecret := "********" + auth = "client-credentials (" + ac.ClientId + ", " + maskedSecret + ")" + } + + t := cli.NewTabular( + []string{"Profile", p.GetProfileName()}, + []string{"Endpoint", p.GetEndpoint()}, + []string{"Is default", isDefault}, + []string{"Auth type", auth}, + ) + + c.Print(t.View()) + return nil +} - profileName := args[0] +// handleProfileDelete implements the business logic for the delete command +func handleProfileDelete(cmd *cobra.Command, req *profilegen.DeleteRequest) error { + c := cli.New(cmd, []string{req.Arguments.Profile}) + InitProfile(c, false) - // TODO: suggest delete-all command to delete all profiles including default + profileName := req.Arguments.Profile - c.Printf("Deleting profile %s... ", profileName) - if err := profile.DeleteProfile(profileName); err != nil { - if errors.Is(err, profiles.ErrDeletingDefaultProfile) { - c.ExitWithWarning("Profile is set as default. Please set another profile as default before deleting.") - } - c.ExitWithError("Failed to delete profile", err) + c.Printf("Deleting profile %s... ", profileName) + if err := profile.DeleteProfile(profileName); err != nil { + if errors.Is(err, profiles.ErrDeletingDefaultProfile) { + c.ExitWithWarning("Profile is set as default. Please set another profile as default before deleting.") } - c.Println("ok") - }, + c.ExitWithError("Failed to delete profile", err) + } + c.Println("ok") + + return nil } -// TODO add delete-all command +// handleProfileSetDefault implements the business logic for the set-default command +func handleProfileSetDefault(cmd *cobra.Command, req *profilegen.SetDefaultRequest) error { + c := cli.New(cmd, []string{req.Arguments.Profile}) + InitProfile(c, false) -var profileSetDefaultCmd = &cobra.Command{ - Use: "set-default ", - Short: "Set a profile as default", - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, false) + profileName := req.Arguments.Profile - profileName := args[0] + c.Printf("Setting profile %s as default... ", profileName) + if err := profile.SetDefaultProfile(profileName); err != nil { + c.ExitWithError("Failed to set default profile", err) + } + c.Println("ok") - c.Printf("Setting profile %s as default... ", profileName) - if err := profile.SetDefaultProfile(profileName); err != nil { - c.ExitWithError("Failed to set default profile", err) - } - c.Println("ok") - }, + return nil } -var profileSetEndpointCmd = &cobra.Command{ - Use: "set-endpoint ", - Short: "Set a profile value", - //nolint:mnd // two args - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - InitProfile(c, false) - - profileName := args[0] - endpoint := args[1] - - p, err := profile.GetProfile(profileName) - if err != nil { - cli.ExitWithError("Failed to load profile", err) - } - - c.Printf("Setting endpoint for profile %s... ", profileName) - if err := p.SetEndpoint(endpoint); err != nil { - c.ExitWithError("Failed to set endpoint", err) - } - c.Println("ok") - }, -} +// handleProfileSetEndpoint implements the business logic for the set-endpoint command +func handleProfileSetEndpoint(cmd *cobra.Command, req *profilegen.SetEndpointRequest) error { + c := cli.New(cmd, []string{req.Arguments.Profile, req.Arguments.Endpoint}) + InitProfile(c, false) -func init() { - profileCreateCmd.Flags().Bool("set-default", false, "Set the profile as default") - profileCreateCmd.Flags().Bool("tls-no-verify", false, "Disable TLS verification") + profileName := req.Arguments.Profile + endpoint := req.Arguments.Endpoint - profileSetEndpointCmd.Flags().Bool("tls-no-verify", false, "Disable TLS verification") + p, err := profile.GetProfile(profileName) + if err != nil { + cli.ExitWithError("Failed to load profile", err) + } - RootCmd.AddCommand(profileCmd) + c.Printf("Setting endpoint for profile %s... ", profileName) + if err := p.SetEndpoint(endpoint); err != nil { + c.ExitWithError("Failed to set endpoint", err) + } + c.Println("ok") - profileCmd.AddCommand(profileCreateCmd) - profileCmd.AddCommand(profileListCmd) - profileCmd.AddCommand(profileGetCmd) - profileCmd.AddCommand(profileDeleteCmd) - profileCmd.AddCommand(profileSetDefaultCmd) - profileCmd.AddCommand(profileSetEndpointCmd) + return nil } diff --git a/cmd/root.go b/cmd/root.go index dd3586dc..f74b2c5f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,11 +4,11 @@ import ( "errors" "fmt" + "github.com/opentdf/otdfctl/cmd/generated" "github.com/opentdf/otdfctl/pkg/auth" "github.com/opentdf/otdfctl/pkg/cli" "github.com/opentdf/otdfctl/pkg/config" "github.com/opentdf/otdfctl/pkg/handlers" - "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/otdfctl/pkg/profiles" "github.com/opentdf/platform/sdk" "github.com/spf13/cobra" @@ -23,7 +23,7 @@ var ( profile *profiles.Profile - RootCmd = &man.Docs.GetDoc("").Command + RootCmd = generated.NewOtdfctlCommand(rootCmdHandler) ) type version struct { @@ -35,6 +35,31 @@ type version struct { SchemaVersion string `json:"schema_version"` } +// rootCmdHandler implements the root command handler using the generated structure +func rootCmdHandler(cmd *cobra.Command, req *generated.OtdfctlRequest) error { + // Create CLI wrapper using raw arguments for compatibility + c := cli.New(cmd, req.RawArguments) + + // Handle version flag + if req.Flags.Version { + v := version{ + AppName: config.AppName, + Version: config.Version, + CommitSha: config.CommitSha, + BuildTime: config.BuildTime, + SDKVersion: sdk.Version, + SchemaVersion: sdk.TDFSpecVersion, + } + + c.Println(fmt.Sprintf("%s version %s (%s) %s", config.AppName, config.Version, config.BuildTime, config.CommitSha)) + c.ExitWithJSON(v) + return nil + } + + // If no version flag, show help + return cmd.Help() +} + // InitProfile initializes the profile store and loads the profile specified in the flags // if onlyNew is set to true, a new profile will be created and returned // returns the profile and the current profile store @@ -207,85 +232,7 @@ func NewHandler(c *cli.Cli) handlers.Handler { } func init() { - rootCmd := man.Docs.GetCommand("", man.WithRun(func(cmd *cobra.Command, args []string) { - c := cli.New(cmd, args) - - if c.Flags.GetOptionalBool("version") { - v := version{ - AppName: config.AppName, - Version: config.Version, - CommitSha: config.CommitSha, - BuildTime: config.BuildTime, - SDKVersion: sdk.Version, - SchemaVersion: sdk.TDFSpecVersion, - } - - c.Println(fmt.Sprintf("%s version %s (%s) %s", config.AppName, config.Version, config.BuildTime, config.CommitSha)) - c.ExitWithJSON(v) - return - } - - //nolint:errcheck // error does not need to be checked - cmd.Help() - })) - - RootCmd = &rootCmd.Command - - RootCmd.Flags().Bool( - rootCmd.GetDocFlag("version").Name, - rootCmd.GetDocFlag("version").DefaultAsBool(), - rootCmd.GetDocFlag("version").Description, - ) - - RootCmd.PersistentFlags().Bool( - rootCmd.GetDocFlag("debug").Name, - rootCmd.GetDocFlag("debug").DefaultAsBool(), - rootCmd.GetDocFlag("debug").Description, - ) - - RootCmd.PersistentFlags().Bool( - rootCmd.GetDocFlag("json").Name, - rootCmd.GetDocFlag("json").DefaultAsBool(), - rootCmd.GetDocFlag("json").Description, - ) - - RootCmd.PersistentFlags().String( - rootCmd.GetDocFlag("profile").Name, - rootCmd.GetDocFlag("profile").Default, - rootCmd.GetDocFlag("profile").Description, - ) - - RootCmd.PersistentFlags().String( - rootCmd.GetDocFlag("host").Name, - rootCmd.GetDocFlag("host").Default, - rootCmd.GetDocFlag("host").Description, - ) - RootCmd.PersistentFlags().Bool( - rootCmd.GetDocFlag("tls-no-verify").Name, - rootCmd.GetDocFlag("tls-no-verify").DefaultAsBool(), - rootCmd.GetDocFlag("tls-no-verify").Description, - ) - RootCmd.PersistentFlags().String( - rootCmd.GetDocFlag("log-level").Name, - rootCmd.GetDocFlag("log-level").Default, - rootCmd.GetDocFlag("log-level").Description, - ) - RootCmd.PersistentFlags().StringVar( - &clientCredsFile, - rootCmd.GetDocFlag("with-client-creds-file").Name, - rootCmd.GetDocFlag("with-client-creds-file").Default, - rootCmd.GetDocFlag("with-client-creds-file").Description, - ) - RootCmd.PersistentFlags().StringVar( - &clientCredsJSON, - rootCmd.GetDocFlag("with-client-creds").Name, - rootCmd.GetDocFlag("with-client-creds").Default, - rootCmd.GetDocFlag("with-client-creds").Description, - ) - RootCmd.PersistentFlags().String( - rootCmd.GetDocFlag("with-access-token").Name, - rootCmd.GetDocFlag("with-access-token").Default, - rootCmd.GetDocFlag("with-access-token").Description, - ) + // All flags are now handled by the generated command + // Just add any additional setup that's needed RootCmd.AddGroup(&cobra.Group{ID: TDF}) } diff --git a/cmd/tdf-decrypt.go b/cmd/tdf-decrypt.go index 6bed38fc..58890fc8 100644 --- a/cmd/tdf-decrypt.go +++ b/cmd/tdf-decrypt.go @@ -5,8 +5,8 @@ import ( "fmt" "os" + decryptgenerated "github.com/opentdf/otdfctl/cmd/generated/decrypt" "github.com/opentdf/otdfctl/pkg/cli" - "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/otdfctl/pkg/utils" "github.com/opentdf/platform/lib/ocrypto" "github.com/spf13/cobra" @@ -19,14 +19,27 @@ var kasAllowList []string const TDF_MAX_FILE_SIZE = int64(10 * 1024 * 1024 * 1024) // 10 GB -func dev_tdfDecryptCmd(cmd *cobra.Command, args []string) { +// handleTdfDecrypt implements the business logic for the decrypt command +func handleTdfDecrypt(cmd *cobra.Command, req *decryptgenerated.DecryptRequest) error { + // Get file arguments from request + args := req.RawArguments + c := cli.New(cmd, args, cli.WithPrintJson()) h := NewHandler(c) defer h.Close() - output := c.Flags.GetOptionalString("out") - disableAssertionVerification := c.Flags.GetOptionalBool("no-verify-assertions") - sessionKeyAlgStr := c.Flags.GetOptionalString("session-key-algorithm") + // Extract flags from the generated request structure + output := req.Flags.Out + disableAssertionVerification := req.Flags.NoVerifyAssertions != "" // Convert string to bool + sessionKeyAlgStr := req.Flags.SessionKeyAlgorithm + withAssertionVerificationKeys := req.Flags.WithAssertionVerificationKeys + kasAllowlistStr := req.Flags.KasAllowlist + + // Set global variables for compatibility with existing logic + assertionVerification = withAssertionVerificationKeys + if kasAllowlistStr != "" { + kasAllowList = []string{kasAllowlistStr} // Convert single string to slice + } var sessionKeyAlgorithm ocrypto.KeyType switch sessionKeyAlgStr { case string(ocrypto.RSA2048Key): @@ -77,7 +90,7 @@ func dev_tdfDecryptCmd(cmd *cobra.Command, args []string) { if output == "" { //nolint:forbidigo // printing decrypted content to stdout fmt.Print(decrypted.String()) - return + return nil } // Here 'output' is the filename given with -o f, err := os.Create(output) @@ -89,51 +102,15 @@ func dev_tdfDecryptCmd(cmd *cobra.Command, args []string) { if err != nil { cli.ExitWithError("Failed to write decrypted data to file", err) } + + return nil } func init() { - decryptCmd := man.Docs.GetCommand("decrypt", - man.WithRun(dev_tdfDecryptCmd), - ) - decryptCmd.Flags().StringP( - decryptCmd.GetDocFlag("out").Name, - decryptCmd.GetDocFlag("out").Shorthand, - decryptCmd.GetDocFlag("out").Default, - decryptCmd.GetDocFlag("out").Description, - ) - // deprecated flag - decryptCmd.Flags().StringP( - decryptCmd.GetDocFlag("tdf-type").Name, - decryptCmd.GetDocFlag("tdf-type").Shorthand, - decryptCmd.GetDocFlag("tdf-type").Default, - decryptCmd.GetDocFlag("tdf-type").Description, - ) - decryptCmd.Flags().StringVarP( - &assertionVerification, - decryptCmd.GetDocFlag("with-assertion-verification-keys").Name, - decryptCmd.GetDocFlag("with-assertion-verification-keys").Shorthand, - "", - decryptCmd.GetDocFlag("with-assertion-verification-keys").Description, - ) - decryptCmd.Flags().String( - decryptCmd.GetDocFlag("session-key-algorithm").Name, - decryptCmd.GetDocFlag("session-key-algorithm").Default, - decryptCmd.GetDocFlag("session-key-algorithm").Description, - ) - decryptCmd.Flags().Bool( - decryptCmd.GetDocFlag("no-verify-assertions").Name, - decryptCmd.GetDocFlag("no-verify-assertions").DefaultAsBool(), - decryptCmd.GetDocFlag("no-verify-assertions").Description, - ) - decryptCmd.Flags().StringSliceVarP( - &kasAllowList, - decryptCmd.GetDocFlag("kas-allowlist").Name, - decryptCmd.GetDocFlag("kas-allowlist").Shorthand, - nil, - decryptCmd.GetDocFlag("kas-allowlist").Description, - ) - - decryptCmd.Command.GroupID = TDF + // Create command using generated constructor with handler function + decryptCmd := decryptgenerated.NewDecryptCommand(handleTdfDecrypt) + decryptCmd.GroupID = TDF - RootCmd.AddCommand(&decryptCmd.Command) + // Add to root command + RootCmd.AddCommand(decryptCmd) } diff --git a/cmd/tdf-encrypt.go b/cmd/tdf-encrypt.go index 9186ab5c..414ba75c 100644 --- a/cmd/tdf-encrypt.go +++ b/cmd/tdf-encrypt.go @@ -9,8 +9,8 @@ import ( "strings" "github.com/gabriel-vasile/mimetype" + encryptgenerated "github.com/opentdf/otdfctl/cmd/generated/encrypt" "github.com/opentdf/otdfctl/pkg/cli" - "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/otdfctl/pkg/utils" "github.com/opentdf/platform/lib/ocrypto" "github.com/spf13/cobra" @@ -28,7 +28,11 @@ var assertions string const INPUT_MAX_FILE_SIZE = int64(10 * 1024 * 1024 * 1024) // 10 GB -func dev_tdfEncryptCmd(cmd *cobra.Command, args []string) { +// handleTdfEncrypt implements the business logic for the encrypt command +func handleTdfEncrypt(cmd *cobra.Command, req *encryptgenerated.EncryptRequest) error { + // Get file arguments from request + args := req.RawArguments + c := cli.New(cmd, args, cli.WithPrintJson()) h := NewHandler(c) defer h.Close() @@ -40,13 +44,26 @@ func dev_tdfEncryptCmd(cmd *cobra.Command, args []string) { fileExt = strings.ToLower(strings.TrimPrefix(filepath.Ext(filePath), ".")) } - out := c.Flags.GetOptionalString("out") - fileMimeType := c.Flags.GetOptionalString("mime-type") - attrValues = c.Flags.GetStringSlice("attr", attrValues, cli.FlagsStringSliceOptions{Min: 0}) - tdfType := c.Flags.GetOptionalString("tdf-type") - kasURLPath := c.Flags.GetOptionalString("kas-url-path") - wrappingKeyAlgStr := c.Flags.GetOptionalString("wrapping-key-algorithm") - targetMode := c.Flags.GetOptionalString("target-mode") + // Extract flags from the generated request structure + out := req.Flags.Out + fileMimeType := req.Flags.MimeType + attrValue := req.Flags.Attr + tdfType := req.Flags.TdfType + kasURLPath := req.Flags.KasUrlPath + wrappingKeyAlgStr := req.Flags.WrappingKeyAlgorithm + targetMode := req.Flags.TargetMode + ecdsaBinding := req.Flags.EcdsaBinding + withAssertions := req.Flags.WithAssertions + + // Convert single attr string to slice for compatibility with existing logic + if attrValue != "" { + attrValues = []string{attrValue} + } else { + attrValues = []string{} + } + + // Set assertions for compatibility + assertions = withAssertions var wrappingKeyAlgorithm ocrypto.KeyType switch wrappingKeyAlgStr { case string(ocrypto.RSA2048Key): @@ -117,7 +134,7 @@ func dev_tdfEncryptCmd(cmd *cobra.Command, args []string) { attrValues, fileMimeType, kasURLPath, - c.Flags.GetOptionalBool("ecdsa-binding"), + ecdsaBinding != "", // Convert string to bool (non-empty string means enabled) assertions, wrappingKeyAlgorithm, targetMode, @@ -147,64 +164,15 @@ func dev_tdfEncryptCmd(cmd *cobra.Command, args []string) { if e != nil { cli.ExitWithError("Failed to write encrypted data to stdout", e) } + + return nil } func init() { - encryptCmd := man.Docs.GetCommand("encrypt", - man.WithRun(dev_tdfEncryptCmd), - ) - encryptCmd.Flags().StringP( - encryptCmd.GetDocFlag("out").Name, - encryptCmd.GetDocFlag("out").Shorthand, - encryptCmd.GetDocFlag("out").Default, - encryptCmd.GetDocFlag("out").Description, - ) - encryptCmd.Flags().StringSliceVarP( - &attrValues, - encryptCmd.GetDocFlag("attr").Name, - encryptCmd.GetDocFlag("attr").Shorthand, - []string{}, - encryptCmd.GetDocFlag("attr").Description, - ) - encryptCmd.Flags().StringVarP( - &assertions, - encryptCmd.GetDocFlag("with-assertions").Name, - encryptCmd.GetDocFlag("with-assertions").Shorthand, - "", - encryptCmd.GetDocFlag("with-assertions").Description, - ) - encryptCmd.Flags().String( - encryptCmd.GetDocFlag("mime-type").Name, - encryptCmd.GetDocFlag("mime-type").Default, - encryptCmd.GetDocFlag("mime-type").Description, - ) - encryptCmd.Flags().String( - encryptCmd.GetDocFlag("tdf-type").Name, - encryptCmd.GetDocFlag("tdf-type").Default, - encryptCmd.GetDocFlag("tdf-type").Description, - ) - encryptCmd.Flags().StringP( - encryptCmd.GetDocFlag("wrapping-key-algorithm").Name, - encryptCmd.GetDocFlag("wrapping-key-algorithm").Shorthand, - encryptCmd.GetDocFlag("wrapping-key-algorithm").Default, - encryptCmd.GetDocFlag("wrapping-key-algorithm").Description, - ) - encryptCmd.Flags().Bool( - encryptCmd.GetDocFlag("ecdsa-binding").Name, - false, - encryptCmd.GetDocFlag("ecdsa-binding").Description, - ) - encryptCmd.Flags().String( - encryptCmd.GetDocFlag("kas-url-path").Name, - encryptCmd.GetDocFlag("kas-url-path").Default, - encryptCmd.GetDocFlag("kas-url-path").Description, - ) - encryptCmd.Flags().String( - encryptCmd.GetDocFlag("target-mode").Name, - encryptCmd.GetDocFlag("target-mode").Default, - encryptCmd.GetDocFlag("target-mode").Description, - ) - encryptCmd.Command.GroupID = TDF + // Create command using generated constructor with handler function + encryptCmd := encryptgenerated.NewEncryptCommand(handleTdfEncrypt) + encryptCmd.GroupID = TDF - RootCmd.AddCommand(&encryptCmd.Command) + // Add to root command + RootCmd.AddCommand(encryptCmd) } diff --git a/cmd/tdf-inspect.go b/cmd/tdf-inspect.go index 3f4e82ca..541de896 100644 --- a/cmd/tdf-inspect.go +++ b/cmd/tdf-inspect.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" + inspectgenerated "github.com/opentdf/otdfctl/cmd/generated/inspect" "github.com/opentdf/otdfctl/pkg/cli" "github.com/opentdf/otdfctl/pkg/handlers" - "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/platform/sdk" "github.com/spf13/cobra" ) @@ -40,7 +40,12 @@ type tdfInspectResult struct { Attributes []string `json:"attributes"` } -func tdf_InspectCmd(cmd *cobra.Command, args []string) { +// handleTdfInspect implements the business logic for the inspect command +func handleTdfInspect(cmd *cobra.Command, req *inspectgenerated.InspectRequest) error { + // The file argument is now properly extracted by the generated code + filePath := req.Arguments.File + args := []string{filePath} + c := cli.New(cmd, args, cli.WithPrintJson()) h := NewHandler(c) defer h.Close() @@ -109,18 +114,20 @@ func tdf_InspectCmd(cmd *cobra.Command, args []string) { } else { c.ExitWithError("failed to inspect TDF", nil) } + + return nil } func init() { - tdf_InspectCmd := man.Docs.GetCommand("inspect", - man.WithRun(tdf_InspectCmd), - ) - tdf_InspectCmd.Command.GroupID = TDF + // Create command using generated constructor with handler function + inspectCmd := inspectgenerated.NewInspectCommand(handleTdfInspect) + inspectCmd.GroupID = TDF - tdf_InspectCmd.Command.PreRun = func(cmd *cobra.Command, args []string) { - // Set the json flag to true since we only support json output + // Set the json flag to true since we only support json output + inspectCmd.PreRun = func(cmd *cobra.Command, args []string) { cmd.SetArgs(append(args, "--json")) } - RootCmd.AddCommand(&tdf_InspectCmd.Command) + // Add to root command + RootCmd.AddCommand(inspectCmd) } diff --git a/docs/man/_index.md b/docs/man/_index.md index 66cbb2cc..fca1ae6e 100644 --- a/docs/man/_index.md +++ b/docs/man/_index.md @@ -7,6 +7,8 @@ command: - name: version description: show version default: false + type: bool + persistent_flags: - name: profile description: profile to use for interacting with the platform default: @@ -16,6 +18,7 @@ command: - name: tls-no-verify description: disable verification of the server's TLS certificate default: false + type: bool - name: log-level description: log level enum: @@ -36,9 +39,11 @@ command: - name: json description: output in JSON format default: false + type: bool - name: debug description: enable debug output default: false + type: bool --- **Note**: Starting with version 1.67 of go-grpc, ALPN (Application-Layer Protocol Negotiation) is now enforced. diff --git a/docs/man/auth/clear-client-credentials.md b/docs/man/auth/clear-client-credentials.md index d24b0ae4..a40cbaad 100644 --- a/docs/man/auth/clear-client-credentials.md +++ b/docs/man/auth/clear-client-credentials.md @@ -7,6 +7,7 @@ command: - name: all description: Deprecated -- see the `profile` subcommand default: false + type: bool --- > [!WARNING] diff --git a/docs/man/inspect/_index.md b/docs/man/inspect/_index.md index 46a1ec73..d49fb2d4 100644 --- a/docs/man/inspect/_index.md +++ b/docs/man/inspect/_index.md @@ -1,8 +1,12 @@ --- title: Inspect a TDF file command: - name: inspect [file] - flags: + name: inspect + arguments: + - name: file + description: Path to the TDF file to inspect + required: true + type: string --- # Inspect a TDF file diff --git a/docs/man/policy/kas-registry/create.md b/docs/man/policy/kas-registry/create.md index 4a40452d..b5d0486b 100644 --- a/docs/man/policy/kas-registry/create.md +++ b/docs/man/policy/kas-registry/create.md @@ -17,7 +17,6 @@ command: - name: public-key-remote shorthand: r description: "(Deprecated: Use otdfctl policy kas-registry keys) Remote URI where the public key can be retrieved for the KAS" - - name: label - name: name shorthand: n description: Optional name of the registered KAS (must be unique within Policy) diff --git a/docs/man/profile.md b/docs/man/profile.md new file mode 100644 index 00000000..185946ed --- /dev/null +++ b/docs/man/profile.md @@ -0,0 +1,12 @@ +--- +title: Manage profiles (experimental) +command: + name: profile + aliases: + - profiles + - prof +--- + +Manage profiles for connecting to different OpenTDF Platform instances. + +Profiles store connection settings and authentication credentials for easy switching between environments. \ No newline at end of file diff --git a/docs/man/profile/create.md b/docs/man/profile/create.md new file mode 100644 index 00000000..81a19c6d --- /dev/null +++ b/docs/man/profile/create.md @@ -0,0 +1,29 @@ +--- +title: Create a new profile +command: + name: create + aliases: + - add + arguments: + - name: profile + description: Name of the profile to create + required: true + type: string + - name: endpoint + description: Platform endpoint URL + required: true + type: string + flags: + - name: set-default + description: Set the profile as default + default: false + type: bool + - name: tls-no-verify + description: Disable TLS verification + default: false + type: bool +--- + +Create a new profile with the specified name and endpoint. + +A profile stores connection settings for an OpenTDF Platform instance, including the endpoint URL and authentication credentials. \ No newline at end of file diff --git a/docs/man/profile/delete.md b/docs/man/profile/delete.md new file mode 100644 index 00000000..75fe5ec2 --- /dev/null +++ b/docs/man/profile/delete.md @@ -0,0 +1,14 @@ +--- +title: Delete a profile +command: + name: delete + arguments: + - name: profile + description: Name of the profile to delete + required: true + type: string +--- + +Delete a profile. + +The default profile cannot be deleted. Set another profile as default before deleting the current default profile. \ No newline at end of file diff --git a/docs/man/profile/get.md b/docs/man/profile/get.md new file mode 100644 index 00000000..d76d4953 --- /dev/null +++ b/docs/man/profile/get.md @@ -0,0 +1,14 @@ +--- +title: Get a profile value +command: + name: get + arguments: + - name: profile + description: Name of the profile to retrieve + required: true + type: string +--- + +Get detailed information about a specific profile. + +Shows the profile name, endpoint, default status, and authentication type (with credentials masked for security). \ No newline at end of file diff --git a/docs/man/profile/list.md b/docs/man/profile/list.md new file mode 100644 index 00000000..7244943a --- /dev/null +++ b/docs/man/profile/list.md @@ -0,0 +1,9 @@ +--- +title: List profiles +command: + name: list +--- + +List all configured profiles. + +The default profile is marked with an asterisk (*). \ No newline at end of file diff --git a/docs/man/profile/set-default.md b/docs/man/profile/set-default.md new file mode 100644 index 00000000..f2f6e2e5 --- /dev/null +++ b/docs/man/profile/set-default.md @@ -0,0 +1,14 @@ +--- +title: Set a profile as default +command: + name: set-default + arguments: + - name: profile + description: Name of the profile to set as default + required: true + type: string +--- + +Set the specified profile as the default profile. + +The default profile is used when no --profile flag is specified in commands. \ No newline at end of file diff --git a/docs/man/profile/set-endpoint.md b/docs/man/profile/set-endpoint.md new file mode 100644 index 00000000..01f887eb --- /dev/null +++ b/docs/man/profile/set-endpoint.md @@ -0,0 +1,23 @@ +--- +title: Set a profile value +command: + name: set-endpoint + arguments: + - name: profile + description: Name of the profile to update + required: true + type: string + - name: endpoint + description: New endpoint URL for the profile + required: true + type: string + flags: + - name: tls-no-verify + description: Disable TLS verification + default: false + type: bool +--- + +Update the endpoint URL for an existing profile. + +This allows changing the platform endpoint without recreating the profile and losing authentication credentials. \ No newline at end of file diff --git a/go.mod b/go.mod index 353be0db..2000bdaf 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( al.essio.dev/pkg/shellescape v1.5.1 // indirect buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250603165357-b52ab10f4468.1 // indirect connectrpc.com/connect v1.18.1 // indirect - github.com/BurntSushi/toml v0.3.1 // indirect + github.com/BurntSushi/toml v1.4.0 // indirect github.com/Masterminds/semver/v3 v3.3.1 // indirect github.com/alecthomas/chroma/v2 v2.14.0 // indirect github.com/atotto/clipboard v0.1.4 // indirect diff --git a/go.sum b/go.sum index 99ae8742..8f1fd5e6 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,9 @@ dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4= diff --git a/pkg/man/docflags.go b/pkg/man/docflags.go index 2f8664d1..7a51c4f1 100644 --- a/pkg/man/docflags.go +++ b/pkg/man/docflags.go @@ -14,6 +14,50 @@ type DocFlag struct { Enum []string `yaml:"enum"` } +type DocArgument struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + Required bool `yaml:"required"` + Type string `yaml:"type"` +} + +// FlexibleArgs can handle both []string and []DocArgument formats +type FlexibleArgs struct { + StringArgs []string + ObjectArgs []DocArgument +} + +func (f *FlexibleArgs) UnmarshalYAML(unmarshal func(interface{}) error) error { + // Try to unmarshal as []string first + var stringArgs []string + if err := unmarshal(&stringArgs); err == nil { + f.StringArgs = stringArgs + return nil + } + + // If that fails, try to unmarshal as []DocArgument + var objectArgs []DocArgument + if err := unmarshal(&objectArgs); err == nil { + f.ObjectArgs = objectArgs + return nil + } + + return fmt.Errorf("arguments must be either a list of strings or a list of argument objects") +} + +// ToStringSlice converts FlexibleArgs to a simple string slice for compatibility +func (f *FlexibleArgs) ToStringSlice() []string { + if len(f.StringArgs) > 0 { + return f.StringArgs + } + + result := make([]string, len(f.ObjectArgs)) + for i, arg := range f.ObjectArgs { + result[i] = arg.Name + } + return result +} + func (d *Doc) GetDocFlag(name string) DocFlag { for _, f := range d.DocFlags { if f.Name == name { diff --git a/pkg/man/man.go b/pkg/man/man.go index 5f63b1e6..77aacdce 100644 --- a/pkg/man/man.go +++ b/pkg/man/man.go @@ -204,12 +204,12 @@ func ProcessDoc(doc string) (*Doc, error) { var matter struct { Title string `yaml:"title"` Command struct { - Name string `yaml:"name"` - Args []string `yaml:"arguments"` - ArbitraryArgs []string `yaml:"arbitraryArgs"` - Hidden bool `yaml:"hidden"` - Aliases []string `yaml:"aliases"` - Flags []DocFlag `yaml:"flags"` + Name string `yaml:"name"` + Args FlexibleArgs `yaml:"arguments"` + ArbitraryArgs []string `yaml:"arbitraryArgs"` + Hidden bool `yaml:"hidden"` + Aliases []string `yaml:"aliases"` + Flags []DocFlag `yaml:"flags"` } `yaml:"command"` } rest, err := frontmatter.Parse(strings.NewReader(doc), &matter) @@ -226,8 +226,9 @@ func ProcessDoc(doc string) (*Doc, error) { long := "# " + matter.Title + "\n\n" + strings.TrimSpace(string(rest)) var args cobra.PositionalArgs - if len(c.Args) > 0 { - args = cobra.ExactArgs(len(c.Args)) + argSlice := c.Args.ToStringSlice() + if len(argSlice) > 0 { + args = cobra.ExactArgs(len(argSlice)) } if len(c.ArbitraryArgs) > 0 { args = cobra.ArbitraryArgs