adm/frostfsid: Add 'set-kv' #1634

Merged
dstepanov-yadro merged 2 commits from achuprov/frostfs-node:feat/frostfs_adm_add_set-kv into master 2025-02-10 16:27:51 +00:00
Member

Add:

 frostfs-adm morph frostfsid set-kv --help
Store a key-value pair in the subject's KV storage

Usage:
  frostfs-adm morph frostfsid set-kv [flags]

Flags:
  -h, --help                     help for set-kv
      --key string               Key for storing a value in the subject's KV storage
      --nns-allow-register-tld   Allow subject to create TLD domains
  -r, --rpc-endpoint string      N3 RPC node endpoint
      --subject-address string   Subject address
      --value string             Key for storing a value in the subject's KV storage

Global Flags:
  -c, --config string       Config file
      --config-dir string   Config directory
  -v, --verbose             Verbose output
 frostfs-adm morph frostfsid delete-kv --help
Delete a value from the subject's KV storage

Usage:
frostfs-adm morph frostfsid delete-kv [flags]

Flags:
-h, --help                     help for delete-kv
    --key string               Key for storing a value in the subject's KV storage
-r, --rpc-endpoint string      N3 RPC node endpoint
    --subject-address string   Subject address

Global Flags:
-c, --config string       Config file
    --config-dir string   Config directory
-v, --verbose             Verbose output

Signed-off-by: Alexander Chuprov a.chuprov@yadro.com

Add: ``` frostfs-adm morph frostfsid set-kv --help Store a key-value pair in the subject's KV storage Usage: frostfs-adm morph frostfsid set-kv [flags] Flags: -h, --help help for set-kv --key string Key for storing a value in the subject's KV storage --nns-allow-register-tld Allow subject to create TLD domains -r, --rpc-endpoint string N3 RPC node endpoint --subject-address string Subject address --value string Key for storing a value in the subject's KV storage Global Flags: -c, --config string Config file --config-dir string Config directory -v, --verbose Verbose output ``` ``` frostfs-adm morph frostfsid delete-kv --help Delete a value from the subject's KV storage Usage: frostfs-adm morph frostfsid delete-kv [flags] Flags: -h, --help help for delete-kv --key string Key for storing a value in the subject's KV storage -r, --rpc-endpoint string N3 RPC node endpoint --subject-address string Subject address Global Flags: -c, --config string Config file --config-dir string Config directory -v, --verbose Verbose output ``` Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
achuprov added 1 commit 2025-02-04 13:07:54 +00:00
[#1614] adm/frostfsid: Add 'set-kv'
All checks were successful
DCO action / DCO (pull_request) Successful in 41s
Vulncheck / Vulncheck (pull_request) Successful in 59s
Build / Build Components (pull_request) Successful in 2m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m0s
Tests and linters / gopls check (pull_request) Successful in 2m42s
Tests and linters / Run gofumpt (pull_request) Successful in 2m42s
Tests and linters / Staticcheck (pull_request) Successful in 3m21s
Tests and linters / Tests (pull_request) Successful in 3m24s
Tests and linters / Lint (pull_request) Successful in 3m26s
Tests and linters / Tests with -race (pull_request) Successful in 4m11s
626a7ae344
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
requested reviews from storage-core-committers, storage-core-developers 2025-02-04 13:07:54 +00:00
aarifullin reviewed 2025-02-04 15:13:36 +00:00
@ -403,6 +433,48 @@ func frostfsidRemoveSubjectFromGroup(cmd *cobra.Command, _ []string) {
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
}
const disable = "disable"
Member

You don't need to introduce the constant. You've already got disableFlag. So, feel free to use it in cmd.Flags().GetBool(disable) :)

You don't need to introduce the constant. You've already got `disableFlag`. So, feel free to use it in `cmd.Flags().GetBool(disable)` :)
Author
Member

Thanks, fixed

Thanks, fixed
aarifullin marked this conversation as resolved
aarifullin reviewed 2025-02-04 15:27:14 +00:00
@ -406,0 +465,4 @@
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
method, args := ffsid.roCli.SetSubjectKVCall(subjectAddress, key, value)
if ok, _ := cmd.Flags().GetBool(disable); ok {
Member

I can't figure out what is going on in this part. Why do you set a key to subject's KV storage and then remove it if disable flag is set? I checked the contract's method and deleteSubjectKV literally means deletion but not disabling.
So, we need to make frostfsidSetKV free from deletion and introduce frostfsidDeleteKV and not use disable.
frostfsidSetKV is responsible for setting but not "disabling" (when it deletes in fact) :)

I can't figure out what is going on in this part. Why do you set a key to subject's KV storage and then remove it if `disable` flag is set? I checked the contract's method and `deleteSubjectKV` literally means deletion but not disabling. So, we need to make `frostfsidSetKV` free from deletion and introduce `frostfsidDeleteKV` and not use `disable`. `frostfsidSetKV` is responsible for setting but not "disabling" (when it deletes in fact) :)
Author
Member

IMHO, by default, the FrostFS ID KV storage does not contain any options. When we add a key, these options are enabled. This means that deleting an option disables it.

IMHO, by default, the `FrostFS ID KV` storage does not contain any options. When we add a key, these options are enabled. This means that deleting an option disables it.
Owner

There are no "options" that are enabled or disabled, there are keys and values, which (according to contract) we can set and delete.

