Skip to content

Commit 3fadbae

Browse files
authored
neofs cli container list lists nothing (#3613)
Closes #3307.
2 parents 4f76ba1 + 2a1293e commit 3fadbae

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Changelog for NeoFS Node
1818
- Empty storage and error-free startup when changing layout parameters (#3594)
1919
- Flaky storage evacuation unit test (#3605)
2020
- Incorrect search request from SN when processing tombstones (#3610)
21+
- `neofs-cli container list` lists nothing if there are no flags (#3613)
2122

2223
### Changed
2324
- Stream payload without buffering to reduce memory usage in CLI `Get/Put` operations (#3535)

cmd/neofs-cli/internal/key/raw.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func Get(cmd *cobra.Command) (*ecdsa.PrivateKey, error) {
2727
return pk, nil
2828
}
2929

30-
var errMissingFlag = errors.New("missing key flag")
30+
var ErrMissingFlag = errors.New("missing key flag")
3131

3232
// get decodes ecdsa.PrivateKey from the wallet file located in the path
3333
// stored by commonflags.WalletPath viper key. Returns errMissingFlag
3434
// if the viper flag is not set.
3535
func get(cmd *cobra.Command) (*ecdsa.PrivateKey, error) {
3636
keyDesc := viper.GetString(commonflags.WalletPath)
3737
if keyDesc == "" {
38-
return nil, errMissingFlag
38+
return nil, ErrMissingFlag
3939
}
4040
w, err := wallet.NewWalletFromFile(keyDesc)
4141
if err != nil {
@@ -60,7 +60,7 @@ func GetOrGenerate(cmd *cobra.Command) (*ecdsa.PrivateKey, error) {
6060
func getOrGenerate(cmd *cobra.Command) (*ecdsa.PrivateKey, error) {
6161
if !viper.GetBool(commonflags.GenerateKey) {
6262
key, err := get(cmd)
63-
if !errors.Is(err, errMissingFlag) {
63+
if !errors.Is(err, ErrMissingFlag) {
6464
if err == nil {
6565
common.PrintVerbose(cmd, "Configured wallet will be used for the command.")
6666
}

cmd/neofs-cli/modules/container/list.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package container
22

33
import (
4+
"errors"
45
"fmt"
56

67
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
@@ -31,18 +32,18 @@ var listContainersCmd = &cobra.Command{
3132
RunE: func(cmd *cobra.Command, _ []string) error {
3233
var idUser user.ID
3334

34-
key, err := key.GetOrGenerate(cmd)
35-
if err != nil {
35+
pk, err := key.Get(cmd)
36+
if err != nil && !errors.Is(err, key.ErrMissingFlag) {
3637
return err
3738
}
3839

39-
if flagVarListContainerOwner == "" {
40-
idUser = user.NewFromECDSAPublicKey(key.PublicKey)
41-
} else {
40+
if flagVarListContainerOwner != "" {
4241
err := idUser.DecodeString(flagVarListContainerOwner)
4342
if err != nil {
4443
return fmt.Errorf("invalid user ID: %w", err)
4544
}
45+
} else if pk != nil {
46+
idUser = user.NewFromECDSAPublicKey(pk.PublicKey)
4647
}
4748

4849
ctx, cancel := commonflags.GetCommandContext(cmd)
@@ -83,7 +84,7 @@ func initContainerListContainersCmd() {
8384
flags := listContainersCmd.Flags()
8485

8586
flags.StringVar(&flagVarListContainerOwner, flagListContainerOwner, "",
86-
"Owner of containers (omit to use owner from private key)",
87+
"Owner of containers (omit to use owner from private key or if no key provided - list all containers)",
8788
)
8889
flags.BoolVar(&flagVarListPrintAttr, flagListPrintAttr, false,
8990
"Request and print attributes of each container",

cmd/neofs-node/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ func (x *containersInChain) GetEACL(id cid.ID) (eacl.Table, error) {
371371
}
372372

373373
func (x *containersInChain) List(id user.ID) ([]cid.ID, error) {
374+
if id.IsZero() {
375+
return x.cnrLst.List(nil)
376+
}
374377
return x.cnrLst.List(&id)
375378
}
376379

docs/cli-commands/neofs-cli_container_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ neofs-cli container list [flags]
1616
--address string Address of wallet account
1717
-g, --generate-key Generate new private key
1818
-h, --help help for list
19-
--owner string Owner of containers (omit to use owner from private key)
19+
--owner string Owner of containers (omit to use owner from private key or if no key provided - list all containers)
2020
-r, --rpc-endpoint string Remote node address (as 'multiaddr' or '<host>:<port>')
2121
-t, --timeout duration Timeout for the operation (default 15s)
2222
--ttl uint32 TTL value in request meta header (default 2)

pkg/services/container/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
1515
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
1616
icrypto "github.com/nspcc-dev/neofs-node/internal/crypto"
17+
islices "github.com/nspcc-dev/neofs-node/internal/slices"
1718
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
1819
"github.com/nspcc-dev/neofs-node/pkg/services/util"
1920
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
@@ -430,8 +431,10 @@ func (s *server) List(_ context.Context, req *protocontainer.ListRequest) (*prot
430431
}
431432

432433
var id user.ID
433-
if err := id.FromProtoMessage(mID); err != nil {
434-
return s.makeFailedListResponse(fmt.Errorf("invalid user: %w", err))
434+
if len(mID.Value) != user.IDSize || !islices.AllZeros(mID.Value) {
435+
if err := id.FromProtoMessage(mID); err != nil {
436+
return s.makeFailedListResponse(fmt.Errorf("invalid user: %w", err))
437+
}
435438
}
436439

437440
cs, err := s.contract.List(id)

0 commit comments

Comments
 (0)