|
| 1 | +package flink |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/spf13/cobra" |
| 5 | + |
| 6 | + pcmd "github.com/confluentinc/cli/v4/pkg/cmd" |
| 7 | + "github.com/confluentinc/cli/v4/pkg/deletion" |
| 8 | + "github.com/confluentinc/cli/v4/pkg/errors" |
| 9 | + "github.com/confluentinc/cli/v4/pkg/resource" |
| 10 | +) |
| 11 | + |
| 12 | +func (c *command) newSecretMappingDeleteCommand() *cobra.Command { |
| 13 | + cmd := &cobra.Command{ |
| 14 | + Use: "delete <name-1> [name-2] ... [name-n]", |
| 15 | + Short: "Delete one or more Flink secret mappings.", |
| 16 | + Long: "Delete one or more Flink environment secret mappings in Confluent Platform.", |
| 17 | + Args: cobra.MinimumNArgs(1), |
| 18 | + RunE: c.secretMappingDelete, |
| 19 | + } |
| 20 | + |
| 21 | + cmd.Flags().String("environment", "", "Name of the Flink environment.") |
| 22 | + cobra.CheckErr(cmd.MarkFlagRequired("environment")) |
| 23 | + addCmfFlagSet(cmd) |
| 24 | + pcmd.AddForceFlag(cmd) |
| 25 | + |
| 26 | + return cmd |
| 27 | +} |
| 28 | + |
| 29 | +func (c *command) secretMappingDelete(cmd *cobra.Command, args []string) error { |
| 30 | + environment, err := cmd.Flags().GetString("environment") |
| 31 | + if err != nil { |
| 32 | + return err |
| 33 | + } |
| 34 | + |
| 35 | + client, err := c.GetCmfClient(cmd) |
| 36 | + if err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + |
| 40 | + existenceFunc := func(name string) bool { |
| 41 | + _, err := client.DescribeSecretMapping(c.createContext(), environment, name) |
| 42 | + return err == nil |
| 43 | + } |
| 44 | + |
| 45 | + if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, resource.FlinkSecretMapping); err != nil { |
| 46 | + suggestions := "List available Flink secret mappings with `confluent flink secret-mapping list --environment <envName>`." |
| 47 | + suggestions += "\nCheck that CMF is running and accessible." |
| 48 | + return errors.NewErrorWithSuggestions(err.Error(), suggestions) |
| 49 | + } |
| 50 | + |
| 51 | + deleteFunc := func(name string) error { |
| 52 | + return client.DeleteSecretMapping(c.createContext(), environment, name) |
| 53 | + } |
| 54 | + |
| 55 | + _, err = deletion.Delete(cmd, args, deleteFunc, resource.FlinkSecretMapping) |
| 56 | + return err |
| 57 | +} |
0 commit comments