forked from TrueCloudLab/frostfs-node
[#79] Simplify getCID and getOID functions in CLI
Parser from string is available in neofs-api-go. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
4ce58fb26c
commit
1482b0c5d0
1 changed files with 6 additions and 22 deletions
|
@ -2,7 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/container"
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
@ -453,30 +451,16 @@ func parseObjectAttrs(cmd *cobra.Command) ([]*object.Attribute, error) {
|
||||||
|
|
||||||
func getCID(cmd *cobra.Command) (*container.ID, error) {
|
func getCID(cmd *cobra.Command) (*container.ID, error) {
|
||||||
cid := container.NewID()
|
cid := container.NewID()
|
||||||
var v [32]byte
|
err := cid.Parse(cmd.Flag("cid").Value.String())
|
||||||
b, err := base58.Decode(cmd.Flag("cid").Value.String())
|
|
||||||
if err != nil {
|
return cid, err
|
||||||
return nil, err
|
|
||||||
} else if len(b) != sha256.Size {
|
|
||||||
return nil, errors.New("invalid length")
|
|
||||||
}
|
|
||||||
copy(v[:], b)
|
|
||||||
cid.SetSHA256(v)
|
|
||||||
return cid, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOID(cmd *cobra.Command) (*object.ID, error) {
|
func getOID(cmd *cobra.Command) (*object.ID, error) {
|
||||||
oid := object.NewID()
|
oid := object.NewID()
|
||||||
var v [32]byte
|
err := oid.Parse(cmd.Flag("oid").Value.String())
|
||||||
b, err := base58.Decode(cmd.Flag("oid").Value.String())
|
|
||||||
if err != nil {
|
return oid, err
|
||||||
return nil, err
|
|
||||||
} else if len(b) != sha256.Size {
|
|
||||||
return nil, errors.New("invalid length")
|
|
||||||
}
|
|
||||||
copy(v[:], b)
|
|
||||||
oid.SetSHA256(v)
|
|
||||||
return oid, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getObjectAddress(cmd *cobra.Command) (*object.Address, error) {
|
func getObjectAddress(cmd *cobra.Command) (*object.Address, error) {
|
||||||
|
|
Loading…
Reference in a new issue