From 7e8e8faf9de05e4d8c32799e1c771f2d09301a57 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 14:37:50 +0200 Subject: [PATCH 01/24] add kms key show --- cmd/kms/key/key.go | 15 +++++++++++ cmd/kms/key/key_show.go | 59 +++++++++++++++++++++++++++++++++++++++++ cmd/kms/kms.go | 15 +++++++++++ cmd/subcommands/init.go | 2 ++ 4 files changed, 91 insertions(+) create mode 100644 cmd/kms/key/key.go create mode 100644 cmd/kms/key/key_show.go create mode 100644 cmd/kms/kms.go diff --git a/cmd/kms/key/key.go b/cmd/kms/key/key.go new file mode 100644 index 000000000..d1f7969a6 --- /dev/null +++ b/cmd/kms/key/key.go @@ -0,0 +1,15 @@ +package key + +import ( + "github.com/exoscale/cli/cmd/kms" + "github.com/spf13/cobra" +) + +var keyCmd = &cobra.Command{ + Use: "key", + Short: "KMS key", +} + +func init() { + kms.KMSCmd.AddCommand(keyCmd) +} diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go new file mode 100644 index 000000000..c83741b1e --- /dev/null +++ b/cmd/kms/key/key_show.go @@ -0,0 +1,59 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type KeyShowOutput struct { + v3.GetKmsKeyResponse +} + +func (o *KeyShowOutput) Type() string { return "KMS key" } +func (o *KeyShowOutput) ToJSON() { output.JSON(o) } +func (o *KeyShowOutput) ToText() { output.Text(o) } +func (o *KeyShowOutput) ToTable() { output.Table(o) } + +type keyShowCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"show"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *keyShowCmd) CmdAliases() []string { return exocmd.GShowAlias } + +func (c *keyShowCmd) CmdShort() string { + return "Shows details of a KMS key." +} + +func (c *keyShowCmd) CmdLong() string { + return "Shows details of a KMS key." +} + +func (c *keyShowCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + resp, err := client.GetKmsKey(ctx, v3.UUID(c.Key)) + if err != nil { + return err + } + + out := KeyShowOutput{*resp} + return c.OutputFunc(&out, err) +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyShowCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/kms.go b/cmd/kms/kms.go new file mode 100644 index 000000000..67791de36 --- /dev/null +++ b/cmd/kms/kms.go @@ -0,0 +1,15 @@ +package kms + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/spf13/cobra" +) + +var KMSCmd = &cobra.Command{ + Use: "kms", + Short: "Key management", +} + +func init() { + exocmd.RootCmd.AddCommand(KMSCmd) +} diff --git a/cmd/subcommands/init.go b/cmd/subcommands/init.go index bdb53bdcd..a39305195 100644 --- a/cmd/subcommands/init.go +++ b/cmd/subcommands/init.go @@ -26,5 +26,7 @@ import ( _ "github.com/exoscale/cli/cmd/dbaas" _ "github.com/exoscale/cli/cmd/dns" _ "github.com/exoscale/cli/cmd/iam" + _ "github.com/exoscale/cli/cmd/kms" + _ "github.com/exoscale/cli/cmd/kms/key" _ "github.com/exoscale/cli/cmd/storage" ) From 209af2ceac3e9d91c062eb8b57806bd859aadddb Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 15:34:23 +0200 Subject: [PATCH 02/24] kms key create --- cmd/kms/key/key_create.go | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 cmd/kms/key/key_create.go diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go new file mode 100644 index 000000000..1060459b0 --- /dev/null +++ b/cmd/kms/key/key_create.go @@ -0,0 +1,58 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyCreateCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"create"` + + Name string `cli-arg:"#" cli-usage:"NAME"` + + Description string `cli-flag:"description" cli-usage:"key description" cli-short:"desc"` + Usage string `cli-flag:"usage" cli-usage:"symmetric encryption with encrypt-decrypt"` + Multizone bool `cli-flag:"multizone" cli-usage:"allow replication accross zones"` +} + +func (c *keyCreateCmd) CmdAliases() []string { return nil } + +func (c *keyCreateCmd) CmdShort() string { + return "Creates a new KMS key." +} + +func (c *keyCreateCmd) CmdLong() string { + return "Creates a new KMS key." +} + +func (c *keyCreateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyCreateCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + req := v3.CreateKmsKeyRequest{ + Name: c.Name, + Description: c.Description, + Usage: v3.CreateKmsKeyRequestUsage(c.Usage), + MultiZone: &c.Multizone, + } + + if _, err := client.CreateKmsKey(ctx, req); err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyCreateCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From c34983b6e62e850aec8ce5610b9d40c54d51dc3a Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 15:34:31 +0200 Subject: [PATCH 03/24] kms key disable --- cmd/kms/key/key_disable.go | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cmd/kms/key/key_disable.go diff --git a/cmd/kms/key/key_disable.go b/cmd/kms/key/key_disable.go new file mode 100644 index 000000000..5419e278b --- /dev/null +++ b/cmd/kms/key/key_disable.go @@ -0,0 +1,47 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyDisableCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"disable"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *keyDisableCmd) CmdAliases() []string { return nil } + +func (c *keyDisableCmd) CmdShort() string { + return "Enables a KMS key." +} + +func (c *keyDisableCmd) CmdLong() string { + return "Enables a KMS key." +} + +func (c *keyDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + if _, err := client.DisableKmsKey(ctx, v3.UUID(c.Key)); err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyDisableCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From 7c1ddd0b2138733913c72d3a0a4f20470619219e Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 15:34:38 +0200 Subject: [PATCH 04/24] kms key enable --- cmd/kms/key/key_enable.go | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cmd/kms/key/key_enable.go diff --git a/cmd/kms/key/key_enable.go b/cmd/kms/key/key_enable.go new file mode 100644 index 000000000..52b0585a3 --- /dev/null +++ b/cmd/kms/key/key_enable.go @@ -0,0 +1,47 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyEnableCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"enable"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *keyEnableCmd) CmdAliases() []string { return nil } + +func (c *keyEnableCmd) CmdShort() string { + return "Enables a KMS key." +} + +func (c *keyEnableCmd) CmdLong() string { + return "Enables a KMS key." +} + +func (c *keyEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + if _, err := client.EnableKmsKey(ctx, v3.UUID(c.Key)); err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyEnableCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From 77e97be7dcb4a13f0cbb73cf746e8d65dba8448f Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 15:34:47 +0200 Subject: [PATCH 05/24] kms key list --- cmd/kms/key/key_list.go | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cmd/kms/key/key_list.go diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go new file mode 100644 index 000000000..15f0018a7 --- /dev/null +++ b/cmd/kms/key/key_list.go @@ -0,0 +1,79 @@ +package key + +import ( + "os" + "strconv" + "strings" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyListOutput struct { + v3.ListKmsKeysResponse +} + +func (o *keyListOutput) ToJSON() { output.JSON(o) } +func (o *keyListOutput) ToText() { output.Text(o) } +func (o *keyListOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "ID", + "NAME", + "ORIGINZONE", + "STATUS", + "MULTIZONE", + "REPLICAS", + }) + + for _, key := range o.KmsKeys { + t.Append([]string{ + string(key.ID), + key.Name, + string(key.OriginZone), + string(key.Status), + strconv.FormatBool(*key.MultiZone), + strings.Join(key.Replicas, ", "), + }) + } +} + +type keyListCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"list"` +} + +func (c *keyListCmd) CmdAliases() []string { return exocmd.GListAlias } + +func (c *keyListCmd) CmdShort() string { + return "List KMS keys." +} + +func (c *keyListCmd) CmdLong() string { + return "List KMS keys." +} + +func (c *keyListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyListCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + keys, err := client.ListKmsKeys(ctx) + if err != nil { + return err + } + + out := keyListOutput{*keys} + + return c.OutputFunc(&out, nil) +} From 5d12ba2ac9dacf6517380f3d792da4c66605e647 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 15:39:41 +0200 Subject: [PATCH 06/24] kms key replicate --- cmd/kms/key/key_list.go | 6 +++++ cmd/kms/key/key_replicate.go | 52 ++++++++++++++++++++++++++++++++++++ cmd/kms/key/key_show.go | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 cmd/kms/key/key_replicate.go diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go index 15f0018a7..f8d72d114 100644 --- a/cmd/kms/key/key_list.go +++ b/cmd/kms/key/key_list.go @@ -77,3 +77,9 @@ func (c *keyListCmd) CmdRun(_ *cobra.Command, _ []string) error { return c.OutputFunc(&out, nil) } + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyListCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/key/key_replicate.go b/cmd/kms/key/key_replicate.go new file mode 100644 index 000000000..17da26b11 --- /dev/null +++ b/cmd/kms/key/key_replicate.go @@ -0,0 +1,52 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyReplicateCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"replicate"` + + Key string `cli-arg:"#" cli-usage:"ID"` + Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to replicate the key to"` +} + +func (c *keyReplicateCmd) CmdAliases() []string { return nil } + +func (c *keyReplicateCmd) CmdShort() string { + return "Replicate a KMS key to another zone." +} + +func (c *keyReplicateCmd) CmdLong() string { + return "Replicate a KMS key to another zone." +} + +func (c *keyReplicateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyReplicateCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + req := v3.ReplicateKmsKeyRequest{ + Zone: string(c.Zone), + } + + if _, err := client.ReplicateKmsKey(ctx, v3.UUID(c.Key), req); err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyReplicateCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go index c83741b1e..d29a5ba6c 100644 --- a/cmd/kms/key/key_show.go +++ b/cmd/kms/key/key_show.go @@ -49,7 +49,7 @@ func (c *keyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { } out := KeyShowOutput{*resp} - return c.OutputFunc(&out, err) + return c.OutputFunc(&out, nil) } func init() { From c4215e00ff56614c355c4bd04a00d795c7c60926 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 16:24:59 +0200 Subject: [PATCH 07/24] kms key encrypt --- cmd/kms/key/key_encrypt.go | 57 ++++++++++++++++++++++++++++++++++++ cmd/kms/key/key_replicate.go | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 cmd/kms/key/key_encrypt.go diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go new file mode 100644 index 000000000..ef3c72911 --- /dev/null +++ b/cmd/kms/key/key_encrypt.go @@ -0,0 +1,57 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyEncryptCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"encrypt"` + + Key string `cli-arg:"#" cli-usage:"ID"` + Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT_b64"` + + EncryptionContext string `cli-short:"ec" cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` +} + +func (c *keyEncryptCmd) CmdAliases() []string { return nil } + +func (c *keyEncryptCmd) CmdShort() string { + return "Encrypts data using a KMS key." +} + +func (c *keyEncryptCmd) CmdLong() string { + return "Encrypts data using a KMS key." +} + +func (c *keyEncryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + ec := []byte(c.EncryptionContext) + req := v3.EncryptRequest{ + Plaintext: []byte(c.Plaintext), + EncryptionContext: &ec, + } + + _, err := client.Encrypt(ctx, v3.UUID(c.Key), req) + if err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyEncryptCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/key/key_replicate.go b/cmd/kms/key/key_replicate.go index 17da26b11..3b9498c02 100644 --- a/cmd/kms/key/key_replicate.go +++ b/cmd/kms/key/key_replicate.go @@ -13,7 +13,7 @@ type keyReplicateCmd struct { _ bool `cli-cmd:"replicate"` Key string `cli-arg:"#" cli-usage:"ID"` - Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to replicate the key to"` + Zone v3.ZoneName `cli-arg:"#" cli-short:"z" cli-usage:"zone to replicate the key to"` } func (c *keyReplicateCmd) CmdAliases() []string { return nil } From 895d5bcc7cf424b5f7a22a373cdcfffe9b81242b Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 15 May 2026 16:25:09 +0200 Subject: [PATCH 08/24] kms key decrypt --- cmd/kms/key/key_decrypt.go | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cmd/kms/key/key_decrypt.go diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go new file mode 100644 index 000000000..7fb693763 --- /dev/null +++ b/cmd/kms/key/key_decrypt.go @@ -0,0 +1,57 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type KeyDecryptCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"decrypt"` + + Key string `cli-arg:"#" cli-usage:"ID"` + Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT_b64"` + + EncryptionContext string `cli-short:"ec" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` +} + +func (c *KeyDecryptCmd) CmdAliases() []string { return nil } + +func (c *KeyDecryptCmd) CmdShort() string { + return "Decrypts data using a KMS key." +} + +func (c *KeyDecryptCmd) CmdLong() string { + return "Decrypts data using a KMS key." +} + +func (c *KeyDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *KeyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + ec := []byte(c.EncryptionContext) + req := v3.DecryptRequest{ + Ciphertext: []byte(c.Ciphertext), + EncryptionContext: &ec, + } + + _, err := client.Decrypt(ctx, v3.UUID(c.Key), req) + if err != nil { + return err + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &KeyDecryptCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From b9668b5877ae396ec87db14000cdb8ec493ab98c Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 10:56:05 +0200 Subject: [PATCH 09/24] short command uses single char --- cmd/kms/key/key_create.go | 2 +- cmd/kms/key/key_decrypt.go | 2 +- cmd/kms/key/key_encrypt.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index 1060459b0..bce8e23c9 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -14,7 +14,7 @@ type keyCreateCmd struct { Name string `cli-arg:"#" cli-usage:"NAME"` - Description string `cli-flag:"description" cli-usage:"key description" cli-short:"desc"` + Description string `cli-flag:"description" cli-usage:"key description"` Usage string `cli-flag:"usage" cli-usage:"symmetric encryption with encrypt-decrypt"` Multizone bool `cli-flag:"multizone" cli-usage:"allow replication accross zones"` } diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go index 7fb693763..3280f1598 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/key/key_decrypt.go @@ -15,7 +15,7 @@ type KeyDecryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT_b64"` - EncryptionContext string `cli-short:"ec" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` + EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` } func (c *KeyDecryptCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index ef3c72911..57d551dd1 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -15,7 +15,7 @@ type keyEncryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT_b64"` - EncryptionContext string `cli-short:"ec" cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` + EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` } func (c *keyEncryptCmd) CmdAliases() []string { return nil } From 893077c42c936e96dbd3770d4b37cadada9fee4d Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 13:04:36 +0200 Subject: [PATCH 10/24] better formatting --- cmd/kms/key/formatting.go | 67 ++++++++++++++++++++++++++++++++++++ cmd/kms/key/key_create.go | 10 +++++- cmd/kms/key/key_decrypt.go | 39 +++++++++++++++++++-- cmd/kms/key/key_disable.go | 7 ++++ cmd/kms/key/key_enable.go | 7 ++++ cmd/kms/key/key_encrypt.go | 33 +++++++++++++++++- cmd/kms/key/key_replicate.go | 11 ++++-- cmd/kms/key/key_show.go | 30 ++++++++++++++-- 8 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 cmd/kms/key/formatting.go diff --git a/cmd/kms/key/formatting.go b/cmd/kms/key/formatting.go new file mode 100644 index 000000000..a84a54cf7 --- /dev/null +++ b/cmd/kms/key/formatting.go @@ -0,0 +1,67 @@ +package key + +import ( + "fmt" + "os" + "strings" + + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" + v3 "github.com/exoscale/egoscale/v3" +) + +type successResponseOutput v3.SuccessResponse + +func (o *successResponseOutput) ToJSON() { output.JSON(o) } +func (o *successResponseOutput) ToText() { output.Text(o) } +func (o *successResponseOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "STATUS", + }) + + t.Append([]string{ + fmt.Sprintf("%s", o.Status), + }) +} + +func boolPtrToString(b *bool) string { + if b != nil && *b { + return "true" + } + return "false" +} + +func formatKeyRotationConfig(s *v3.KeyRotationConfig) string { + if s == nil { + return "" + } + return fmt.Sprintf("auto: %s\ncount: %d\nnextAt: %s\nrotationPeriod: %d", + boolPtrToString(s.Automatic), + s.ManualCount, + s.NextAT, + s.RotationPeriod) +} + +func formatKeyMaterial(s *v3.KeyMaterial) string { + if s == nil { + return "-" + } + return fmt.Sprintf("auto: %s\ncreatedAt: %s\nversion: %d", + boolPtrToString(s.Automatic), + s.CreatedAT, + s.Version) +} + +func formatReplicaStatus(s []v3.ReplicaState) string { + if len(s) == 0 { + return "-" + } + var res []string + for _, r := range s { + res = append(res, r.Zone) + } + return strings.Join(res, ", ") +} diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index bce8e23c9..7f884fbe6 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -44,10 +44,18 @@ func (c *keyCreateCmd) CmdRun(_ *cobra.Command, _ []string) error { MultiZone: &c.Multizone, } - if _, err := client.CreateKmsKey(ctx, req); err != nil { + resp, err := client.CreateKmsKey(ctx, req) + if err != nil { return err } + if !globalstate.Quiet { + return (&keyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: resp.ID.String(), + }).CmdRun(nil, nil) + } + return nil } diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go index 3280f1598..fec81166b 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/key/key_decrypt.go @@ -1,12 +1,36 @@ package key import ( + "encoding/base64" + "os" + exocmd "github.com/exoscale/cli/cmd" "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" v3 "github.com/exoscale/egoscale/v3" "github.com/spf13/cobra" ) +type keyDecryptOutput struct { + Plaintext string `json:"plaintext"` +} + +func (o *keyDecryptOutput) ToJSON() { output.JSON(o) } +func (o *keyDecryptOutput) ToText() { output.Text(o) } +func (o *keyDecryptOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "PLAINTEXT", + }) + + t.Append([]string{ + o.Plaintext, + }) +} + type KeyDecryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` @@ -37,16 +61,27 @@ func (c *KeyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { client := globalstate.EgoscaleV3Client ec := []byte(c.EncryptionContext) + decoded, err := base64.StdEncoding.DecodeString(c.Ciphertext) + if err != nil { + return err + } req := v3.DecryptRequest{ - Ciphertext: []byte(c.Ciphertext), + Ciphertext: decoded, EncryptionContext: &ec, } - _, err := client.Decrypt(ctx, v3.UUID(c.Key), req) + resp, err := client.Decrypt(ctx, v3.UUID(c.Key), req) if err != nil { return err } + if !globalstate.Quiet { + out := keyDecryptOutput{ + Plaintext: base64.StdEncoding.EncodeToString(resp.Plaintext), + } + return c.OutputFunc(&out, nil) + } + return nil } diff --git a/cmd/kms/key/key_disable.go b/cmd/kms/key/key_disable.go index 5419e278b..7947b1952 100644 --- a/cmd/kms/key/key_disable.go +++ b/cmd/kms/key/key_disable.go @@ -37,6 +37,13 @@ func (c *keyDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { return err } + if !globalstate.Quiet { + return (&keyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + return nil } diff --git a/cmd/kms/key/key_enable.go b/cmd/kms/key/key_enable.go index 52b0585a3..478d288bd 100644 --- a/cmd/kms/key/key_enable.go +++ b/cmd/kms/key/key_enable.go @@ -37,6 +37,13 @@ func (c *keyEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { return err } + if !globalstate.Quiet { + return (&keyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + return nil } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index 57d551dd1..b2975dde7 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -1,12 +1,36 @@ package key import ( + "encoding/base64" + "os" + exocmd "github.com/exoscale/cli/cmd" "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" v3 "github.com/exoscale/egoscale/v3" "github.com/spf13/cobra" ) +type keyEncryptOutput struct { + Ciphertext string `json:"ciphertext"` +} + +func (o *keyEncryptOutput) ToJSON() { output.JSON(o) } +func (o *keyEncryptOutput) ToText() { output.Text(o) } +func (o *keyEncryptOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "CIPHERTEXT", + }) + + t.Append([]string{ + o.Ciphertext, + }) +} + type keyEncryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` @@ -42,11 +66,18 @@ func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { EncryptionContext: &ec, } - _, err := client.Encrypt(ctx, v3.UUID(c.Key), req) + resp, err := client.Encrypt(ctx, v3.UUID(c.Key), req) if err != nil { return err } + if !globalstate.Quiet { + out := keyEncryptOutput{ + Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), + } + c.OutputFunc(&out, nil) + } + return nil } diff --git a/cmd/kms/key/key_replicate.go b/cmd/kms/key/key_replicate.go index 3b9498c02..c23621eee 100644 --- a/cmd/kms/key/key_replicate.go +++ b/cmd/kms/key/key_replicate.go @@ -13,7 +13,7 @@ type keyReplicateCmd struct { _ bool `cli-cmd:"replicate"` Key string `cli-arg:"#" cli-usage:"ID"` - Zone v3.ZoneName `cli-arg:"#" cli-short:"z" cli-usage:"zone to replicate the key to"` + Zone v3.ZoneName `cli-arg:"#" cli-usage:"ZONE"` } func (c *keyReplicateCmd) CmdAliases() []string { return nil } @@ -38,10 +38,17 @@ func (c *keyReplicateCmd) CmdRun(_ *cobra.Command, _ []string) error { Zone: string(c.Zone), } - if _, err := client.ReplicateKmsKey(ctx, v3.UUID(c.Key), req); err != nil { + resp, err := client.ReplicateKmsKey(ctx, v3.UUID(c.Key), req) + if err != nil { return err } + if !globalstate.Quiet { + out := successResponseOutput{ + Status: resp.Status, + } + return c.OutputFunc(&out, nil) + } return nil } diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go index d29a5ba6c..163be5240 100644 --- a/cmd/kms/key/key_show.go +++ b/cmd/kms/key/key_show.go @@ -1,6 +1,8 @@ package key import ( + "time" + exocmd "github.com/exoscale/cli/cmd" "github.com/exoscale/cli/pkg/globalstate" "github.com/exoscale/cli/pkg/output" @@ -9,7 +11,18 @@ import ( ) type KeyShowOutput struct { - v3.GetKmsKeyResponse + ID v3.UUID `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` + CreatedAt time.Time `json:"created-at" validate:"required"` + Multizone bool `json:"multi-zone" validate:"required"` + OriginZone string `json:"origin-zone" validate:"required"` + Status v3.GetKmsKeyResponseStatus `json:"status" validate:"required"` + ReplicasStatus string `json:"replicas-status,omitempty"` + Material string `json:"material" validate:"required"` + Rotation string `json:"rotation" validate:"required"` + Usage string `json:"usage" validate:"required"` + Source v3.GetKmsKeyResponseSource `json:"source" validate:"required"` + Description string `json:"description" validate:"required"` } func (o *KeyShowOutput) Type() string { return "KMS key" } @@ -48,7 +61,20 @@ func (c *keyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { return err } - out := KeyShowOutput{*resp} + out := KeyShowOutput{ + ID: resp.ID, + Name: resp.Name, + CreatedAt: resp.CreatedAT, + Multizone: *resp.MultiZone, + OriginZone: resp.OriginZone, + Status: resp.Status, + ReplicasStatus: formatReplicaStatus(resp.ReplicasStatus), + Material: formatKeyMaterial(resp.Material), + Rotation: formatKeyRotationConfig(resp.Rotation), + Usage: string(resp.Usage), + Source: resp.Source, + Description: resp.Description, + } return c.OutputFunc(&out, nil) } From eb1f56a664a5e96293c22f5d8202d934d7ba3bb1 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 13:22:53 +0200 Subject: [PATCH 11/24] add generate dek command --- cmd/kms/key/key_generate_dek.go | 103 ++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 cmd/kms/key/key_generate_dek.go diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_dek.go new file mode 100644 index 000000000..537260fd1 --- /dev/null +++ b/cmd/kms/key/key_generate_dek.go @@ -0,0 +1,103 @@ +package key + +import ( + "encoding/base64" + "os" + "strconv" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyGenerateDEKOutput struct { + Plaintext string `json:"plaintext"` + Ciphertext string `json:"ciphertext"` +} + +func (o *keyGenerateDEKOutput) ToJSON() { output.JSON(o) } +func (o *keyGenerateDEKOutput) ToText() { output.Text(o) } +func (o *keyGenerateDEKOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "PLAINTEXT", + "CIPHERTEXT", + }) + + t.Append([]string{ + o.Plaintext, + o.Ciphertext, + }) +} + +type keyGenerateDEKCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"generate-dek"` + + Key string `cli-arg:"#" cli-usage:"ID"` + KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK ("AES_256")"` + BytesCount string `cli-flag:"bytes-count" cli-usage:"number of bytes for DEK"` + EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` +} + +func (c *keyGenerateDEKCmd) CmdAliases() []string { return nil } + +func (c *keyGenerateDEKCmd) CmdShort() string { + return "Generates a data encryption key (DEK) using a KMS key." +} + +func (c *keyGenerateDEKCmd) CmdLong() string { + return "Generates a data encryption key (DEK) using a KMS key." +} + +func (c *keyGenerateDEKCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyGenerateDEKCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + ec := []byte(c.EncryptionContext) + + var bytecount int + if c.BytesCount != "" { + n, err := strconv.Atoi(c.BytesCount) + if err != nil { + return err + } + bytecount = n + } + + req := v3.GenerateDataKeyRequest{ + KeySpec: c.KeySpec, + BytesCount: bytecount, + EncryptionContext: &ec, + } + + resp, err := client.GenerateDataKey(ctx, v3.UUID(c.Key), req) + if err != nil { + return err + } + + if !globalstate.Quiet { + out := keyGenerateDEKOutput{ + Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), + Plaintext: base64.StdEncoding.EncodeToString(resp.Plaintext), + } + return c.OutputFunc(&out, nil) + } + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyGenerateDEKCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From f47d4d3b46422b33d9074be95218a43959389d4b Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 14:39:57 +0200 Subject: [PATCH 12/24] add reencrypt --- cmd/kms/key/formatting.go | 2 +- cmd/kms/key/key_decrypt.go | 16 +++--- cmd/kms/key/key_encrypt.go | 2 +- cmd/kms/key/key_generate_dek.go | 2 +- cmd/kms/key/key_reencrypt.go | 91 +++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 cmd/kms/key/key_reencrypt.go diff --git a/cmd/kms/key/formatting.go b/cmd/kms/key/formatting.go index a84a54cf7..8beaa8ad4 100644 --- a/cmd/kms/key/formatting.go +++ b/cmd/kms/key/formatting.go @@ -23,7 +23,7 @@ func (o *successResponseOutput) ToTable() { }) t.Append([]string{ - fmt.Sprintf("%s", o.Status), + string(o.Status), }) } diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go index fec81166b..f630bc56c 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/key/key_decrypt.go @@ -31,32 +31,32 @@ func (o *keyDecryptOutput) ToTable() { }) } -type KeyDecryptCmd struct { +type keyDecryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"decrypt"` Key string `cli-arg:"#" cli-usage:"ID"` - Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT_b64"` + Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` } -func (c *KeyDecryptCmd) CmdAliases() []string { return nil } +func (c *keyDecryptCmd) CmdAliases() []string { return nil } -func (c *KeyDecryptCmd) CmdShort() string { +func (c *keyDecryptCmd) CmdShort() string { return "Decrypts data using a KMS key." } -func (c *KeyDecryptCmd) CmdLong() string { +func (c *keyDecryptCmd) CmdLong() string { return "Decrypts data using a KMS key." } -func (c *KeyDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *KeyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client := globalstate.EgoscaleV3Client @@ -86,7 +86,7 @@ func (c *KeyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &KeyDecryptCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyDecryptCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index b2975dde7..48320f03f 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -75,7 +75,7 @@ func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { out := keyEncryptOutput{ Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), } - c.OutputFunc(&out, nil) + return c.OutputFunc(&out, nil) } return nil diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_dek.go index 537260fd1..7ae9d3870 100644 --- a/cmd/kms/key/key_generate_dek.go +++ b/cmd/kms/key/key_generate_dek.go @@ -41,7 +41,7 @@ type keyGenerateDEKCmd struct { _ bool `cli-cmd:"generate-dek"` Key string `cli-arg:"#" cli-usage:"ID"` - KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK ("AES_256")"` + KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK (AES_256)"` BytesCount string `cli-flag:"bytes-count" cli-usage:"number of bytes for DEK"` EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` } diff --git a/cmd/kms/key/key_reencrypt.go b/cmd/kms/key/key_reencrypt.go new file mode 100644 index 000000000..3e13d693f --- /dev/null +++ b/cmd/kms/key/key_reencrypt.go @@ -0,0 +1,91 @@ +package key + +import ( + "encoding/base64" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyReencryptCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"reencrypt"` + + Key string `cli-arg:"#" cli-usage:"SRC_ID"` + DestinationKey string `cli-arg:"#" cli-usage:"DEST_ID"` + Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` + + SourceEncryptionContext string `cli-flag:"source-encryption-context" cli-usage:"encryption context to use for source ciphertext decryption"` + DestEncryptionContext string `cli-flag:"dest-encryption-context" cli-usage:"encryption context to use for destination ciphertext encryption"` +} + +func (c *keyReencryptCmd) CmdAliases() []string { return nil } + +func (c *keyReencryptCmd) CmdShort() string { + return "Re-encrypts data from a KMS key to another KMS key." +} + +func (c *keyReencryptCmd) CmdLong() string { + return "Re-encrypts data from a KMS key to another KMS key." +} + +func (c *keyReencryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + var sourceEC []byte + if c.SourceEncryptionContext != "" { + sourceEC = []byte(c.SourceEncryptionContext) + } + + decodedCipher, err := base64.StdEncoding.DecodeString(c.Ciphertext) + if err != nil { + return err + } + source := &v3.ReEncryptRequestSource{ + Ciphertext: decodedCipher, + EncryptionContext: &sourceEC, + Key: v3.UUID(c.Key), + } + + var destEC []byte + if c.DestEncryptionContext != "" { + destEC = []byte(c.DestEncryptionContext) + } + dest := &v3.ReEncryptRequestDestination{ + Key: v3.UUID(c.DestinationKey), + EncryptionContext: &destEC, + } + + req := v3.ReEncryptRequest{ + Source: source, + Destination: dest, + } + + resp, err := client.ReEncrypt(ctx, v3.UUID(c.Key), req) + if err != nil { + return err + } + + if !globalstate.Quiet { + out := keyEncryptOutput{ + Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), + } + return c.OutputFunc(&out, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyReencryptCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From ef01c89e0c80a6faca143f7188b47fe800e5199d Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 15:34:19 +0200 Subject: [PATCH 13/24] add delete --- cmd/kms/key/key_delete.go | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cmd/kms/key/key_delete.go diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_delete.go new file mode 100644 index 000000000..2957ba78f --- /dev/null +++ b/cmd/kms/key/key_delete.go @@ -0,0 +1,73 @@ +package key + +import ( + "fmt" + "strconv" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyDeleteCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"delete"` + + Key string `cli-arg:"#" cli-usage:"ID"` + + DelayDays string `cli-flag:"delay-days" cli-usage:"number of days before deletion (7-30, default 30)"` +} + +func (c *keyDeleteCmd) CmdAliases() []string { return nil } + +func (c *keyDeleteCmd) CmdShort() string { + return "Deletes a KMS key." +} + +func (c *keyDeleteCmd) CmdLong() string { + return "Deletes a KMS key." +} + +func (c *keyDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + var delayDays int + if c.DelayDays != "" { + n, err := strconv.Atoi(c.DelayDays) + if err != nil { + return fmt.Errorf("invalid delay days: %v", err) + } + delayDays = n + } + + req := v3.ScheduleKmsKeyDeletionRequest{ + DelayDays: delayDays, + } + + _, err := client.ScheduleKmsKeyDeletion(ctx, v3.UUID(c.Key), req) + if err != nil { + return err + } + + if !globalstate.Quiet { + return (&keyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyDeleteCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From 18c866de409d4b7bc40bfbaf667fd7389733f872 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 15:34:27 +0200 Subject: [PATCH 14/24] add cancel-delete --- cmd/kms/key/key_cancel_delete.go | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 cmd/kms/key/key_cancel_delete.go diff --git a/cmd/kms/key/key_cancel_delete.go b/cmd/kms/key/key_cancel_delete.go new file mode 100644 index 000000000..d7aae0fdc --- /dev/null +++ b/cmd/kms/key/key_cancel_delete.go @@ -0,0 +1,55 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyCancelDeleteCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"cancel-delete"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *keyCancelDeleteCmd) CmdAliases() []string { return nil } + +func (c *keyCancelDeleteCmd) CmdShort() string { + return "Cancels the scheduled deletion of a KMS key." +} + +func (c *keyCancelDeleteCmd) CmdLong() string { + return "Cancels the scheduled deletion of a KMS key." +} + +func (c *keyCancelDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyCancelDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + _, err := client.CancelKmsKeyDeletion(ctx, v3.UUID(c.Key)) + if err != nil { + return err + } + + if !globalstate.Quiet { + return (&keyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyCancelDeleteCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} From 445c005febe098298d75c597a3332445feaa5912 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 16:36:19 +0200 Subject: [PATCH 15/24] add rotation commands --- cmd/kms/key/formatting.go | 12 ++--- cmd/kms/key/key_cancel_delete.go | 2 +- cmd/kms/key/key_create.go | 2 +- cmd/kms/key/key_delete.go | 2 +- cmd/kms/key/key_disable.go | 2 +- cmd/kms/key/key_enable.go | 2 +- cmd/kms/key/key_rotate.go | 55 +++++++++++++++++++ cmd/kms/key/key_show.go | 14 ++--- cmd/kms/rotation/rotation.go | 15 ++++++ cmd/kms/rotation/rotation_disable.go | 55 +++++++++++++++++++ cmd/kms/rotation/rotation_enable.go | 70 ++++++++++++++++++++++++ cmd/kms/rotation/rotation_list.go | 79 ++++++++++++++++++++++++++++ cmd/subcommands/init.go | 1 + 13 files changed, 290 insertions(+), 21 deletions(-) create mode 100644 cmd/kms/key/key_rotate.go create mode 100644 cmd/kms/rotation/rotation.go create mode 100644 cmd/kms/rotation/rotation_disable.go create mode 100644 cmd/kms/rotation/rotation_enable.go create mode 100644 cmd/kms/rotation/rotation_list.go diff --git a/cmd/kms/key/formatting.go b/cmd/kms/key/formatting.go index 8beaa8ad4..348745867 100644 --- a/cmd/kms/key/formatting.go +++ b/cmd/kms/key/formatting.go @@ -3,6 +3,7 @@ package key import ( "fmt" "os" + "strconv" "strings" "github.com/exoscale/cli/pkg/output" @@ -27,19 +28,12 @@ func (o *successResponseOutput) ToTable() { }) } -func boolPtrToString(b *bool) string { - if b != nil && *b { - return "true" - } - return "false" -} - func formatKeyRotationConfig(s *v3.KeyRotationConfig) string { if s == nil { return "" } return fmt.Sprintf("auto: %s\ncount: %d\nnextAt: %s\nrotationPeriod: %d", - boolPtrToString(s.Automatic), + strconv.FormatBool(*s.Automatic), s.ManualCount, s.NextAT, s.RotationPeriod) @@ -50,7 +44,7 @@ func formatKeyMaterial(s *v3.KeyMaterial) string { return "-" } return fmt.Sprintf("auto: %s\ncreatedAt: %s\nversion: %d", - boolPtrToString(s.Automatic), + strconv.FormatBool(*s.Automatic), s.CreatedAT, s.Version) } diff --git a/cmd/kms/key/key_cancel_delete.go b/cmd/kms/key/key_cancel_delete.go index d7aae0fdc..b1bdd6e98 100644 --- a/cmd/kms/key/key_cancel_delete.go +++ b/cmd/kms/key/key_cancel_delete.go @@ -39,7 +39,7 @@ func (c *keyCancelDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&keyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index 7f884fbe6..e83213e10 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -50,7 +50,7 @@ func (c *keyCreateCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&keyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: resp.ID.String(), }).CmdRun(nil, nil) diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_delete.go index 2957ba78f..a960b4645 100644 --- a/cmd/kms/key/key_delete.go +++ b/cmd/kms/key/key_delete.go @@ -57,7 +57,7 @@ func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&keyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) diff --git a/cmd/kms/key/key_disable.go b/cmd/kms/key/key_disable.go index 7947b1952..a42b938f6 100644 --- a/cmd/kms/key/key_disable.go +++ b/cmd/kms/key/key_disable.go @@ -38,7 +38,7 @@ func (c *keyDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&keyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) diff --git a/cmd/kms/key/key_enable.go b/cmd/kms/key/key_enable.go index 478d288bd..a2a66a1ee 100644 --- a/cmd/kms/key/key_enable.go +++ b/cmd/kms/key/key_enable.go @@ -38,7 +38,7 @@ func (c *keyEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&keyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) diff --git a/cmd/kms/key/key_rotate.go b/cmd/kms/key/key_rotate.go new file mode 100644 index 000000000..45b44b932 --- /dev/null +++ b/cmd/kms/key/key_rotate.go @@ -0,0 +1,55 @@ +package key + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type keyRotateCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"rotate"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *keyRotateCmd) CmdAliases() []string { return nil } + +func (c *keyRotateCmd) CmdShort() string { + return "Rotates a KMS key." +} + +func (c *keyRotateCmd) CmdLong() string { + return "Rotates a KMS key." +} + +func (c *keyRotateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *keyRotateCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + _, err := client.RotateKmsKey(ctx, v3.UUID(c.Key)) + if err != nil { + return err + } + + if !globalstate.Quiet { + return (&KeyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyRotateCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go index 163be5240..17b4b5543 100644 --- a/cmd/kms/key/key_show.go +++ b/cmd/kms/key/key_show.go @@ -30,7 +30,7 @@ func (o *KeyShowOutput) ToJSON() { output.JSON(o) } func (o *KeyShowOutput) ToText() { output.Text(o) } func (o *KeyShowOutput) ToTable() { output.Table(o) } -type keyShowCmd struct { +type KeyShowCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"show"` @@ -38,21 +38,21 @@ type keyShowCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` } -func (c *keyShowCmd) CmdAliases() []string { return exocmd.GShowAlias } +func (c *KeyShowCmd) CmdAliases() []string { return exocmd.GShowAlias } -func (c *keyShowCmd) CmdShort() string { +func (c *KeyShowCmd) CmdShort() string { return "Shows details of a KMS key." } -func (c *keyShowCmd) CmdLong() string { +func (c *KeyShowCmd) CmdLong() string { return "Shows details of a KMS key." } -func (c *keyShowCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *KeyShowCmd) CmdPreRun(cmd *cobra.Command, args []string) error { return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *KeyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client := globalstate.EgoscaleV3Client @@ -79,7 +79,7 @@ func (c *keyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyShowCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &KeyShowCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/rotation/rotation.go b/cmd/kms/rotation/rotation.go new file mode 100644 index 000000000..368e546ea --- /dev/null +++ b/cmd/kms/rotation/rotation.go @@ -0,0 +1,15 @@ +package rotation + +import ( + "github.com/exoscale/cli/cmd/kms" + "github.com/spf13/cobra" +) + +var rotationCmd = &cobra.Command{ + Use: "rotation", + Short: "KMS key rotation", +} + +func init() { + kms.KMSCmd.AddCommand(rotationCmd) +} diff --git a/cmd/kms/rotation/rotation_disable.go b/cmd/kms/rotation/rotation_disable.go new file mode 100644 index 000000000..6036a2fa3 --- /dev/null +++ b/cmd/kms/rotation/rotation_disable.go @@ -0,0 +1,55 @@ +package rotation + +import ( + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/cmd/kms/key" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type rotationDisableCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"disable"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *rotationDisableCmd) CmdAliases() []string { return nil } + +func (c *rotationDisableCmd) CmdShort() string { + return "Disable KMS key auto rotation." +} + +func (c *rotationDisableCmd) CmdLong() string { + return "Disable KMS key auto rotation." +} + +func (c *rotationDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *rotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + if _, err := client.DisableKmsKeyRotation(ctx, v3.UUID(c.Key)); err != nil { + return err + } + + if !globalstate.Quiet { + return (&key.KeyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationDisableCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/rotation/rotation_enable.go b/cmd/kms/rotation/rotation_enable.go new file mode 100644 index 000000000..50f645c85 --- /dev/null +++ b/cmd/kms/rotation/rotation_enable.go @@ -0,0 +1,70 @@ +package rotation + +import ( + "strconv" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/cmd/kms/key" + "github.com/exoscale/cli/pkg/globalstate" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type rotationEnableCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"enable"` + + Key string `cli-arg:"#" cli-usage:"ID"` + + RotationPeriod string `cli-flag:"rotation-period" cli-usage:"rotation period to use for auto rotation"` +} + +func (c *rotationEnableCmd) CmdAliases() []string { return nil } + +func (c *rotationEnableCmd) CmdShort() string { + return "Enable KMS key auto rotation." +} + +func (c *rotationEnableCmd) CmdLong() string { + return "Enable KMS key auto rotation." +} + +func (c *rotationEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *rotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + var req v3.EnableKmsKeyRotationRequest + if c.RotationPeriod != "" { + n, err := strconv.Atoi(c.RotationPeriod) + if err != nil { + return err + } + req = v3.EnableKmsKeyRotationRequest{ + RotationPeriod: n, + } + } + + if _, err := client.EnableKmsKeyRotation(ctx, v3.UUID(c.Key), req); err != nil { + return err + } + + if !globalstate.Quiet { + return (&key.KeyShowCmd{ + CliCommandSettings: c.CliCommandSettings, + Key: c.Key, + }).CmdRun(nil, nil) + } + + return nil +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationEnableCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/kms/rotation/rotation_list.go b/cmd/kms/rotation/rotation_list.go new file mode 100644 index 000000000..91c9273c9 --- /dev/null +++ b/cmd/kms/rotation/rotation_list.go @@ -0,0 +1,79 @@ +package rotation + +import ( + "os" + "strconv" + + exocmd "github.com/exoscale/cli/cmd" + "github.com/exoscale/cli/pkg/globalstate" + "github.com/exoscale/cli/pkg/output" + "github.com/exoscale/cli/table" + v3 "github.com/exoscale/egoscale/v3" + "github.com/spf13/cobra" +) + +type rotationListOutput struct { + v3.ListKmsKeyRotationsResponse +} + +func (o *rotationListOutput) ToJSON() { output.JSON(o) } +func (o *rotationListOutput) ToText() { output.Text(o) } +func (o *rotationListOutput) ToTable() { + t := table.NewTable(os.Stdout) + defer t.Render() + + t.SetHeader([]string{ + "VERSION", + "ROTATED_AT", + "AUTOMATIC", + }) + + for _, rotation := range o.Rotations { + t.Append([]string{ + strconv.Itoa(rotation.Version), + rotation.RotatedAT.String(), + strconv.FormatBool(*rotation.Automatic), + }) + } +} + +type rotationListCmd struct { + exocmd.CliCommandSettings `cli-cmd:"-"` + + _ bool `cli-cmd:"list"` + + Key string `cli-arg:"#" cli-usage:"ID"` +} + +func (c *rotationListCmd) CmdAliases() []string { return exocmd.GListAlias } + +func (c *rotationListCmd) CmdShort() string { + return "List KMS key rotations." +} + +func (c *rotationListCmd) CmdLong() string { + return "List KMS key rotations." +} + +func (c *rotationListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + return exocmd.CliCommandDefaultPreRun(c, cmd, args) +} + +func (c *rotationListCmd) CmdRun(_ *cobra.Command, _ []string) error { + ctx := exocmd.GContext + client := globalstate.EgoscaleV3Client + + resp, err := client.ListKmsKeyRotations(ctx, v3.UUID(c.Key)) + if err != nil { + return err + } + out := rotationListOutput{*resp} + + return c.OutputFunc(&out, nil) +} + +func init() { + cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationListCmd{ + CliCommandSettings: exocmd.DefaultCLICmdSettings(), + })) +} diff --git a/cmd/subcommands/init.go b/cmd/subcommands/init.go index a39305195..d1e3921ba 100644 --- a/cmd/subcommands/init.go +++ b/cmd/subcommands/init.go @@ -28,5 +28,6 @@ import ( _ "github.com/exoscale/cli/cmd/iam" _ "github.com/exoscale/cli/cmd/kms" _ "github.com/exoscale/cli/cmd/kms/key" + _ "github.com/exoscale/cli/cmd/kms/rotation" _ "github.com/exoscale/cli/cmd/storage" ) From 0d69e1bec3ec114dcfa65409715c657f323a6094 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Mon, 18 May 2026 16:47:48 +0200 Subject: [PATCH 16/24] add defaults in description --- cmd/kms/key/key_create.go | 4 ++-- cmd/kms/key/key_delete.go | 2 +- cmd/kms/key/key_encrypt.go | 2 +- cmd/kms/key/key_generate_dek.go | 4 ++-- cmd/kms/rotation/rotation_enable.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index e83213e10..abb5a1c5a 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -15,8 +15,8 @@ type keyCreateCmd struct { Name string `cli-arg:"#" cli-usage:"NAME"` Description string `cli-flag:"description" cli-usage:"key description"` - Usage string `cli-flag:"usage" cli-usage:"symmetric encryption with encrypt-decrypt"` - Multizone bool `cli-flag:"multizone" cli-usage:"allow replication accross zones"` + Usage string `cli-flag:"usage" cli-usage:"key usage [encrypt-decrypt]"` + Multizone bool `cli-flag:"multizone" cli-usage:"allow replication accross zones (default: false)"` } func (c *keyCreateCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_delete.go index a960b4645..fa628e092 100644 --- a/cmd/kms/key/key_delete.go +++ b/cmd/kms/key/key_delete.go @@ -17,7 +17,7 @@ type keyDeleteCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - DelayDays string `cli-flag:"delay-days" cli-usage:"number of days before deletion (7-30, default 30)"` + DelayDays string `cli-flag:"delay-days" cli-usage:"number of days before deletion (7 - 30, default: 30)"` } func (c *keyDeleteCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index 48320f03f..07fa152b4 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -37,7 +37,7 @@ type keyEncryptCmd struct { _ bool `cli-cmd:"encrypt"` Key string `cli-arg:"#" cli-usage:"ID"` - Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT_b64"` + Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT"` EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` } diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_dek.go index 7ae9d3870..fdd174690 100644 --- a/cmd/kms/key/key_generate_dek.go +++ b/cmd/kms/key/key_generate_dek.go @@ -41,8 +41,8 @@ type keyGenerateDEKCmd struct { _ bool `cli-cmd:"generate-dek"` Key string `cli-arg:"#" cli-usage:"ID"` - KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK (AES_256)"` - BytesCount string `cli-flag:"bytes-count" cli-usage:"number of bytes for DEK"` + KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK [AES_256]"` + BytesCount string `cli-flag:"bytes-count" cli-usage:"number of bytes for DEK (1 - 1024)"` EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` } diff --git a/cmd/kms/rotation/rotation_enable.go b/cmd/kms/rotation/rotation_enable.go index 50f645c85..1b519f613 100644 --- a/cmd/kms/rotation/rotation_enable.go +++ b/cmd/kms/rotation/rotation_enable.go @@ -17,7 +17,7 @@ type rotationEnableCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - RotationPeriod string `cli-flag:"rotation-period" cli-usage:"rotation period to use for auto rotation"` + RotationPeriod string `cli-flag:"rotation-period" cli-usage:"number of days for auto rotation period (90 - 2560, default: 365)"` } func (c *rotationEnableCmd) CmdAliases() []string { return nil } From d7e58c59ccec4a7ea700ee881c253cdc51c7b7f1 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 19 May 2026 09:23:57 +0200 Subject: [PATCH 17/24] add cli-short --- cmd/kms/key/key_create.go | 6 +++--- cmd/kms/key/key_decrypt.go | 2 +- cmd/kms/key/key_delete.go | 2 +- cmd/kms/key/key_encrypt.go | 2 +- cmd/kms/key/key_generate_dek.go | 6 +++--- cmd/kms/key/key_reencrypt.go | 4 ++-- cmd/kms/rotation/rotation_enable.go | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index abb5a1c5a..96a112de9 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -14,9 +14,9 @@ type keyCreateCmd struct { Name string `cli-arg:"#" cli-usage:"NAME"` - Description string `cli-flag:"description" cli-usage:"key description"` - Usage string `cli-flag:"usage" cli-usage:"key usage [encrypt-decrypt]"` - Multizone bool `cli-flag:"multizone" cli-usage:"allow replication accross zones (default: false)"` + Description string `cli-short:"d" cli-flag:"description" cli-usage:"key description"` + Usage string `cli-short:"u" cli-flag:"usage" cli-usage:"key usage [encrypt-decrypt]"` + Multizone bool `cli-short:"m" cli-flag:"multizone" cli-usage:"allow replication accross zones (default: false)"` } func (c *keyCreateCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go index f630bc56c..0d60d4c90 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/key/key_decrypt.go @@ -39,7 +39,7 @@ type keyDecryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` - EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` + EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` } func (c *keyDecryptCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_delete.go index fa628e092..aadedbbc1 100644 --- a/cmd/kms/key/key_delete.go +++ b/cmd/kms/key/key_delete.go @@ -17,7 +17,7 @@ type keyDeleteCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - DelayDays string `cli-flag:"delay-days" cli-usage:"number of days before deletion (7 - 30, default: 30)"` + DelayDays string `cli-short:"d" cli-flag:"delay-days" cli-usage:"number of days before deletion (7 - 30, default: 30)"` } func (c *keyDeleteCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index 07fa152b4..40b3dece1 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -39,7 +39,7 @@ type keyEncryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT"` - EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` + EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` } func (c *keyEncryptCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_dek.go index fdd174690..6d8409640 100644 --- a/cmd/kms/key/key_generate_dek.go +++ b/cmd/kms/key/key_generate_dek.go @@ -41,9 +41,9 @@ type keyGenerateDEKCmd struct { _ bool `cli-cmd:"generate-dek"` Key string `cli-arg:"#" cli-usage:"ID"` - KeySpec v3.GenerateDataKeyRequestKeySpec `cli-flag:"key-spec" cli-usage:"key spec for DEK [AES_256]"` - BytesCount string `cli-flag:"bytes-count" cli-usage:"number of bytes for DEK (1 - 1024)"` - EncryptionContext string `cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` + KeySpec v3.GenerateDataKeyRequestKeySpec `cli-short:"s" cli-flag:"key-spec" cli-usage:"key spec for DEK [AES_256]"` + BytesCount string `cli-short:"b" cli-flag:"bytes-count" cli-usage:"number of bytes for DEK (1 - 1024)"` + EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` } func (c *keyGenerateDEKCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/key/key_reencrypt.go b/cmd/kms/key/key_reencrypt.go index 3e13d693f..1438bb15d 100644 --- a/cmd/kms/key/key_reencrypt.go +++ b/cmd/kms/key/key_reencrypt.go @@ -18,8 +18,8 @@ type keyReencryptCmd struct { DestinationKey string `cli-arg:"#" cli-usage:"DEST_ID"` Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` - SourceEncryptionContext string `cli-flag:"source-encryption-context" cli-usage:"encryption context to use for source ciphertext decryption"` - DestEncryptionContext string `cli-flag:"dest-encryption-context" cli-usage:"encryption context to use for destination ciphertext encryption"` + SourceEncryptionContext string `cli-short:"s" cli-flag:"source-encryption-context" cli-usage:"encryption context to use for source ciphertext decryption"` + DestEncryptionContext string `cli-short:"d" cli-flag:"dest-encryption-context" cli-usage:"encryption context to use for destination ciphertext encryption"` } func (c *keyReencryptCmd) CmdAliases() []string { return nil } diff --git a/cmd/kms/rotation/rotation_enable.go b/cmd/kms/rotation/rotation_enable.go index 1b519f613..a05917ebf 100644 --- a/cmd/kms/rotation/rotation_enable.go +++ b/cmd/kms/rotation/rotation_enable.go @@ -17,7 +17,7 @@ type rotationEnableCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - RotationPeriod string `cli-flag:"rotation-period" cli-usage:"number of days for auto rotation period (90 - 2560, default: 365)"` + RotationPeriod string `cli-flag:"rotation-period" cli-short:"r" cli-usage:"number of days for auto rotation period (90 - 2560, default: 365)"` } func (c *rotationEnableCmd) CmdAliases() []string { return nil } From 3558ff5350e0100c484fb0439d99b77355bf4ead Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 19 May 2026 09:40:32 +0200 Subject: [PATCH 18/24] add title to error message --- cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index d1623e0ed..cc996ab7e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -116,7 +116,7 @@ func formatError(err error) string { return apiErr.Unwrap().Error() } - msg := apiErr.Unwrap().Error() + ": " + lead + msg := apiErr.Unwrap().Error() + ": " + apiErr.Title + ": " + lead for _, e := range apiErr.Errors { field := formatFieldName(e.Location) detail := formatDetail(e.Detail) From 24c758e70d0a3a42a79921a42d29de70c4c1b1ed Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 19 May 2026 10:15:57 +0200 Subject: [PATCH 19/24] add zone support --- cmd/kms/key/key_cancel_delete.go | 10 ++++++++-- cmd/kms/key/key_create.go | 13 +++++++++---- cmd/kms/key/key_decrypt.go | 9 +++++++-- cmd/kms/key/key_delete.go | 11 ++++++++--- cmd/kms/key/key_disable.go | 8 +++++++- cmd/kms/key/key_enable.go | 8 +++++++- cmd/kms/key/key_encrypt.go | 9 +++++++-- cmd/kms/key/key_generate_dek.go | 10 ++++++++-- cmd/kms/key/key_list.go | 8 +++++++- cmd/kms/key/key_reencrypt.go | 11 ++++++++--- cmd/kms/key/key_replicate.go | 14 ++++++++++---- cmd/kms/key/key_rotate.go | 10 ++++++++-- cmd/kms/key/key_show.go | 8 +++++++- cmd/kms/rotation/rotation_disable.go | 8 +++++++- cmd/kms/rotation/rotation_enable.go | 9 +++++++-- cmd/kms/rotation/rotation_list.go | 9 ++++++++- 16 files changed, 123 insertions(+), 32 deletions(-) diff --git a/cmd/kms/key/key_cancel_delete.go b/cmd/kms/key/key_cancel_delete.go index b1bdd6e98..111172aa6 100644 --- a/cmd/kms/key/key_cancel_delete.go +++ b/cmd/kms/key/key_cancel_delete.go @@ -13,6 +13,8 @@ type keyCancelDeleteCmd struct { _ bool `cli-cmd:"cancel-delete"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyCancelDeleteCmd) CmdAliases() []string { return nil } @@ -26,14 +28,18 @@ func (c *keyCancelDeleteCmd) CmdLong() string { } func (c *keyCancelDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyCancelDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } - _, err := client.CancelKmsKeyDeletion(ctx, v3.UUID(c.Key)) + _, err = client.CancelKmsKeyDeletion(ctx, v3.UUID(c.Key)) if err != nil { return err } diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index 96a112de9..bf81c88d9 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -14,9 +14,10 @@ type keyCreateCmd struct { Name string `cli-arg:"#" cli-usage:"NAME"` - Description string `cli-short:"d" cli-flag:"description" cli-usage:"key description"` - Usage string `cli-short:"u" cli-flag:"usage" cli-usage:"key usage [encrypt-decrypt]"` - Multizone bool `cli-short:"m" cli-flag:"multizone" cli-usage:"allow replication accross zones (default: false)"` + Description string `cli-short:"d" cli-flag:"description" cli-usage:"key description"` + Usage string `cli-short:"u" cli-flag:"usage" cli-usage:"key usage [encrypt-decrypt]"` + Multizone bool `cli-short:"m" cli-flag:"multizone" cli-usage:"allow replication accross zones (default: false)"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyCreateCmd) CmdAliases() []string { return nil } @@ -30,12 +31,16 @@ func (c *keyCreateCmd) CmdLong() string { } func (c *keyCreateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyCreateCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } req := v3.CreateKmsKeyRequest{ Name: c.Name, diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/key/key_decrypt.go index 0d60d4c90..dd6607356 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/key/key_decrypt.go @@ -39,7 +39,8 @@ type keyDecryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` - EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` + EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyDecryptCmd) CmdAliases() []string { return nil } @@ -53,12 +54,16 @@ func (c *keyDecryptCmd) CmdLong() string { } func (c *keyDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } ec := []byte(c.EncryptionContext) decoded, err := base64.StdEncoding.DecodeString(c.Ciphertext) diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_delete.go index aadedbbc1..ea31cb1ae 100644 --- a/cmd/kms/key/key_delete.go +++ b/cmd/kms/key/key_delete.go @@ -17,7 +17,8 @@ type keyDeleteCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - DelayDays string `cli-short:"d" cli-flag:"delay-days" cli-usage:"number of days before deletion (7 - 30, default: 30)"` + DelayDays string `cli-short:"d" cli-flag:"delay-days" cli-usage:"number of days before deletion (7 - 30, default: 30)"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyDeleteCmd) CmdAliases() []string { return nil } @@ -31,12 +32,16 @@ func (c *keyDeleteCmd) CmdLong() string { } func (c *keyDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } var delayDays int if c.DelayDays != "" { @@ -51,7 +56,7 @@ func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { DelayDays: delayDays, } - _, err := client.ScheduleKmsKeyDeletion(ctx, v3.UUID(c.Key), req) + _, err = client.ScheduleKmsKeyDeletion(ctx, v3.UUID(c.Key), req) if err != nil { return err } diff --git a/cmd/kms/key/key_disable.go b/cmd/kms/key/key_disable.go index a42b938f6..059dfbf29 100644 --- a/cmd/kms/key/key_disable.go +++ b/cmd/kms/key/key_disable.go @@ -13,6 +13,8 @@ type keyDisableCmd struct { _ bool `cli-cmd:"disable"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyDisableCmd) CmdAliases() []string { return nil } @@ -26,12 +28,16 @@ func (c *keyDisableCmd) CmdLong() string { } func (c *keyDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } if _, err := client.DisableKmsKey(ctx, v3.UUID(c.Key)); err != nil { return err diff --git a/cmd/kms/key/key_enable.go b/cmd/kms/key/key_enable.go index a2a66a1ee..7a4ad5065 100644 --- a/cmd/kms/key/key_enable.go +++ b/cmd/kms/key/key_enable.go @@ -13,6 +13,8 @@ type keyEnableCmd struct { _ bool `cli-cmd:"enable"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyEnableCmd) CmdAliases() []string { return nil } @@ -26,12 +28,16 @@ func (c *keyEnableCmd) CmdLong() string { } func (c *keyEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } if _, err := client.EnableKmsKey(ctx, v3.UUID(c.Key)); err != nil { return err diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/key/key_encrypt.go index 40b3dece1..a42f9edd2 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/key/key_encrypt.go @@ -39,7 +39,8 @@ type keyEncryptCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` Plaintext string `cli-arg:"#" cli-usage:"PLAINTEXT"` - EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` + EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for encryption"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyEncryptCmd) CmdAliases() []string { return nil } @@ -53,12 +54,16 @@ func (c *keyEncryptCmd) CmdLong() string { } func (c *keyEncryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } ec := []byte(c.EncryptionContext) req := v3.EncryptRequest{ diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_dek.go index 6d8409640..c20208c1c 100644 --- a/cmd/kms/key/key_generate_dek.go +++ b/cmd/kms/key/key_generate_dek.go @@ -40,10 +40,12 @@ type keyGenerateDEKCmd struct { _ bool `cli-cmd:"generate-dek"` - Key string `cli-arg:"#" cli-usage:"ID"` + Key string `cli-arg:"#" cli-usage:"ID"` + KeySpec v3.GenerateDataKeyRequestKeySpec `cli-short:"s" cli-flag:"key-spec" cli-usage:"key spec for DEK [AES_256]"` BytesCount string `cli-short:"b" cli-flag:"bytes-count" cli-usage:"number of bytes for DEK (1 - 1024)"` EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for DEK generation"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyGenerateDEKCmd) CmdAliases() []string { return nil } @@ -57,12 +59,16 @@ func (c *keyGenerateDEKCmd) CmdLong() string { } func (c *keyGenerateDEKCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyGenerateDEKCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } ec := []byte(c.EncryptionContext) diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go index f8d72d114..e0b0e536c 100644 --- a/cmd/kms/key/key_list.go +++ b/cmd/kms/key/key_list.go @@ -48,6 +48,8 @@ type keyListCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"list"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyListCmd) CmdAliases() []string { return exocmd.GListAlias } @@ -61,12 +63,16 @@ func (c *keyListCmd) CmdLong() string { } func (c *keyListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyListCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } keys, err := client.ListKmsKeys(ctx) if err != nil { diff --git a/cmd/kms/key/key_reencrypt.go b/cmd/kms/key/key_reencrypt.go index 1438bb15d..3bbc29481 100644 --- a/cmd/kms/key/key_reencrypt.go +++ b/cmd/kms/key/key_reencrypt.go @@ -18,8 +18,9 @@ type keyReencryptCmd struct { DestinationKey string `cli-arg:"#" cli-usage:"DEST_ID"` Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` - SourceEncryptionContext string `cli-short:"s" cli-flag:"source-encryption-context" cli-usage:"encryption context to use for source ciphertext decryption"` - DestEncryptionContext string `cli-short:"d" cli-flag:"dest-encryption-context" cli-usage:"encryption context to use for destination ciphertext encryption"` + SourceEncryptionContext string `cli-short:"s" cli-flag:"source-encryption-context" cli-usage:"encryption context to use for source ciphertext decryption"` + DestEncryptionContext string `cli-short:"d" cli-flag:"dest-encryption-context" cli-usage:"encryption context to use for destination ciphertext encryption"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyReencryptCmd) CmdAliases() []string { return nil } @@ -33,12 +34,16 @@ func (c *keyReencryptCmd) CmdLong() string { } func (c *keyReencryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } var sourceEC []byte if c.SourceEncryptionContext != "" { diff --git a/cmd/kms/key/key_replicate.go b/cmd/kms/key/key_replicate.go index c23621eee..54894817f 100644 --- a/cmd/kms/key/key_replicate.go +++ b/cmd/kms/key/key_replicate.go @@ -12,8 +12,10 @@ type keyReplicateCmd struct { _ bool `cli-cmd:"replicate"` - Key string `cli-arg:"#" cli-usage:"ID"` - Zone v3.ZoneName `cli-arg:"#" cli-usage:"ZONE"` + Key string `cli-arg:"#" cli-usage:"ID"` + TargetZone v3.ZoneName `cli-arg:"#" cli-usage:"TARGET_ZONE"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyReplicateCmd) CmdAliases() []string { return nil } @@ -27,15 +29,19 @@ func (c *keyReplicateCmd) CmdLong() string { } func (c *keyReplicateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyReplicateCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } req := v3.ReplicateKmsKeyRequest{ - Zone: string(c.Zone), + Zone: string(c.TargetZone), } resp, err := client.ReplicateKmsKey(ctx, v3.UUID(c.Key), req) diff --git a/cmd/kms/key/key_rotate.go b/cmd/kms/key/key_rotate.go index 45b44b932..ad3c80034 100644 --- a/cmd/kms/key/key_rotate.go +++ b/cmd/kms/key/key_rotate.go @@ -13,6 +13,8 @@ type keyRotateCmd struct { _ bool `cli-cmd:"rotate"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyRotateCmd) CmdAliases() []string { return nil } @@ -26,14 +28,18 @@ func (c *keyRotateCmd) CmdLong() string { } func (c *keyRotateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *keyRotateCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } - _, err := client.RotateKmsKey(ctx, v3.UUID(c.Key)) + _, err = client.RotateKmsKey(ctx, v3.UUID(c.Key)) if err != nil { return err } diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go index 17b4b5543..28cac50f8 100644 --- a/cmd/kms/key/key_show.go +++ b/cmd/kms/key/key_show.go @@ -36,6 +36,8 @@ type KeyShowCmd struct { _ bool `cli-cmd:"show"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *KeyShowCmd) CmdAliases() []string { return exocmd.GShowAlias } @@ -49,12 +51,16 @@ func (c *KeyShowCmd) CmdLong() string { } func (c *KeyShowCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *KeyShowCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } resp, err := client.GetKmsKey(ctx, v3.UUID(c.Key)) if err != nil { diff --git a/cmd/kms/rotation/rotation_disable.go b/cmd/kms/rotation/rotation_disable.go index 6036a2fa3..9736cbc89 100644 --- a/cmd/kms/rotation/rotation_disable.go +++ b/cmd/kms/rotation/rotation_disable.go @@ -14,6 +14,8 @@ type rotationDisableCmd struct { _ bool `cli-cmd:"disable"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *rotationDisableCmd) CmdAliases() []string { return nil } @@ -27,12 +29,16 @@ func (c *rotationDisableCmd) CmdLong() string { } func (c *rotationDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *rotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } if _, err := client.DisableKmsKeyRotation(ctx, v3.UUID(c.Key)); err != nil { return err diff --git a/cmd/kms/rotation/rotation_enable.go b/cmd/kms/rotation/rotation_enable.go index a05917ebf..b26f50d95 100644 --- a/cmd/kms/rotation/rotation_enable.go +++ b/cmd/kms/rotation/rotation_enable.go @@ -17,7 +17,8 @@ type rotationEnableCmd struct { Key string `cli-arg:"#" cli-usage:"ID"` - RotationPeriod string `cli-flag:"rotation-period" cli-short:"r" cli-usage:"number of days for auto rotation period (90 - 2560, default: 365)"` + RotationPeriod string `cli-flag:"rotation-period" cli-short:"r" cli-usage:"number of days for auto rotation period (90 - 2560, default: 365)"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *rotationEnableCmd) CmdAliases() []string { return nil } @@ -31,12 +32,16 @@ func (c *rotationEnableCmd) CmdLong() string { } func (c *rotationEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *rotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } var req v3.EnableKmsKeyRotationRequest if c.RotationPeriod != "" { diff --git a/cmd/kms/rotation/rotation_list.go b/cmd/kms/rotation/rotation_list.go index 91c9273c9..acd7f9969 100644 --- a/cmd/kms/rotation/rotation_list.go +++ b/cmd/kms/rotation/rotation_list.go @@ -43,6 +43,8 @@ type rotationListCmd struct { _ bool `cli-cmd:"list"` Key string `cli-arg:"#" cli-usage:"ID"` + + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *rotationListCmd) CmdAliases() []string { return exocmd.GListAlias } @@ -56,12 +58,17 @@ func (c *rotationListCmd) CmdLong() string { } func (c *rotationListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { + exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } func (c *rotationListCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext - client := globalstate.EgoscaleV3Client + + client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) + if err != nil { + return err + } resp, err := client.ListKmsKeyRotations(ctx, v3.UUID(c.Key)) if err != nil { From cb24b0c72c9af01bf0801e13e7b9ed72a5a526d7 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 19 May 2026 10:23:06 +0200 Subject: [PATCH 20/24] add --ignore-replica --status filter --- cmd/kms/key/key_list.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go index e0b0e536c..a06c1741f 100644 --- a/cmd/kms/key/key_list.go +++ b/cmd/kms/key/key_list.go @@ -49,7 +49,9 @@ type keyListCmd struct { _ bool `cli-cmd:"list"` - Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` + IgnoreReplicas bool `cli-short:"i" cli-flag:"ignore-replica" cli-usage:"filter out replicas"` + Status string `cli-short:"s" cli-flag:"status" cli-usage:"filter by key status [enabled|disabled|pending-deletion]"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyListCmd) CmdAliases() []string { return exocmd.GListAlias } @@ -79,7 +81,18 @@ func (c *keyListCmd) CmdRun(_ *cobra.Command, _ []string) error { return err } - out := keyListOutput{*keys} + filtered := make([]v3.ListKmsKeysResponseEntry, 0, len(keys.KmsKeys)) + for _, key := range keys.KmsKeys { + if c.IgnoreReplicas && key.OriginZone != string(c.Zone) { + continue + } + if c.Status != "" && string(key.Status) != c.Status { + continue + } + filtered = append(filtered, key) + } + + out := keyListOutput{v3.ListKmsKeysResponse{KmsKeys: filtered}} return c.OutputFunc(&out, nil) } From 5928dd2ab2bf5c20d58149fcc53067e1e140499c Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 19 May 2026 10:24:25 +0200 Subject: [PATCH 21/24] typo --- cmd/kms/key/key_list.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go index a06c1741f..a648896e3 100644 --- a/cmd/kms/key/key_list.go +++ b/cmd/kms/key/key_list.go @@ -49,9 +49,9 @@ type keyListCmd struct { _ bool `cli-cmd:"list"` - IgnoreReplicas bool `cli-short:"i" cli-flag:"ignore-replica" cli-usage:"filter out replicas"` - Status string `cli-short:"s" cli-flag:"status" cli-usage:"filter by key status [enabled|disabled|pending-deletion]"` - Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` + IgnoreReplica bool `cli-short:"i" cli-flag:"ignore-replica" cli-usage:"filter out replicas"` + Status string `cli-short:"s" cli-flag:"status" cli-usage:"filter by key status [enabled|disabled|pending-deletion]"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } func (c *keyListCmd) CmdAliases() []string { return exocmd.GListAlias } @@ -83,7 +83,7 @@ func (c *keyListCmd) CmdRun(_ *cobra.Command, _ []string) error { filtered := make([]v3.ListKmsKeysResponseEntry, 0, len(keys.KmsKeys)) for _, key := range keys.KmsKeys { - if c.IgnoreReplicas && key.OriginZone != string(c.Zone) { + if c.IgnoreReplica && key.OriginZone != string(c.Zone) { continue } if c.Status != "" && string(key.Status) != c.Status { From b28ffee0f3ec53a9e43738906b95f5ec0440a595 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 26 May 2026 15:07:35 +0200 Subject: [PATCH 22/24] renaming --- ...nerate_dek.go => key_generate_data_key.go} | 30 +++++++++---------- ...key_delete.go => key_schedule_deletion.go} | 20 ++++++------- 2 files changed, 25 insertions(+), 25 deletions(-) rename cmd/kms/key/{key_generate_dek.go => key_generate_data_key.go} (70%) rename cmd/kms/key/{key_delete.go => key_schedule_deletion.go} (69%) diff --git a/cmd/kms/key/key_generate_dek.go b/cmd/kms/key/key_generate_data_key.go similarity index 70% rename from cmd/kms/key/key_generate_dek.go rename to cmd/kms/key/key_generate_data_key.go index c20208c1c..4814ea71a 100644 --- a/cmd/kms/key/key_generate_dek.go +++ b/cmd/kms/key/key_generate_data_key.go @@ -13,14 +13,14 @@ import ( "github.com/spf13/cobra" ) -type keyGenerateDEKOutput struct { +type keyGenerateDataKeyOutput struct { Plaintext string `json:"plaintext"` Ciphertext string `json:"ciphertext"` } -func (o *keyGenerateDEKOutput) ToJSON() { output.JSON(o) } -func (o *keyGenerateDEKOutput) ToText() { output.Text(o) } -func (o *keyGenerateDEKOutput) ToTable() { +func (o *keyGenerateDataKeyOutput) ToJSON() { output.JSON(o) } +func (o *keyGenerateDataKeyOutput) ToText() { output.Text(o) } +func (o *keyGenerateDataKeyOutput) ToTable() { t := table.NewTable(os.Stdout) defer t.Render() @@ -35,10 +35,10 @@ func (o *keyGenerateDEKOutput) ToTable() { }) } -type keyGenerateDEKCmd struct { +type keyGenerateDataKeyCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"generate-dek"` + _ bool `cli-cmd:"generate-data-key"` Key string `cli-arg:"#" cli-usage:"ID"` @@ -48,22 +48,22 @@ type keyGenerateDEKCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyGenerateDEKCmd) CmdAliases() []string { return nil } +func (c *keyGenerateDataKeyCmd) CmdAliases() []string { return nil } -func (c *keyGenerateDEKCmd) CmdShort() string { - return "Generates a data encryption key (DEK) using a KMS key." +func (c *keyGenerateDataKeyCmd) CmdShort() string { + return "Generates a data encryption key using a KMS key." } -func (c *keyGenerateDEKCmd) CmdLong() string { - return "Generates a data encryption key (DEK) using a KMS key." +func (c *keyGenerateDataKeyCmd) CmdLong() string { + return "Generates a data encryption key using a KMS key." } -func (c *keyGenerateDEKCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyGenerateDataKeyCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyGenerateDEKCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyGenerateDataKeyCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -93,7 +93,7 @@ func (c *keyGenerateDEKCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - out := keyGenerateDEKOutput{ + out := keyGenerateDataKeyOutput{ Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), Plaintext: base64.StdEncoding.EncodeToString(resp.Plaintext), } @@ -103,7 +103,7 @@ func (c *keyGenerateDEKCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyGenerateDEKCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyGenerateDataKeyCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_delete.go b/cmd/kms/key/key_schedule_deletion.go similarity index 69% rename from cmd/kms/key/key_delete.go rename to cmd/kms/key/key_schedule_deletion.go index ea31cb1ae..ff115610c 100644 --- a/cmd/kms/key/key_delete.go +++ b/cmd/kms/key/key_schedule_deletion.go @@ -10,10 +10,10 @@ import ( "github.com/spf13/cobra" ) -type keyDeleteCmd struct { +type keyScheduleDeletionCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"delete"` + _ bool `cli-cmd:"schedule-deletion"` Key string `cli-arg:"#" cli-usage:"ID"` @@ -21,22 +21,22 @@ type keyDeleteCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyDeleteCmd) CmdAliases() []string { return nil } +func (c *keyScheduleDeletionCmd) CmdAliases() []string { return nil } -func (c *keyDeleteCmd) CmdShort() string { - return "Deletes a KMS key." +func (c *keyScheduleDeletionCmd) CmdShort() string { + return "Schedules deletion of a KMS key." } -func (c *keyDeleteCmd) CmdLong() string { - return "Deletes a KMS key." +func (c *keyScheduleDeletionCmd) CmdLong() string { + return "Schedules deletion of a KMS key." } -func (c *keyDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyScheduleDeletionCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyScheduleDeletionCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -72,7 +72,7 @@ func (c *keyDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyDeleteCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyScheduleDeletionCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } From db989b491250fb1eb980ddf97a28d8c2efb6a604 Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Tue, 26 May 2026 16:02:30 +0200 Subject: [PATCH 23/24] renaming --- cmd/kms/crypto/crypto.go | 15 ++++++++++ .../crypto_decrypt.go} | 28 +++++++++---------- .../crypto_encrypt.go} | 26 ++++++++--------- .../crypto_generate_data_key.go} | 26 ++++++++--------- .../crypto_reencrypt.go} | 18 ++++++------ ...ancel_delete.go => key_cancel_deletion.go} | 16 +++++------ .../key_rotation_disable.go} | 21 +++++++------- .../key_rotation_enable.go} | 21 +++++++------- .../key_rotation_list.go} | 28 +++++++++---------- cmd/kms/rotation/rotation.go | 15 ---------- cmd/subcommands/init.go | 2 +- 11 files changed, 107 insertions(+), 109 deletions(-) create mode 100644 cmd/kms/crypto/crypto.go rename cmd/kms/{key/key_decrypt.go => crypto/crypto_decrypt.go} (71%) rename cmd/kms/{key/key_encrypt.go => crypto/crypto_encrypt.go} (71%) rename cmd/kms/{key/key_generate_data_key.go => crypto/crypto_generate_data_key.go} (74%) rename cmd/kms/{key/key_reencrypt.go => crypto/crypto_reencrypt.go} (82%) rename cmd/kms/key/{key_cancel_delete.go => key_cancel_deletion.go} (72%) rename cmd/kms/{rotation/rotation_disable.go => key/key_rotation_disable.go} (63%) rename cmd/kms/{rotation/rotation_enable.go => key/key_rotation_enable.go} (71%) rename cmd/kms/{rotation/rotation_list.go => key/key_rotation_list.go} (63%) delete mode 100644 cmd/kms/rotation/rotation.go diff --git a/cmd/kms/crypto/crypto.go b/cmd/kms/crypto/crypto.go new file mode 100644 index 000000000..55275920a --- /dev/null +++ b/cmd/kms/crypto/crypto.go @@ -0,0 +1,15 @@ +package crypto + +import ( + "github.com/exoscale/cli/cmd/kms" + "github.com/spf13/cobra" +) + +var cryptoCmd = &cobra.Command{ + Use: "crypto", + Short: "KMS key cryptographic operations", +} + +func init() { + kms.KMSCmd.AddCommand(cryptoCmd) +} diff --git a/cmd/kms/key/key_decrypt.go b/cmd/kms/crypto/crypto_decrypt.go similarity index 71% rename from cmd/kms/key/key_decrypt.go rename to cmd/kms/crypto/crypto_decrypt.go index dd6607356..d10db3ae1 100644 --- a/cmd/kms/key/key_decrypt.go +++ b/cmd/kms/crypto/crypto_decrypt.go @@ -1,4 +1,4 @@ -package key +package crypto import ( "encoding/base64" @@ -12,13 +12,13 @@ import ( "github.com/spf13/cobra" ) -type keyDecryptOutput struct { +type cryptoDecryptOutput struct { Plaintext string `json:"plaintext"` } -func (o *keyDecryptOutput) ToJSON() { output.JSON(o) } -func (o *keyDecryptOutput) ToText() { output.Text(o) } -func (o *keyDecryptOutput) ToTable() { +func (o *cryptoDecryptOutput) ToJSON() { output.JSON(o) } +func (o *cryptoDecryptOutput) ToText() { output.Text(o) } +func (o *cryptoDecryptOutput) ToTable() { t := table.NewTable(os.Stdout) defer t.Render() @@ -31,7 +31,7 @@ func (o *keyDecryptOutput) ToTable() { }) } -type keyDecryptCmd struct { +type cryptoDecryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"decrypt"` @@ -40,25 +40,25 @@ type keyDecryptCmd struct { Ciphertext string `cli-arg:"#" cli-usage:"CIPHERTEXT"` EncryptionContext string `cli-short:"e" cli-flag:"encryption-context" cli-usage:"encryption context to use for decryption"` - Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` + Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"crypto zone"` } -func (c *keyDecryptCmd) CmdAliases() []string { return nil } +func (c *cryptoDecryptCmd) CmdAliases() []string { return nil } -func (c *keyDecryptCmd) CmdShort() string { +func (c *cryptoDecryptCmd) CmdShort() string { return "Decrypts data using a KMS key." } -func (c *keyDecryptCmd) CmdLong() string { +func (c *cryptoDecryptCmd) CmdLong() string { return "Decrypts data using a KMS key." } -func (c *keyDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *cryptoDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *cryptoDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -81,7 +81,7 @@ func (c *keyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - out := keyDecryptOutput{ + out := cryptoDecryptOutput{ Plaintext: base64.StdEncoding.EncodeToString(resp.Plaintext), } return c.OutputFunc(&out, nil) @@ -91,7 +91,7 @@ func (c *keyDecryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyDecryptCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(cryptoCmd, &cryptoDecryptCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_encrypt.go b/cmd/kms/crypto/crypto_encrypt.go similarity index 71% rename from cmd/kms/key/key_encrypt.go rename to cmd/kms/crypto/crypto_encrypt.go index a42f9edd2..d0f0e01bf 100644 --- a/cmd/kms/key/key_encrypt.go +++ b/cmd/kms/crypto/crypto_encrypt.go @@ -1,4 +1,4 @@ -package key +package crypto import ( "encoding/base64" @@ -12,13 +12,13 @@ import ( "github.com/spf13/cobra" ) -type keyEncryptOutput struct { +type cryptoEncryptOutput struct { Ciphertext string `json:"ciphertext"` } -func (o *keyEncryptOutput) ToJSON() { output.JSON(o) } -func (o *keyEncryptOutput) ToText() { output.Text(o) } -func (o *keyEncryptOutput) ToTable() { +func (o *cryptoEncryptOutput) ToJSON() { output.JSON(o) } +func (o *cryptoEncryptOutput) ToText() { output.Text(o) } +func (o *cryptoEncryptOutput) ToTable() { t := table.NewTable(os.Stdout) defer t.Render() @@ -31,7 +31,7 @@ func (o *keyEncryptOutput) ToTable() { }) } -type keyEncryptCmd struct { +type cryptoEncryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"encrypt"` @@ -43,22 +43,22 @@ type keyEncryptCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyEncryptCmd) CmdAliases() []string { return nil } +func (c *cryptoEncryptCmd) CmdAliases() []string { return nil } -func (c *keyEncryptCmd) CmdShort() string { +func (c *cryptoEncryptCmd) CmdShort() string { return "Encrypts data using a KMS key." } -func (c *keyEncryptCmd) CmdLong() string { +func (c *cryptoEncryptCmd) CmdLong() string { return "Encrypts data using a KMS key." } -func (c *keyEncryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *cryptoEncryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *cryptoEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -77,7 +77,7 @@ func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - out := keyEncryptOutput{ + out := cryptoEncryptOutput{ Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), } return c.OutputFunc(&out, nil) @@ -87,7 +87,7 @@ func (c *keyEncryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyEncryptCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(cryptoCmd, &cryptoEncryptCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_generate_data_key.go b/cmd/kms/crypto/crypto_generate_data_key.go similarity index 74% rename from cmd/kms/key/key_generate_data_key.go rename to cmd/kms/crypto/crypto_generate_data_key.go index 4814ea71a..5225b137d 100644 --- a/cmd/kms/key/key_generate_data_key.go +++ b/cmd/kms/crypto/crypto_generate_data_key.go @@ -1,4 +1,4 @@ -package key +package crypto import ( "encoding/base64" @@ -13,14 +13,14 @@ import ( "github.com/spf13/cobra" ) -type keyGenerateDataKeyOutput struct { +type cryptoGenerateDataKeyOutput struct { Plaintext string `json:"plaintext"` Ciphertext string `json:"ciphertext"` } -func (o *keyGenerateDataKeyOutput) ToJSON() { output.JSON(o) } -func (o *keyGenerateDataKeyOutput) ToText() { output.Text(o) } -func (o *keyGenerateDataKeyOutput) ToTable() { +func (o *cryptoGenerateDataKeyOutput) ToJSON() { output.JSON(o) } +func (o *cryptoGenerateDataKeyOutput) ToText() { output.Text(o) } +func (o *cryptoGenerateDataKeyOutput) ToTable() { t := table.NewTable(os.Stdout) defer t.Render() @@ -35,7 +35,7 @@ func (o *keyGenerateDataKeyOutput) ToTable() { }) } -type keyGenerateDataKeyCmd struct { +type cryptoGenerateDataKeyCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"generate-data-key"` @@ -48,22 +48,22 @@ type keyGenerateDataKeyCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyGenerateDataKeyCmd) CmdAliases() []string { return nil } +func (c *cryptoGenerateDataKeyCmd) CmdAliases() []string { return nil } -func (c *keyGenerateDataKeyCmd) CmdShort() string { +func (c *cryptoGenerateDataKeyCmd) CmdShort() string { return "Generates a data encryption key using a KMS key." } -func (c *keyGenerateDataKeyCmd) CmdLong() string { +func (c *cryptoGenerateDataKeyCmd) CmdLong() string { return "Generates a data encryption key using a KMS key." } -func (c *keyGenerateDataKeyCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *cryptoGenerateDataKeyCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyGenerateDataKeyCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *cryptoGenerateDataKeyCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -93,7 +93,7 @@ func (c *keyGenerateDataKeyCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - out := keyGenerateDataKeyOutput{ + out := cryptoGenerateDataKeyOutput{ Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), Plaintext: base64.StdEncoding.EncodeToString(resp.Plaintext), } @@ -103,7 +103,7 @@ func (c *keyGenerateDataKeyCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyGenerateDataKeyCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(cryptoCmd, &cryptoGenerateDataKeyCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_reencrypt.go b/cmd/kms/crypto/crypto_reencrypt.go similarity index 82% rename from cmd/kms/key/key_reencrypt.go rename to cmd/kms/crypto/crypto_reencrypt.go index 3bbc29481..b62924183 100644 --- a/cmd/kms/key/key_reencrypt.go +++ b/cmd/kms/crypto/crypto_reencrypt.go @@ -1,4 +1,4 @@ -package key +package crypto import ( "encoding/base64" @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -type keyReencryptCmd struct { +type cryptoReencryptCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` _ bool `cli-cmd:"reencrypt"` @@ -23,22 +23,22 @@ type keyReencryptCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyReencryptCmd) CmdAliases() []string { return nil } +func (c *cryptoReencryptCmd) CmdAliases() []string { return nil } -func (c *keyReencryptCmd) CmdShort() string { +func (c *cryptoReencryptCmd) CmdShort() string { return "Re-encrypts data from a KMS key to another KMS key." } -func (c *keyReencryptCmd) CmdLong() string { +func (c *cryptoReencryptCmd) CmdLong() string { return "Re-encrypts data from a KMS key to another KMS key." } -func (c *keyReencryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *cryptoReencryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *cryptoReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -80,7 +80,7 @@ func (c *keyReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - out := keyEncryptOutput{ + out := cryptoEncryptOutput{ Ciphertext: base64.StdEncoding.EncodeToString(resp.Ciphertext), } return c.OutputFunc(&out, nil) @@ -90,7 +90,7 @@ func (c *keyReencryptCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyReencryptCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(cryptoCmd, &cryptoReencryptCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/key/key_cancel_delete.go b/cmd/kms/key/key_cancel_deletion.go similarity index 72% rename from cmd/kms/key/key_cancel_delete.go rename to cmd/kms/key/key_cancel_deletion.go index 111172aa6..3d7cdef5d 100644 --- a/cmd/kms/key/key_cancel_delete.go +++ b/cmd/kms/key/key_cancel_deletion.go @@ -7,32 +7,32 @@ import ( "github.com/spf13/cobra" ) -type keyCancelDeleteCmd struct { +type keyCancelDeletionCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"cancel-delete"` + _ bool `cli-cmd:"cancel-deletion"` Key string `cli-arg:"#" cli-usage:"ID"` Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *keyCancelDeleteCmd) CmdAliases() []string { return nil } +func (c *keyCancelDeletionCmd) CmdAliases() []string { return nil } -func (c *keyCancelDeleteCmd) CmdShort() string { +func (c *keyCancelDeletionCmd) CmdShort() string { return "Cancels the scheduled deletion of a KMS key." } -func (c *keyCancelDeleteCmd) CmdLong() string { +func (c *keyCancelDeletionCmd) CmdLong() string { return "Cancels the scheduled deletion of a KMS key." } -func (c *keyCancelDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyCancelDeletionCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *keyCancelDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyCancelDeletionCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -55,7 +55,7 @@ func (c *keyCancelDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyCancelDeleteCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyCancelDeletionCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/rotation/rotation_disable.go b/cmd/kms/key/key_rotation_disable.go similarity index 63% rename from cmd/kms/rotation/rotation_disable.go rename to cmd/kms/key/key_rotation_disable.go index 9736cbc89..28b4218e5 100644 --- a/cmd/kms/rotation/rotation_disable.go +++ b/cmd/kms/key/key_rotation_disable.go @@ -1,39 +1,38 @@ -package rotation +package key import ( exocmd "github.com/exoscale/cli/cmd" - "github.com/exoscale/cli/cmd/kms/key" "github.com/exoscale/cli/pkg/globalstate" v3 "github.com/exoscale/egoscale/v3" "github.com/spf13/cobra" ) -type rotationDisableCmd struct { +type keyRotationDisableCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"disable"` + _ bool `cli-cmd:"disable-rotation"` Key string `cli-arg:"#" cli-usage:"ID"` Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *rotationDisableCmd) CmdAliases() []string { return nil } +func (c *keyRotationDisableCmd) CmdAliases() []string { return nil } -func (c *rotationDisableCmd) CmdShort() string { +func (c *keyRotationDisableCmd) CmdShort() string { return "Disable KMS key auto rotation." } -func (c *rotationDisableCmd) CmdLong() string { +func (c *keyRotationDisableCmd) CmdLong() string { return "Disable KMS key auto rotation." } -func (c *rotationDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyRotationDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *rotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyRotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -45,7 +44,7 @@ func (c *rotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&key.KeyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) @@ -55,7 +54,7 @@ func (c *rotationDisableCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationDisableCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyRotationDisableCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/rotation/rotation_enable.go b/cmd/kms/key/key_rotation_enable.go similarity index 71% rename from cmd/kms/rotation/rotation_enable.go rename to cmd/kms/key/key_rotation_enable.go index b26f50d95..7bb90f578 100644 --- a/cmd/kms/rotation/rotation_enable.go +++ b/cmd/kms/key/key_rotation_enable.go @@ -1,19 +1,18 @@ -package rotation +package key import ( "strconv" exocmd "github.com/exoscale/cli/cmd" - "github.com/exoscale/cli/cmd/kms/key" "github.com/exoscale/cli/pkg/globalstate" v3 "github.com/exoscale/egoscale/v3" "github.com/spf13/cobra" ) -type rotationEnableCmd struct { +type keyRotationEnableCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"enable"` + _ bool `cli-cmd:"enable-rotation"` Key string `cli-arg:"#" cli-usage:"ID"` @@ -21,22 +20,22 @@ type rotationEnableCmd struct { Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *rotationEnableCmd) CmdAliases() []string { return nil } +func (c *keyRotationEnableCmd) CmdAliases() []string { return nil } -func (c *rotationEnableCmd) CmdShort() string { +func (c *keyRotationEnableCmd) CmdShort() string { return "Enable KMS key auto rotation." } -func (c *rotationEnableCmd) CmdLong() string { +func (c *keyRotationEnableCmd) CmdLong() string { return "Enable KMS key auto rotation." } -func (c *rotationEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyRotationEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *rotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyRotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) if err != nil { @@ -59,7 +58,7 @@ func (c *rotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { } if !globalstate.Quiet { - return (&key.KeyShowCmd{ + return (&KeyShowCmd{ CliCommandSettings: c.CliCommandSettings, Key: c.Key, }).CmdRun(nil, nil) @@ -69,7 +68,7 @@ func (c *rotationEnableCmd) CmdRun(_ *cobra.Command, _ []string) error { } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationEnableCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyRotationEnableCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/rotation/rotation_list.go b/cmd/kms/key/key_rotation_list.go similarity index 63% rename from cmd/kms/rotation/rotation_list.go rename to cmd/kms/key/key_rotation_list.go index acd7f9969..e95bf3890 100644 --- a/cmd/kms/rotation/rotation_list.go +++ b/cmd/kms/key/key_rotation_list.go @@ -1,4 +1,4 @@ -package rotation +package key import ( "os" @@ -12,13 +12,13 @@ import ( "github.com/spf13/cobra" ) -type rotationListOutput struct { +type keyRotationListOutput struct { v3.ListKmsKeyRotationsResponse } -func (o *rotationListOutput) ToJSON() { output.JSON(o) } -func (o *rotationListOutput) ToText() { output.Text(o) } -func (o *rotationListOutput) ToTable() { +func (o *keyRotationListOutput) ToJSON() { output.JSON(o) } +func (o *keyRotationListOutput) ToText() { output.Text(o) } +func (o *keyRotationListOutput) ToTable() { t := table.NewTable(os.Stdout) defer t.Render() @@ -37,32 +37,32 @@ func (o *rotationListOutput) ToTable() { } } -type rotationListCmd struct { +type keyRotationListCmd struct { exocmd.CliCommandSettings `cli-cmd:"-"` - _ bool `cli-cmd:"list"` + _ bool `cli-cmd:"list-rotation"` Key string `cli-arg:"#" cli-usage:"ID"` Zone v3.ZoneName `cli-short:"z" cli-flag:"zone" cli-usage:"key zone"` } -func (c *rotationListCmd) CmdAliases() []string { return exocmd.GListAlias } +func (c *keyRotationListCmd) CmdAliases() []string { return exocmd.GListAlias } -func (c *rotationListCmd) CmdShort() string { +func (c *keyRotationListCmd) CmdShort() string { return "List KMS key rotations." } -func (c *rotationListCmd) CmdLong() string { +func (c *keyRotationListCmd) CmdLong() string { return "List KMS key rotations." } -func (c *rotationListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { +func (c *keyRotationListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { exocmd.CmdSetZoneFlagFromDefault(cmd) return exocmd.CliCommandDefaultPreRun(c, cmd, args) } -func (c *rotationListCmd) CmdRun(_ *cobra.Command, _ []string) error { +func (c *keyRotationListCmd) CmdRun(_ *cobra.Command, _ []string) error { ctx := exocmd.GContext client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) @@ -74,13 +74,13 @@ func (c *rotationListCmd) CmdRun(_ *cobra.Command, _ []string) error { if err != nil { return err } - out := rotationListOutput{*resp} + out := keyRotationListOutput{*resp} return c.OutputFunc(&out, nil) } func init() { - cobra.CheckErr(exocmd.RegisterCLICommand(rotationCmd, &rotationListCmd{ + cobra.CheckErr(exocmd.RegisterCLICommand(keyCmd, &keyRotationListCmd{ CliCommandSettings: exocmd.DefaultCLICmdSettings(), })) } diff --git a/cmd/kms/rotation/rotation.go b/cmd/kms/rotation/rotation.go deleted file mode 100644 index 368e546ea..000000000 --- a/cmd/kms/rotation/rotation.go +++ /dev/null @@ -1,15 +0,0 @@ -package rotation - -import ( - "github.com/exoscale/cli/cmd/kms" - "github.com/spf13/cobra" -) - -var rotationCmd = &cobra.Command{ - Use: "rotation", - Short: "KMS key rotation", -} - -func init() { - kms.KMSCmd.AddCommand(rotationCmd) -} diff --git a/cmd/subcommands/init.go b/cmd/subcommands/init.go index d1e3921ba..d54545275 100644 --- a/cmd/subcommands/init.go +++ b/cmd/subcommands/init.go @@ -27,7 +27,7 @@ import ( _ "github.com/exoscale/cli/cmd/dns" _ "github.com/exoscale/cli/cmd/iam" _ "github.com/exoscale/cli/cmd/kms" + _ "github.com/exoscale/cli/cmd/kms/crypto" _ "github.com/exoscale/cli/cmd/kms/key" - _ "github.com/exoscale/cli/cmd/kms/rotation" _ "github.com/exoscale/cli/cmd/storage" ) From 038fb69094053248e748d98357978d2462b1951b Mon Sep 17 00:00:00 2001 From: Leo Loch Date: Fri, 29 May 2026 17:24:22 +0200 Subject: [PATCH 24/24] same description for commands as api doc --- cmd/kms/crypto/crypto_decrypt.go | 4 ++-- cmd/kms/crypto/crypto_encrypt.go | 4 ++-- cmd/kms/crypto/crypto_generate_data_key.go | 4 ++-- cmd/kms/crypto/crypto_reencrypt.go | 4 ++-- cmd/kms/key/key_cancel_deletion.go | 4 ++-- cmd/kms/key/key_create.go | 4 ++-- cmd/kms/key/key_disable.go | 4 ++-- cmd/kms/key/key_enable.go | 4 ++-- cmd/kms/key/key_list.go | 4 ++-- cmd/kms/key/key_replicate.go | 4 ++-- cmd/kms/key/key_rotate.go | 4 ++-- cmd/kms/key/key_rotation_disable.go | 4 ++-- cmd/kms/key/key_rotation_enable.go | 4 ++-- cmd/kms/key/key_rotation_list.go | 4 ++-- cmd/kms/key/key_schedule_deletion.go | 4 ++-- cmd/kms/key/key_show.go | 4 ++-- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cmd/kms/crypto/crypto_decrypt.go b/cmd/kms/crypto/crypto_decrypt.go index d10db3ae1..90f7f44f2 100644 --- a/cmd/kms/crypto/crypto_decrypt.go +++ b/cmd/kms/crypto/crypto_decrypt.go @@ -46,11 +46,11 @@ type cryptoDecryptCmd struct { func (c *cryptoDecryptCmd) CmdAliases() []string { return nil } func (c *cryptoDecryptCmd) CmdShort() string { - return "Decrypts data using a KMS key." + return "Decrypt a ciphertext." } func (c *cryptoDecryptCmd) CmdLong() string { - return "Decrypts data using a KMS key." + return "Decrypt a ciphertext." } func (c *cryptoDecryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/crypto/crypto_encrypt.go b/cmd/kms/crypto/crypto_encrypt.go index d0f0e01bf..6e2493fd9 100644 --- a/cmd/kms/crypto/crypto_encrypt.go +++ b/cmd/kms/crypto/crypto_encrypt.go @@ -46,11 +46,11 @@ type cryptoEncryptCmd struct { func (c *cryptoEncryptCmd) CmdAliases() []string { return nil } func (c *cryptoEncryptCmd) CmdShort() string { - return "Encrypts data using a KMS key." + return "Encrypt a plaintext." } func (c *cryptoEncryptCmd) CmdLong() string { - return "Encrypts data using a KMS key." + return "Encrypt a plaintext." } func (c *cryptoEncryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/crypto/crypto_generate_data_key.go b/cmd/kms/crypto/crypto_generate_data_key.go index 5225b137d..5f5150867 100644 --- a/cmd/kms/crypto/crypto_generate_data_key.go +++ b/cmd/kms/crypto/crypto_generate_data_key.go @@ -51,11 +51,11 @@ type cryptoGenerateDataKeyCmd struct { func (c *cryptoGenerateDataKeyCmd) CmdAliases() []string { return nil } func (c *cryptoGenerateDataKeyCmd) CmdShort() string { - return "Generates a data encryption key using a KMS key." + return "Generate a Data Encryption Key from a given KMS Key." } func (c *cryptoGenerateDataKeyCmd) CmdLong() string { - return "Generates a data encryption key using a KMS key." + return "Generate a Data Encryption Key from a given KMS Key." } func (c *cryptoGenerateDataKeyCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/crypto/crypto_reencrypt.go b/cmd/kms/crypto/crypto_reencrypt.go index b62924183..7df7e2ad2 100644 --- a/cmd/kms/crypto/crypto_reencrypt.go +++ b/cmd/kms/crypto/crypto_reencrypt.go @@ -26,11 +26,11 @@ type cryptoReencryptCmd struct { func (c *cryptoReencryptCmd) CmdAliases() []string { return nil } func (c *cryptoReencryptCmd) CmdShort() string { - return "Re-encrypts data from a KMS key to another KMS key." + return "Decrypts and encrypts an exisiting ciphertext with newest key material or a different KMS key." } func (c *cryptoReencryptCmd) CmdLong() string { - return "Re-encrypts data from a KMS key to another KMS key." + return "Decrypts an existing ciphertext using its original key material and re-encrypts the underlying plaintext using a specified KMS key or the latest key material of the same KMS Key." } func (c *cryptoReencryptCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_cancel_deletion.go b/cmd/kms/key/key_cancel_deletion.go index 3d7cdef5d..3e512f1a7 100644 --- a/cmd/kms/key/key_cancel_deletion.go +++ b/cmd/kms/key/key_cancel_deletion.go @@ -20,11 +20,11 @@ type keyCancelDeletionCmd struct { func (c *keyCancelDeletionCmd) CmdAliases() []string { return nil } func (c *keyCancelDeletionCmd) CmdShort() string { - return "Cancels the scheduled deletion of a KMS key." + return "Cancel the scheduled deletion of a KMS Key." } func (c *keyCancelDeletionCmd) CmdLong() string { - return "Cancels the scheduled deletion of a KMS key." + return "Cancel the scheduled deletion of a KMS Key." } func (c *keyCancelDeletionCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_create.go b/cmd/kms/key/key_create.go index bf81c88d9..83f91f984 100644 --- a/cmd/kms/key/key_create.go +++ b/cmd/kms/key/key_create.go @@ -23,11 +23,11 @@ type keyCreateCmd struct { func (c *keyCreateCmd) CmdAliases() []string { return nil } func (c *keyCreateCmd) CmdShort() string { - return "Creates a new KMS key." + return "Create a KMS Key in a given zone with a given name." } func (c *keyCreateCmd) CmdLong() string { - return "Creates a new KMS key." + return "Create a KMS Key in a given zone with a given name." } func (c *keyCreateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_disable.go b/cmd/kms/key/key_disable.go index 059dfbf29..edce33b55 100644 --- a/cmd/kms/key/key_disable.go +++ b/cmd/kms/key/key_disable.go @@ -20,11 +20,11 @@ type keyDisableCmd struct { func (c *keyDisableCmd) CmdAliases() []string { return nil } func (c *keyDisableCmd) CmdShort() string { - return "Enables a KMS key." + return "Disables a KMS Key." } func (c *keyDisableCmd) CmdLong() string { - return "Enables a KMS key." + return "Disables a KMS Key." } func (c *keyDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_enable.go b/cmd/kms/key/key_enable.go index 7a4ad5065..9d4fed4e8 100644 --- a/cmd/kms/key/key_enable.go +++ b/cmd/kms/key/key_enable.go @@ -20,11 +20,11 @@ type keyEnableCmd struct { func (c *keyEnableCmd) CmdAliases() []string { return nil } func (c *keyEnableCmd) CmdShort() string { - return "Enables a KMS key." + return "Enables a KMS Key." } func (c *keyEnableCmd) CmdLong() string { - return "Enables a KMS key." + return "Enables a KMS Key." } func (c *keyEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_list.go b/cmd/kms/key/key_list.go index a648896e3..2b92c35de 100644 --- a/cmd/kms/key/key_list.go +++ b/cmd/kms/key/key_list.go @@ -57,11 +57,11 @@ type keyListCmd struct { func (c *keyListCmd) CmdAliases() []string { return exocmd.GListAlias } func (c *keyListCmd) CmdShort() string { - return "List KMS keys." + return "List KMS Keys details for an organization in a given zone." } func (c *keyListCmd) CmdLong() string { - return "List KMS keys." + return "List KMS Keys details for an organization in a given zone." } func (c *keyListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_replicate.go b/cmd/kms/key/key_replicate.go index 54894817f..79e8e4e19 100644 --- a/cmd/kms/key/key_replicate.go +++ b/cmd/kms/key/key_replicate.go @@ -21,11 +21,11 @@ type keyReplicateCmd struct { func (c *keyReplicateCmd) CmdAliases() []string { return nil } func (c *keyReplicateCmd) CmdShort() string { - return "Replicate a KMS key to another zone." + return "Replicate a KMS key to a target zone." } func (c *keyReplicateCmd) CmdLong() string { - return "Replicate a KMS key to another zone." + return "Replicate a KMS key to a target zone." } func (c *keyReplicateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_rotate.go b/cmd/kms/key/key_rotate.go index ad3c80034..509bcb0ea 100644 --- a/cmd/kms/key/key_rotate.go +++ b/cmd/kms/key/key_rotate.go @@ -20,11 +20,11 @@ type keyRotateCmd struct { func (c *keyRotateCmd) CmdAliases() []string { return nil } func (c *keyRotateCmd) CmdShort() string { - return "Rotates a KMS key." + return "Perform a manual rotation of the key material for a symmetric key." } func (c *keyRotateCmd) CmdLong() string { - return "Rotates a KMS key." + return "Perform a manual rotation of the key material for a symmetric key." } func (c *keyRotateCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_rotation_disable.go b/cmd/kms/key/key_rotation_disable.go index 28b4218e5..8166bb4c0 100644 --- a/cmd/kms/key/key_rotation_disable.go +++ b/cmd/kms/key/key_rotation_disable.go @@ -20,11 +20,11 @@ type keyRotationDisableCmd struct { func (c *keyRotationDisableCmd) CmdAliases() []string { return nil } func (c *keyRotationDisableCmd) CmdShort() string { - return "Disable KMS key auto rotation." + return "Disable the periodic rotation of a KMS Key." } func (c *keyRotationDisableCmd) CmdLong() string { - return "Disable KMS key auto rotation." + return "Disable the periodic rotation of a KMS Key." } func (c *keyRotationDisableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_rotation_enable.go b/cmd/kms/key/key_rotation_enable.go index 7bb90f578..ca67840d2 100644 --- a/cmd/kms/key/key_rotation_enable.go +++ b/cmd/kms/key/key_rotation_enable.go @@ -23,11 +23,11 @@ type keyRotationEnableCmd struct { func (c *keyRotationEnableCmd) CmdAliases() []string { return nil } func (c *keyRotationEnableCmd) CmdShort() string { - return "Enable KMS key auto rotation." + return "Enable the periodic rotation of a KMS Key." } func (c *keyRotationEnableCmd) CmdLong() string { - return "Enable KMS key auto rotation." + return "Enable the periodic rotation of a KMS Key." } func (c *keyRotationEnableCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_rotation_list.go b/cmd/kms/key/key_rotation_list.go index e95bf3890..94621b5ad 100644 --- a/cmd/kms/key/key_rotation_list.go +++ b/cmd/kms/key/key_rotation_list.go @@ -50,11 +50,11 @@ type keyRotationListCmd struct { func (c *keyRotationListCmd) CmdAliases() []string { return exocmd.GListAlias } func (c *keyRotationListCmd) CmdShort() string { - return "List KMS key rotations." + return "List all the key material versions of a KMS Key." } func (c *keyRotationListCmd) CmdLong() string { - return "List KMS key rotations." + return "List all the key material versions of a KMS Key." } func (c *keyRotationListCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_schedule_deletion.go b/cmd/kms/key/key_schedule_deletion.go index ff115610c..4256fdedf 100644 --- a/cmd/kms/key/key_schedule_deletion.go +++ b/cmd/kms/key/key_schedule_deletion.go @@ -24,11 +24,11 @@ type keyScheduleDeletionCmd struct { func (c *keyScheduleDeletionCmd) CmdAliases() []string { return nil } func (c *keyScheduleDeletionCmd) CmdShort() string { - return "Schedules deletion of a KMS key." + return "Schedule a KMS key for deletion after a delay." } func (c *keyScheduleDeletionCmd) CmdLong() string { - return "Schedules deletion of a KMS key." + return "Schedule a KMS key for deletion after a delay." } func (c *keyScheduleDeletionCmd) CmdPreRun(cmd *cobra.Command, args []string) error { diff --git a/cmd/kms/key/key_show.go b/cmd/kms/key/key_show.go index 28cac50f8..4755321e8 100644 --- a/cmd/kms/key/key_show.go +++ b/cmd/kms/key/key_show.go @@ -43,11 +43,11 @@ type KeyShowCmd struct { func (c *KeyShowCmd) CmdAliases() []string { return exocmd.GShowAlias } func (c *KeyShowCmd) CmdShort() string { - return "Shows details of a KMS key." + return "Retrieve KMS Key details." } func (c *KeyShowCmd) CmdLong() string { - return "Shows details of a KMS key." + return "Retrieve KMS Key details." } func (c *KeyShowCmd) CmdPreRun(cmd *cobra.Command, args []string) error {