forked from TrueCloudLab/frostfs-node
[#1614] adm/frostfsid: Add 'set-kv'
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
5d79abe523
commit
a7145ca9bf
2 changed files with 44 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package frostfsid
|
package frostfsid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -38,6 +39,11 @@ const (
|
||||||
groupIDFlag = "group-id"
|
groupIDFlag = "group-id"
|
||||||
|
|
||||||
rootNamespacePlaceholder = "<root>"
|
rootNamespacePlaceholder = "<root>"
|
||||||
|
|
||||||
|
keyFlag = "key"
|
||||||
|
keyDescFlag = "Key for storing a value in the subject's KV storage"
|
||||||
|
valueFlag = "value"
|
||||||
|
valueDescFlag = "Value to be stored in the subject's KV storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -151,6 +157,15 @@ var (
|
||||||
},
|
},
|
||||||
Run: frostfsidListGroupSubjects,
|
Run: frostfsidListGroupSubjects,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frostfsidSetKVCmd = &cobra.Command{
|
||||||
|
Use: "set-kv",
|
||||||
|
Short: "Store a key-value pair in the subject's KV storage",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidSetKV,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func initFrostfsIDCreateNamespaceCmd() {
|
func initFrostfsIDCreateNamespaceCmd() {
|
||||||
|
@ -236,6 +251,14 @@ func initFrostfsIDListGroupSubjectsCmd() {
|
||||||
frostfsidListGroupSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
frostfsidListGroupSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDSetKVCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidSetKVCmd)
|
||||||
|
frostfsidSetKVCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidSetKVCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
||||||
|
frostfsidSetKVCmd.Flags().String(keyFlag, "", keyDescFlag)
|
||||||
|
frostfsidSetKVCmd.Flags().String(valueFlag, "", valueDescFlag)
|
||||||
|
}
|
||||||
|
|
||||||
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
||||||
ns := getFrostfsIDNamespace(cmd)
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
|
||||||
|
@ -403,6 +426,26 @@ func frostfsidRemoveSubjectFromGroup(cmd *cobra.Command, _ []string) {
|
||||||
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
|
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func frostfsidSetKV(cmd *cobra.Command, _ []string) {
|
||||||
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
||||||
|
key, _ := cmd.Flags().GetString(keyFlag)
|
||||||
|
value, _ := cmd.Flags().GetString(valueFlag)
|
||||||
|
|
||||||
|
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.SetSubjectKVCall(subjectAddress, key, value)
|
||||||
|
|
||||||
|
ffsid.addCall(method, args)
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "set KV: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
||||||
ns := getFrostfsIDNamespace(cmd)
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
groupID := getFrostfsIDGroupID(cmd)
|
groupID := getFrostfsIDGroupID(cmd)
|
||||||
|
|
|
@ -12,6 +12,7 @@ func init() {
|
||||||
initFrostfsIDAddSubjectToGroupCmd()
|
initFrostfsIDAddSubjectToGroupCmd()
|
||||||
initFrostfsIDRemoveSubjectFromGroupCmd()
|
initFrostfsIDRemoveSubjectFromGroupCmd()
|
||||||
initFrostfsIDListGroupSubjectsCmd()
|
initFrostfsIDListGroupSubjectsCmd()
|
||||||
|
initFrostfsIDSetKVCmd()
|
||||||
initFrostfsIDAddSubjectKeyCmd()
|
initFrostfsIDAddSubjectKeyCmd()
|
||||||
initFrostfsIDRemoveSubjectKeyCmd()
|
initFrostfsIDRemoveSubjectKeyCmd()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue