[#1614] adm/frostfsid: Add 'set-kv'
All checks were successful
DCO action / DCO (pull_request) Successful in 40s
Vulncheck / Vulncheck (pull_request) Successful in 56s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m28s
Build / Build Components (pull_request) Successful in 1m26s
Tests and linters / gopls check (pull_request) Successful in 2m24s
Tests and linters / Run gofumpt (pull_request) Successful in 2m40s
Tests and linters / Tests (pull_request) Successful in 2m57s
Tests and linters / Staticcheck (pull_request) Successful in 3m4s
Tests and linters / Lint (pull_request) Successful in 3m14s
Tests and linters / Tests with -race (pull_request) Successful in 4m22s
All checks were successful
DCO action / DCO (pull_request) Successful in 40s
Vulncheck / Vulncheck (pull_request) Successful in 56s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m28s
Build / Build Components (pull_request) Successful in 1m26s
Tests and linters / gopls check (pull_request) Successful in 2m24s
Tests and linters / Run gofumpt (pull_request) Successful in 2m40s
Tests and linters / Tests (pull_request) Successful in 2m57s
Tests and linters / Staticcheck (pull_request) Successful in 3m4s
Tests and linters / Lint (pull_request) Successful in 3m14s
Tests and linters / Tests with -race (pull_request) Successful in 4m22s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
4de5fca547
commit
dbc2495589
2 changed files with 71 additions and 0 deletions
|
@ -1,11 +1,13 @@
|
||||||
package frostfsid
|
package frostfsid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
frostfsidrpclient "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/frostfsid"
|
frostfsidrpclient "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/frostfsid"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
@ -38,6 +40,13 @@ const (
|
||||||
groupIDFlag = "group-id"
|
groupIDFlag = "group-id"
|
||||||
|
|
||||||
rootNamespacePlaceholder = "<root>"
|
rootNamespacePlaceholder = "<root>"
|
||||||
|
|
||||||
|
disableFlag = "disable"
|
||||||
|
disableDescFlag = "Remove the specified key from the subject's KV storage"
|
||||||
|
keyFlag = "key"
|
||||||
|
keyDescFlag = "Key for storing a value in the subject's KV storage"
|
||||||
|
valueFlag = "value"
|
||||||
|
valueDescFlag = "Key for storing a value in the subject's KV storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -151,6 +160,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 +254,18 @@ 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)
|
||||||
|
frostfsidSetKVCmd.Flags().Bool(disableFlag, false, disableDescFlag)
|
||||||
|
for k, v := range wellKnownFlags {
|
||||||
|
frostfsidSetKVCmd.Flags().Bool(k, false, v.description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
||||||
ns := getFrostfsIDNamespace(cmd)
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
|
||||||
|
@ -403,6 +433,46 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wellKnownFlagDescription struct {
|
||||||
|
description string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
var wellKnownFlags = map[string]wellKnownFlagDescription{
|
||||||
|
nns.FrostfsIDNNSTLDPermissionKey: {"Allow subject to create TLD domains", nns.FrostfsIDTLDRegistrationAllowed},
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidSetKV(cmd *cobra.Command, _ []string) {
|
||||||
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
||||||
|
key, _ := cmd.Flags().GetString(keyFlag)
|
||||||
|
value, _ := cmd.Flags().GetString(valueFlag)
|
||||||
|
|
||||||
|
for wellKnownKey, flagInfo := range wellKnownFlags {
|
||||||
|
if ok, _ := cmd.Flags().GetBool(wellKnownKey); ok {
|
||||||
|
key = wellKnownKey
|
||||||
|
value = flagInfo.value
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
if ok, _ := cmd.Flags().GetBool(disableFlag); ok {
|
||||||
|
method, args = ffsid.roCli.DeleteSubjectKVCall(subjectAddress, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
ffsid.addCall(method, args)
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "failed to perform operation: %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