From a94f6e2711b2df4ef5517ea5ae87889ff9a11e42 Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Thu, 6 Feb 2025 19:25:42 +0300 Subject: [PATCH] [#1614] adm/frostfsid: Add 'delete-kv' Signed-off-by: Alexander Chuprov --- .../modules/morph/frostfsid/frostfsid.go | 45 +++++++++++++++++++ .../internal/modules/morph/frostfsid/root.go | 1 + 2 files changed, 46 insertions(+) diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go index 3eaff0f6c..fda66d9e8 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go @@ -167,6 +167,14 @@ var ( }, Run: frostfsidSetKV, } + frostfsidDeleteKVCmd = &cobra.Command{ + Use: "delete-kv", + Short: "Delete a value from the subject's KV storage", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag)) + }, + Run: frostfsidDeleteKV, + } ) func initFrostfsIDCreateNamespaceCmd() { @@ -271,6 +279,24 @@ func initFrostfsIDSetKVCmd() { }) } +func initFrostfsIDDeleteKVCmd() { + Cmd.AddCommand(frostfsidDeleteKVCmd) + frostfsidDeleteKVCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc) + frostfsidDeleteKVCmd.Flags().String(subjectAddressFlag, "", "Subject address") + frostfsidDeleteKVCmd.Flags().String(keyFlag, "", keyDescFlag) + + frostfsidDeleteKVCmd.ValidArgsFunction = commonflags.AutoCompleteFlags + + _ = frostfsidDeleteKVCmd.RegisterFlagCompletionFunc(keyFlag, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + flags := make([]string, 0, len(wellKnownFlags)) + for k := range wellKnownFlags { + flags = append(flags, k) + } + + return flags, cobra.ShellCompDirectiveDefault + }) +} + func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) { ns := getFrostfsIDNamespace(cmd) @@ -469,6 +495,25 @@ func frostfsidSetKV(cmd *cobra.Command, _ []string) { commonCmd.ExitOnErr(cmd, "failed to set: %w", err) } +func frostfsidDeleteKV(cmd *cobra.Command, _ []string) { + subjectAddress := getFrostfsIDSubjectAddress(cmd) + key, _ := cmd.Flags().GetString(keyFlag) + + if key == "" { + commonCmd.ExitOnErr(cmd, "", errors.New("key can't be empty")) + } + + ffsid, err := newFrostfsIDClient(cmd) + commonCmd.ExitOnErr(cmd, "init contract client: %w", err) + + method, args := ffsid.roCli.DeleteSubjectKVCall(subjectAddress, key) + + ffsid.addCall(method, args) + + err = ffsid.sendWait() + commonCmd.ExitOnErr(cmd, "failed to delete: %w", err) +} + func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) { ns := getFrostfsIDNamespace(cmd) groupID := getFrostfsIDGroupID(cmd) diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go index 930865f81..8aad5c5c1 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go @@ -13,6 +13,7 @@ func init() { initFrostfsIDRemoveSubjectFromGroupCmd() initFrostfsIDListGroupSubjectsCmd() initFrostfsIDSetKVCmd() + initFrostfsIDDeleteKVCmd() initFrostfsIDAddSubjectKeyCmd() initFrostfsIDRemoveSubjectKeyCmd() }