There are no "options" that are enabled or disabled, there are keys and values, which (according to contract) we can `set` and `delete`.
achuprov force-pushed feat/frostfs_adm_add_set-kv from 626a7ae344 to dbc2495589 2025-02-05 11:02:04 +00:00 Compare
fyrchik reviewed 2025-02-05 11:13:26 +00:00
@ -406,0 +447,4 @@
key, _ := cmd.Flags().GetString(keyFlag)
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, flagInfo := range wellKnownFlags {
Owner

Please, let's have 2 separate commands: set-kv and delete-kv.
The --disable flag has a wrong name and this for loop should not be executed if we want to delete kv.

Please, let's have 2 separate commands: `set-kv` and `delete-kv`. The `--disable` flag has a wrong name and this `for` loop should not be executed if we want to delete kv.
Author
Member

done

done
fyrchik reviewed 2025-02-05 11:15:29 +00:00
@ -406,0 +448,4 @@
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, flagInfo := range wellKnownFlags {
if ok, _ := cmd.Flags().GetBool(wellKnownKey); ok {
Owner

This logic should be reverted: we have key and we should check whether it is well-known.
You iterate over all well-known keys and check whether a key is present.
Another problem is that you silently ignore previous key value, the flags should be marked as mutually exclusive.

This logic should be reverted: we _have_ key and we should check whether it is well-known. You iterate over all well-known keys and check whether a key is present. Another problem is that you silently ignore previous key value, the flags should be marked as mutually exclusive.
Author
Member

fixed

fixed
achuprov marked this conversation as resolved
fyrchik changed title from adm/frostfsid: Add 'set-kv' to WIP: adm/frostfsid: Add 'set-kv' 2025-02-06 08:31:22 +00:00
achuprov force-pushed feat/frostfs_adm_add_set-kv from dbc2495589 to a94f6e2711 2025-02-06 16:40:11 +00:00 Compare
achuprov reviewed 2025-02-06 16:45:18 +00:00
@ -0,0 +7,4 @@
"github.com/spf13/pflag"
)
func AutoCompleteFlags(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Author
Member

@fyrchik What do you think about creating a task to add AutoCompleteFlags to all cmd commands?

@fyrchik What do you think about creating a task to add `AutoCompleteFlags` to all cmd commands?
Owner

I think it provides little value but significantly increases mental overhead when reading the code.

I think it provides little value but significantly increases mental overhead when reading the code.
Author
Member

Ok, deleted AutoCompleteFlags.

Ok, deleted `AutoCompleteFlags`.
achuprov marked this conversation as resolved
achuprov force-pushed feat/frostfs_adm_add_set-kv from a94f6e2711 to 8528ddb16d 2025-02-06 16:47:26 +00:00 Compare
achuprov changed title from WIP: adm/frostfsid: Add 'set-kv' to adm/frostfsid: Add 'set-kv' 2025-02-06 16:49:30 +00:00
aarifullin reviewed 2025-02-07 08:36:53 +00:00
@ -406,0 +481,4 @@
}
if key == "" {
commonCmd.ExitOnErr(cmd, "", errors.New("key can't be empty"))
Member

Let's avoid using can't and failed in error messages. I used to use them too but actually that's unnecessary.
I'd consider just empty key. And failed to set -> set key: %w, failed to delete -> delete key: %w

Let's avoid using `can't` and `failed` in error messages. I used to use them too but actually that's unnecessary. I'd consider just `empty key`. And `failed to set` -> `set key: %w`, `failed to delete` -> `delete key: %w`
Author
Member

fixed

fixed
fyrchik reviewed 2025-02-07 09:49:47 +00:00
@ -239,0 +267,4 @@
frostfsidSetKVCmd.Flags().String(keyFlag, "", keyDescFlag)
frostfsidSetKVCmd.Flags().String(valueFlag, "", valueDescFlag)
frostfsidSetKVCmd.ValidArgsFunction = commonflags.AutoCompleteFlags
Owner

Why do we need this line? Its seems generic and unrelated to the "well-known" keys.

Why do we need this line? Its seems generic and unrelated to the "well-known" keys.
achuprov marked this conversation as resolved
fyrchik reviewed 2025-02-07 09:51:25 +00:00
@ -406,0 +474,4 @@
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, wellKnownValue := range wellKnownFlags {
if key == wellKnownKey && value == "" {
Owner

Empty value almost always is an error, because we forgot.
Let's remove this "wellKnownValue" logic.

Empty value almost always is an error, because we forgot. Let's remove this "wellKnownValue" logic.
Author
Member

removed

removed
achuprov force-pushed feat/frostfs_adm_add_set-kv from 8528ddb16d to 8d0b741d37 2025-02-07 11:41:08 +00:00 Compare
achuprov force-pushed feat/frostfs_adm_add_set-kv from 8d0b741d37 to 2be7c21568 2025-02-07 11:45:11 +00:00 Compare
achuprov force-pushed feat/frostfs_adm_add_set-kv from 2be7c21568 to b504078794 2025-02-10 12:21:43 +00:00 Compare
achuprov force-pushed feat/frostfs_adm_add_set-kv from b504078794 to 076952f4c7 2025-02-10 12:28:58 +00:00 Compare
aarifullin approved these changes 2025-02-10 15:37:36 +00:00
dstepanov-yadro approved these changes 2025-02-10 16:27:47 +00:00
dstepanov-yadro merged commit 076952f4c7 into master 2025-02-10 16:27:51 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#1634
No description provided.