forked from TrueCloudLab/frostfs-node
[#25] Use api-go stringers and parsers for ID types in CLI
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d7c53debb5
commit
c0a4343282
2 changed files with 10 additions and 26 deletions
|
@ -2,7 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -12,7 +11,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/mr-tron/base58"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/acl"
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
|
@ -132,8 +130,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
||||||
return fmt.Errorf("rpc error: %w", err)
|
return fmt.Errorf("rpc error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: use stringers after neofs-api-go#147
|
fmt.Println("container ID:", id)
|
||||||
fmt.Println("container ID:", base58.Encode(id.ToV2().GetValue()))
|
|
||||||
|
|
||||||
if containerAwait {
|
if containerAwait {
|
||||||
fmt.Println("awaiting...")
|
fmt.Println("awaiting...")
|
||||||
|
@ -233,8 +230,7 @@ func init() {
|
||||||
|
|
||||||
func prettyPrintContainerList(list []*container.ID) {
|
func prettyPrintContainerList(list []*container.ID) {
|
||||||
for i := range list {
|
for i := range list {
|
||||||
// todo: use stringers after neofs-api-go#147
|
fmt.Println(list[i])
|
||||||
fmt.Println(base58.Encode(list[i].ToV2().GetValue()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,17 +313,12 @@ func parseNonce(nonce string) (uuid.UUID, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseContainerID(cid string) (*container.ID, error) {
|
func parseContainerID(cid string) (*container.ID, error) {
|
||||||
// todo: use decoders after neofs-api-go#147
|
id := container.NewID()
|
||||||
data, err := base58.Decode(cid)
|
|
||||||
if err != nil || len(data) != sha256.Size {
|
err := id.Parse(cid)
|
||||||
|
if err != nil {
|
||||||
return nil, errors.New("can't decode container ID value")
|
return nil, errors.New("can't decode container ID value")
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf [sha256.Size]byte
|
|
||||||
copy(buf[:], data)
|
|
||||||
|
|
||||||
id := container.NewID()
|
|
||||||
id.SetSHA256(buf)
|
|
||||||
|
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/mr-tron/base58"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
|
@ -165,20 +164,14 @@ func getSDKClient() (*client.Client, error) {
|
||||||
|
|
||||||
// ownerFromString converts string with NEO3 wallet address to neofs owner ID.
|
// ownerFromString converts string with NEO3 wallet address to neofs owner ID.
|
||||||
func ownerFromString(s string) (*owner.ID, error) {
|
func ownerFromString(s string) (*owner.ID, error) {
|
||||||
var w owner.NEO3Wallet
|
result := owner.NewID()
|
||||||
|
|
||||||
// todo: move this into neofs-api-go `owner.NEO3WalletFromString` function
|
err := result.Parse(s)
|
||||||
binaryWallet, err := base58.Decode(s)
|
if err != nil {
|
||||||
if err != nil || len(binaryWallet) != len(w) {
|
|
||||||
return nil, errors.New("can't decode owner ID wallet address")
|
return nil, errors.New("can't decode owner ID wallet address")
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(w[:], binaryWallet)
|
return result, nil
|
||||||
|
|
||||||
id := owner.NewID()
|
|
||||||
id.SetNeo3Wallet(&w)
|
|
||||||
|
|
||||||
return id, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printVerbose(format string, a ...interface{}) {
|
func printVerbose(format string, a ...interface{}) {
|
||||||
|
|
Loading…
Reference in a new issue