forked from TrueCloudLab/frostfs-node
[#1454] Upgrade NeoFS SDK Go module with new IDs
Core changes: * avoid package-colliding variable naming * avoid using pointers to IDs where unnecessary * avoid using `idSDK` import alias pattern * use `EncodeToString` for protocol string calculation and `String` for printing Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
cc6209e8a0
commit
1c30414a6c
218 changed files with 2095 additions and 2521 deletions
|
@ -14,8 +14,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/version"
|
||||
)
|
||||
|
||||
|
@ -77,12 +76,12 @@ type PutContainerPrm struct {
|
|||
|
||||
// PutContainerRes groups the resulting values of PutContainer operation.
|
||||
type PutContainerRes struct {
|
||||
cliRes *client.ResContainerPut
|
||||
cnr cid.ID
|
||||
}
|
||||
|
||||
// ID returns identifier of the created container.
|
||||
func (x PutContainerRes) ID() *cid.ID {
|
||||
return x.cliRes.ID()
|
||||
func (x PutContainerRes) ID() cid.ID {
|
||||
return x.cnr
|
||||
}
|
||||
|
||||
// PutContainer sends a request to save the container in NeoFS.
|
||||
|
@ -94,7 +93,15 @@ func (x PutContainerRes) ID() *cid.ID {
|
|||
//
|
||||
// Returns any error which prevented the operation from completing correctly in error return.
|
||||
func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) {
|
||||
res.cliRes, err = prm.cli.ContainerPut(context.Background(), prm.PrmContainerPut)
|
||||
cliRes, err := prm.cli.ContainerPut(context.Background(), prm.PrmContainerPut)
|
||||
if err == nil {
|
||||
cnr := cliRes.ID()
|
||||
if cnr == nil {
|
||||
err = errors.New("missing container ID in response")
|
||||
} else {
|
||||
res.cnr = *cnr
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -306,11 +313,11 @@ func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) {
|
|||
|
||||
// PutObjectRes groups the resulting values of PutObject operation.
|
||||
type PutObjectRes struct {
|
||||
id *oidSDK.ID
|
||||
id oid.ID
|
||||
}
|
||||
|
||||
// ID returns identifier of the created object.
|
||||
func (x PutObjectRes) ID() *oidSDK.ID {
|
||||
func (x PutObjectRes) ID() oid.ID {
|
||||
return x.id
|
||||
}
|
||||
|
||||
|
@ -382,20 +389,18 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
|||
}
|
||||
}
|
||||
|
||||
res, err := wrt.Close()
|
||||
cliRes, err := wrt.Close()
|
||||
if err != nil { // here err already carries both status and client errors
|
||||
return nil, fmt.Errorf("client failure: %w", err)
|
||||
}
|
||||
|
||||
var id oidSDK.ID
|
||||
var res PutObjectRes
|
||||
|
||||
if !res.ReadStoredObjectID(&id) {
|
||||
if !cliRes.ReadStoredObjectID(&res.id) {
|
||||
return nil, errors.New("missing ID of the stored object")
|
||||
}
|
||||
|
||||
return &PutObjectRes{
|
||||
id: &id,
|
||||
}, nil
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// DeleteObjectPrm groups parameters of DeleteObject operation.
|
||||
|
@ -406,12 +411,12 @@ type DeleteObjectPrm struct {
|
|||
|
||||
// DeleteObjectRes groups the resulting values of DeleteObject operation.
|
||||
type DeleteObjectRes struct {
|
||||
addrTombstone *addressSDK.Address
|
||||
tomb oid.ID
|
||||
}
|
||||
|
||||
// TombstoneAddress returns the address of the created object with tombstone.
|
||||
func (x DeleteObjectRes) TombstoneAddress() *addressSDK.Address {
|
||||
return x.addrTombstone
|
||||
// Tombstone returns the ID of the created object with tombstone.
|
||||
func (x DeleteObjectRes) Tombstone() oid.ID {
|
||||
return x.tomb
|
||||
}
|
||||
|
||||
// DeleteObject marks an object to be removed from NeoFS through tombstone placement.
|
||||
|
@ -419,15 +424,8 @@ func (x DeleteObjectRes) TombstoneAddress() *addressSDK.Address {
|
|||
// Returns any error which prevented the operation from completing correctly in error return.
|
||||
func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) {
|
||||
var delPrm client.PrmObjectDelete
|
||||
|
||||
cnr, ok := prm.objAddr.ContainerID()
|
||||
if ok {
|
||||
delPrm.FromContainer(cnr)
|
||||
}
|
||||
|
||||
if id, ok := prm.objAddr.ObjectID(); ok {
|
||||
delPrm.ByID(id)
|
||||
}
|
||||
delPrm.FromContainer(prm.objAddr.Container())
|
||||
delPrm.ByID(prm.objAddr.Object())
|
||||
|
||||
if prm.sessionToken != nil {
|
||||
delPrm.WithinSession(*prm.sessionToken)
|
||||
|
@ -444,18 +442,14 @@ func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) {
|
|||
return nil, fmt.Errorf("remove object via client: %w", err)
|
||||
}
|
||||
|
||||
var id oidSDK.ID
|
||||
var id oid.ID
|
||||
|
||||
if !cliRes.ReadTombstoneID(&id) {
|
||||
return nil, errors.New("object removed but tombstone ID is missing")
|
||||
}
|
||||
|
||||
var addr addressSDK.Address
|
||||
addr.SetObjectID(id)
|
||||
addr.SetContainerID(cnr)
|
||||
|
||||
return &DeleteObjectRes{
|
||||
addrTombstone: &addr,
|
||||
tomb: id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -492,14 +486,8 @@ func (x GetObjectRes) Header() *object.Object {
|
|||
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
||||
func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||
var getPrm client.PrmObjectGet
|
||||
|
||||
if id, ok := prm.objAddr.ContainerID(); ok {
|
||||
getPrm.FromContainer(id)
|
||||
}
|
||||
|
||||
if id, ok := prm.objAddr.ObjectID(); ok {
|
||||
getPrm.ByID(id)
|
||||
}
|
||||
getPrm.FromContainer(prm.objAddr.Container())
|
||||
getPrm.ByID(prm.objAddr.Object())
|
||||
|
||||
if prm.sessionToken != nil {
|
||||
getPrm.WithinSession(*prm.sessionToken)
|
||||
|
@ -574,14 +562,8 @@ func (x HeadObjectRes) Header() *object.Object {
|
|||
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
||||
func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
|
||||
var cliPrm client.PrmObjectHead
|
||||
|
||||
if id, ok := prm.objAddr.ContainerID(); ok {
|
||||
cliPrm.FromContainer(id)
|
||||
}
|
||||
|
||||
if id, ok := prm.objAddr.ObjectID(); ok {
|
||||
cliPrm.ByID(id)
|
||||
}
|
||||
cliPrm.FromContainer(prm.objAddr.Container())
|
||||
cliPrm.ByID(prm.objAddr.Object())
|
||||
|
||||
if prm.sessionToken != nil {
|
||||
cliPrm.WithinSession(*prm.sessionToken)
|
||||
|
@ -632,11 +614,11 @@ func (x *SearchObjectsPrm) SetFilters(filters object.SearchFilters) {
|
|||
|
||||
// SearchObjectsRes groups the resulting values of SearchObjects operation.
|
||||
type SearchObjectsRes struct {
|
||||
ids []oidSDK.ID
|
||||
ids []oid.ID
|
||||
}
|
||||
|
||||
// IDList returns identifiers of the matched objects.
|
||||
func (x SearchObjectsRes) IDList() []oidSDK.ID {
|
||||
func (x SearchObjectsRes) IDList() []oid.ID {
|
||||
return x.ids
|
||||
}
|
||||
|
||||
|
@ -645,11 +627,7 @@ func (x SearchObjectsRes) IDList() []oidSDK.ID {
|
|||
// Returns any error which prevented the operation from completing correctly in error return.
|
||||
func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
||||
var cliPrm client.PrmObjectSearch
|
||||
|
||||
if prm.cnrID != nil {
|
||||
cliPrm.InContainer(*prm.cnrID)
|
||||
}
|
||||
|
||||
cliPrm.InContainer(prm.cnrID)
|
||||
cliPrm.SetFilters(prm.filters)
|
||||
|
||||
if prm.sessionToken != nil {
|
||||
|
@ -671,8 +649,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
|||
return nil, fmt.Errorf("init object search: %w", err)
|
||||
}
|
||||
|
||||
buf := make([]oidSDK.ID, 10)
|
||||
var list []oidSDK.ID
|
||||
buf := make([]oid.ID, 10)
|
||||
var list []oid.ID
|
||||
var n int
|
||||
var ok bool
|
||||
|
||||
|
@ -739,14 +717,8 @@ func (x HashPayloadRangesRes) HashList() [][]byte {
|
|||
// Returns an error if number of received hashes differs with the number of requested ranges.
|
||||
func HashPayloadRanges(prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) {
|
||||
var cliPrm client.PrmObjectHash
|
||||
|
||||
if id, ok := prm.objAddr.ContainerID(); ok {
|
||||
cliPrm.FromContainer(id)
|
||||
}
|
||||
|
||||
if id, ok := prm.objAddr.ObjectID(); ok {
|
||||
cliPrm.ByID(id)
|
||||
}
|
||||
cliPrm.FromContainer(prm.objAddr.Container())
|
||||
cliPrm.ByID(prm.objAddr.Object())
|
||||
|
||||
if prm.local {
|
||||
cliPrm.MarkLocal()
|
||||
|
@ -813,14 +785,8 @@ type PayloadRangeRes struct{}
|
|||
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
||||
func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
||||
var cliPrm client.PrmObjectRange
|
||||
|
||||
if id, ok := prm.objAddr.ContainerID(); ok {
|
||||
cliPrm.FromContainer(id)
|
||||
}
|
||||
|
||||
if id, ok := prm.objAddr.ObjectID(); ok {
|
||||
cliPrm.ByID(id)
|
||||
}
|
||||
cliPrm.FromContainer(prm.objAddr.Container())
|
||||
cliPrm.ByID(prm.objAddr.Object())
|
||||
|
||||
if prm.sessionToken != nil {
|
||||
cliPrm.WithinSession(*prm.sessionToken)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-sdk-go/bearer"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/client"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
)
|
||||
|
||||
|
@ -22,11 +22,11 @@ func (x *commonPrm) SetClient(cli *client.Client) {
|
|||
}
|
||||
|
||||
type containerIDPrm struct {
|
||||
cnrID *cid.ID
|
||||
cnrID cid.ID
|
||||
}
|
||||
|
||||
// SetContainerID sets the container identifier.
|
||||
func (x *containerIDPrm) SetContainerID(id *cid.ID) {
|
||||
func (x *containerIDPrm) SetContainerID(id cid.ID) {
|
||||
x.cnrID = id
|
||||
}
|
||||
|
||||
|
@ -40,10 +40,10 @@ func (x *bearerTokenPrm) SetBearerToken(tok *bearer.Token) {
|
|||
}
|
||||
|
||||
type objectAddressPrm struct {
|
||||
objAddr *addressSDK.Address
|
||||
objAddr oid.Address
|
||||
}
|
||||
|
||||
func (x *objectAddressPrm) SetAddress(addr *addressSDK.Address) {
|
||||
func (x *objectAddressPrm) SetAddress(addr oid.Address) {
|
||||
x.objAddr = addr
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package common
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/nspcc-dev/neofs-sdk-go/bearer"
|
||||
|
@ -33,13 +34,24 @@ func ReadBearerToken(cmd *cobra.Command, flagname string) *bearer.Token {
|
|||
return &tok
|
||||
}
|
||||
|
||||
// ReadSessionToken reads session token as JSON file with session token
|
||||
// from path provided in a specified flag.
|
||||
// ReadSessionToken calls ReadSessionTokenErr and exists on error.
|
||||
func ReadSessionToken(cmd *cobra.Command, dst json.Unmarshaler, fPath string) {
|
||||
ExitOnErr(cmd, "", ReadSessionTokenErr(dst, fPath))
|
||||
}
|
||||
|
||||
// ReadSessionTokenErr reads session token as JSON file with session token
|
||||
// from path provided in a specified flag.
|
||||
func ReadSessionTokenErr(dst json.Unmarshaler, fPath string) error {
|
||||
// try to read session token from file
|
||||
data, err := os.ReadFile(fPath)
|
||||
ExitOnErr(cmd, "could not open file with session token: %w", err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open file with session token <%s>: %w", fPath, err)
|
||||
}
|
||||
|
||||
err = dst.UnmarshalJSON(data)
|
||||
ExitOnErr(cmd, "could not unmarshal session token from file: %w", err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not unmarshal session token from file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,22 +24,22 @@ var accountingBalanceCmd = &cobra.Command{
|
|||
Short: "Get internal balance of NeoFS account",
|
||||
Long: `Get internal balance of NeoFS account`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var oid user.ID
|
||||
var idUser user.ID
|
||||
|
||||
pk := key.GetOrGenerate(cmd)
|
||||
|
||||
balanceOwner, _ := cmd.Flags().GetString(ownerFlag)
|
||||
if balanceOwner == "" {
|
||||
user.IDFromKey(&oid, pk.PublicKey)
|
||||
user.IDFromKey(&idUser, pk.PublicKey)
|
||||
} else {
|
||||
common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", oid.DecodeString(balanceOwner))
|
||||
common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", idUser.DecodeString(balanceOwner))
|
||||
}
|
||||
|
||||
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
||||
|
||||
var prm internalclient.BalanceOfPrm
|
||||
prm.SetClient(cli)
|
||||
prm.SetAccount(oid)
|
||||
prm.SetAccount(idUser)
|
||||
|
||||
res, err := internalclient.BalanceOf(prm)
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/policy"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
||||
|
@ -205,7 +204,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
|||
if containerAwait {
|
||||
cmd.Println("awaiting...")
|
||||
|
||||
getPrm.SetContainer(*id)
|
||||
getPrm.SetContainer(id)
|
||||
|
||||
for i := 0; i < awaitTimeout; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
@ -288,11 +287,9 @@ var listContainerObjectsCmd = &cobra.Command{
|
|||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(*id)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareSessionPrm(cmd, *id, nil, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(id)
|
||||
prm.SetContainerID(*id)
|
||||
prm.SetFilters(*filters)
|
||||
|
||||
res, err := internalclient.SearchObjects(prm)
|
||||
|
@ -301,7 +298,7 @@ var listContainerObjectsCmd = &cobra.Command{
|
|||
objectIDs := res.IDList()
|
||||
|
||||
for i := range objectIDs {
|
||||
cmd.Println(objectIDs[i].String())
|
||||
cmd.Println(objectIDs[i])
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -603,7 +600,7 @@ func init() {
|
|||
|
||||
func prettyPrintContainerList(cmd *cobra.Command, list []cid.ID) {
|
||||
for i := range list {
|
||||
cmd.Println(list[i].String())
|
||||
cmd.Println(list[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -22,20 +19,10 @@ var dropObjectsCmd = &cobra.Command{
|
|||
pk := key.Get(cmd)
|
||||
|
||||
dropObjectsList, _ := cmd.Flags().GetStringSlice(dropObjectsFlag)
|
||||
binAddrList := make([][]byte, 0, len(dropObjectsList))
|
||||
binAddrList := make([][]byte, len(dropObjectsList))
|
||||
|
||||
for i := range dropObjectsList {
|
||||
a := addressSDK.NewAddress()
|
||||
|
||||
err := a.Parse(dropObjectsList[i])
|
||||
if err != nil {
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("could not parse address #%d: %w", i, err))
|
||||
}
|
||||
|
||||
binAddr, err := a.Marshal()
|
||||
common.ExitOnErr(cmd, "could not marshal the address: %w", err)
|
||||
|
||||
binAddrList = append(binAddrList, binAddr)
|
||||
binAddrList[i] = []byte(dropObjectsList[i])
|
||||
}
|
||||
|
||||
body := new(control.DropObjectsRequest_Body)
|
||||
|
|
|
@ -24,16 +24,13 @@ func verifyResponse(cmd *cobra.Command,
|
|||
GetSign() []byte
|
||||
},
|
||||
body interface {
|
||||
StableMarshal([]byte) ([]byte, error)
|
||||
StableMarshal([]byte) []byte
|
||||
},
|
||||
) {
|
||||
if sigControl == nil {
|
||||
common.ExitOnErr(cmd, "", errors.New("missing response signature"))
|
||||
}
|
||||
|
||||
bodyData, err := body.StableMarshal(nil)
|
||||
common.ExitOnErr(cmd, "marshal response body: %w", err)
|
||||
|
||||
// TODO(@cthulhu-rider): #1387 use Signature message from NeoFS API to avoid conversion
|
||||
var sigV2 refs.Signature
|
||||
sigV2.SetScheme(refs.ECDSA_SHA512)
|
||||
|
@ -43,7 +40,7 @@ func verifyResponse(cmd *cobra.Command,
|
|||
var sig neofscrypto.Signature
|
||||
sig.ReadFromV2(sigV2)
|
||||
|
||||
if !sig.Verify(bodyData) {
|
||||
if !sig.Verify(body.StableMarshal(nil)) {
|
||||
common.ExitOnErr(cmd, "", errors.New("invalid response signature"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||
objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
|
@ -51,7 +50,7 @@ var cmdObjectLock = &cobra.Command{
|
|||
|
||||
var prm internalclient.PutObjectPrm
|
||||
|
||||
prepareSessionPrmWithOwner(cmd, objectcore.AddressOf(obj), key, idOwner, &prm)
|
||||
prepareSessionPrmWithOwner(cmd, cnr, nil, key, *idOwner, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetHeader(obj)
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/user"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -317,24 +316,25 @@ type clientKeySession interface {
|
|||
SetSessionToken(*session.Object)
|
||||
}
|
||||
|
||||
func prepareSessionPrm(cmd *cobra.Command, addr *addressSDK.Address, prms ...clientKeySession) {
|
||||
func prepareSessionPrm(cmd *cobra.Command, cnr cid.ID, obj *oid.ID, prms ...clientKeySession) {
|
||||
pk := key.GetOrGenerate(cmd)
|
||||
|
||||
prepareSessionPrmWithKey(cmd, addr, pk, prms...)
|
||||
prepareSessionPrmWithKey(cmd, cnr, obj, pk, prms...)
|
||||
}
|
||||
|
||||
func prepareSessionPrmWithKey(cmd *cobra.Command, addr *addressSDK.Address, key *ecdsa.PrivateKey, prms ...clientKeySession) {
|
||||
func prepareSessionPrmWithKey(cmd *cobra.Command, cnr cid.ID, obj *oid.ID, key *ecdsa.PrivateKey, prms ...clientKeySession) {
|
||||
ownerID, err := getOwnerID(key)
|
||||
common.ExitOnErr(cmd, "owner ID from key: %w", err)
|
||||
|
||||
prepareSessionPrmWithOwner(cmd, addr, key, ownerID, prms...)
|
||||
prepareSessionPrmWithOwner(cmd, cnr, obj, key, *ownerID, prms...)
|
||||
}
|
||||
|
||||
func prepareSessionPrmWithOwner(
|
||||
cmd *cobra.Command,
|
||||
addr *addressSDK.Address,
|
||||
cnr cid.ID,
|
||||
obj *oid.ID,
|
||||
key *ecdsa.PrivateKey,
|
||||
ownerID *user.ID,
|
||||
ownerID user.ID,
|
||||
prms ...clientKeySession,
|
||||
) {
|
||||
cli := internalclient.GetSDKClientByFlag(cmd, key, commonflags.RPC)
|
||||
|
@ -373,7 +373,11 @@ func prepareSessionPrmWithOwner(
|
|||
panic("invalid client parameter type")
|
||||
}
|
||||
|
||||
tok.ApplyTo(*addr)
|
||||
tok.BindContainer(cnr)
|
||||
|
||||
if obj != nil {
|
||||
tok.LimitByObject(*obj)
|
||||
}
|
||||
|
||||
err := tok.Sign(*key)
|
||||
common.ExitOnErr(cmd, "session token signing: %w", err)
|
||||
|
@ -413,8 +417,9 @@ func putObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
ownerID, err := getOwnerID(pk)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
cnr, err := getCID(cmd)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
var cnr cid.ID
|
||||
common.ExitOnErr(cmd, "", readCID(cmd, &cnr))
|
||||
|
||||
filename := cmd.Flag("file").Value.String()
|
||||
f, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm)
|
||||
|
@ -447,7 +452,7 @@ func putObject(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
obj := object.New()
|
||||
obj.SetContainerID(*cnr)
|
||||
obj.SetContainerID(cnr)
|
||||
obj.SetOwnerID(ownerID)
|
||||
obj.SetAttributes(attrs...)
|
||||
|
||||
|
@ -460,9 +465,7 @@ func putObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.PutObjectPrm
|
||||
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(*cnr)
|
||||
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, pk, ownerID, &prm)
|
||||
prepareSessionPrmWithOwner(cmd, cnr, nil, pk, *ownerID, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetHeader(obj)
|
||||
|
||||
|
@ -495,44 +498,37 @@ func putObject(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func deleteObject(cmd *cobra.Command, _ []string) {
|
||||
objAddr, err := getObjectAddress(cmd)
|
||||
var cnr cid.ID
|
||||
var obj oid.ID
|
||||
|
||||
err := readObjectAddress(cmd, &cnr, &obj)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
var prm internalclient.DeleteObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, &obj, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
|
||||
var addr oid.Address
|
||||
addr.SetContainer(cnr)
|
||||
addr.SetObject(obj)
|
||||
|
||||
prm.SetAddress(addr)
|
||||
|
||||
res, err := internalclient.DeleteObject(prm)
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
tombstoneAddr := res.TombstoneAddress()
|
||||
tomb := res.Tombstone()
|
||||
|
||||
cmd.Println("Object removed successfully.")
|
||||
|
||||
const strEmpty = "<empty>"
|
||||
var strID, strCnr string
|
||||
|
||||
id, ok := tombstoneAddr.ObjectID()
|
||||
if ok {
|
||||
strID = id.String()
|
||||
} else {
|
||||
strID = strEmpty
|
||||
}
|
||||
|
||||
cnr, ok := tombstoneAddr.ContainerID()
|
||||
if ok {
|
||||
strCnr = cnr.String()
|
||||
} else {
|
||||
strCnr = strEmpty
|
||||
}
|
||||
|
||||
cmd.Printf(" ID: %s\n CID: %s\n", strID, strCnr)
|
||||
cmd.Printf(" ID: %s\n CID: %s\n", tomb, cnr)
|
||||
}
|
||||
|
||||
func getObject(cmd *cobra.Command, _ []string) {
|
||||
objAddr, err := getObjectAddress(cmd)
|
||||
var cnr cid.ID
|
||||
var obj oid.ID
|
||||
|
||||
err := readObjectAddress(cmd, &cnr, &obj)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
var out io.Writer
|
||||
|
@ -552,8 +548,13 @@ func getObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.GetObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, &obj, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
|
||||
var objAddr oid.Address
|
||||
objAddr.SetContainer(cnr)
|
||||
objAddr.SetObject(obj)
|
||||
|
||||
prm.SetAddress(objAddr)
|
||||
|
||||
var p *pb.ProgressBar
|
||||
|
@ -598,15 +599,23 @@ func getObject(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func getObjectHeader(cmd *cobra.Command, _ []string) {
|
||||
objAddr, err := getObjectAddress(cmd)
|
||||
var cnr cid.ID
|
||||
var obj oid.ID
|
||||
|
||||
err := readObjectAddress(cmd, &cnr, &obj)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
mainOnly, _ := cmd.Flags().GetBool("main-only")
|
||||
|
||||
var prm internalclient.HeadObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, &obj, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
|
||||
var objAddr oid.Address
|
||||
objAddr.SetContainer(cnr)
|
||||
objAddr.SetObject(obj)
|
||||
|
||||
prm.SetAddress(objAddr)
|
||||
prm.SetMainOnlyFlag(mainOnly)
|
||||
|
||||
|
@ -624,7 +633,9 @@ func getObjectHeader(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func searchObject(cmd *cobra.Command, _ []string) {
|
||||
cnr, err := getCID(cmd)
|
||||
var cnr cid.ID
|
||||
|
||||
err := readCID(cmd, &cnr)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
sf, err := parseSearchFilters(cmd)
|
||||
|
@ -632,9 +643,7 @@ func searchObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(*cnr)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareSessionPrm(cmd, cnr, nil, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(cnr)
|
||||
prm.SetFilters(sf)
|
||||
|
@ -646,12 +655,15 @@ func searchObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
cmd.Printf("Found %d objects.\n", len(ids))
|
||||
for i := range ids {
|
||||
cmd.Println(ids[i].String())
|
||||
cmd.Println(ids[i])
|
||||
}
|
||||
}
|
||||
|
||||
func getObjectHash(cmd *cobra.Command, _ []string) {
|
||||
objAddr, err := getObjectAddress(cmd)
|
||||
var cnr cid.ID
|
||||
var obj oid.ID
|
||||
|
||||
err := readObjectAddress(cmd, &cnr, &obj)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
ranges, err := getRangeList(cmd)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
@ -677,9 +689,13 @@ func getObjectHash(cmd *cobra.Command, _ []string) {
|
|||
objPrms = append(objPrms, &headPrm)
|
||||
}
|
||||
|
||||
prepareSessionPrm(cmd, objAddr, sesPrms...)
|
||||
prepareSessionPrm(cmd, cnr, &obj, sesPrms...)
|
||||
prepareObjectPrm(cmd, objPrms...)
|
||||
|
||||
var objAddr oid.Address
|
||||
objAddr.SetContainer(cnr)
|
||||
objAddr.SetObject(obj)
|
||||
|
||||
tz := typ == hashTz
|
||||
|
||||
if fullHash {
|
||||
|
@ -792,10 +808,10 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) {
|
|||
fs.AddPhyFilter()
|
||||
}
|
||||
|
||||
oid, _ := cmd.Flags().GetString(searchOIDFlag)
|
||||
if oid != "" {
|
||||
var id oidSDK.ID
|
||||
if err := id.DecodeString(oid); err != nil {
|
||||
strObj, _ := cmd.Flags().GetString(searchOIDFlag)
|
||||
if strObj != "" {
|
||||
var id oid.ID
|
||||
if err := id.DecodeString(strObj); err != nil {
|
||||
return nil, fmt.Errorf("could not parse object ID: %w", err)
|
||||
}
|
||||
|
||||
|
@ -879,42 +895,36 @@ func parseObjectNotifications(cmd *cobra.Command) (*object.NotificationInfo, err
|
|||
return ni, nil
|
||||
}
|
||||
|
||||
func getCID(cmd *cobra.Command) (*cid.ID, error) {
|
||||
var id cid.ID
|
||||
|
||||
err := id.DecodeString(cmd.Flag("cid").Value.String())
|
||||
func readCID(cmd *cobra.Command, cnr *cid.ID) error {
|
||||
err := cnr.DecodeString(cmd.Flag("cid").Value.String())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse container ID: %w", err)
|
||||
return fmt.Errorf("decode container ID string: %w", err)
|
||||
}
|
||||
|
||||
return &id, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func getOID(cmd *cobra.Command) (*oidSDK.ID, error) {
|
||||
var oid oidSDK.ID
|
||||
|
||||
err := oid.DecodeString(cmd.Flag("oid").Value.String())
|
||||
func readOID(cmd *cobra.Command, obj *oid.ID) error {
|
||||
err := obj.DecodeString(cmd.Flag("oid").Value.String())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse object ID: %w", err)
|
||||
return fmt.Errorf("decode container ID string: %w", err)
|
||||
}
|
||||
|
||||
return &oid, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func getObjectAddress(cmd *cobra.Command) (*addressSDK.Address, error) {
|
||||
cnr, err := getCID(cmd)
|
||||
func readObjectAddress(cmd *cobra.Command, cnr *cid.ID, obj *oid.ID) error {
|
||||
err := readCID(cmd, cnr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oid, err := getOID(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
objAddr := addressSDK.NewAddress()
|
||||
objAddr.SetContainerID(*cnr)
|
||||
objAddr.SetObjectID(*oid)
|
||||
return objAddr, nil
|
||||
err = readOID(cmd, obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRangeList(cmd *cobra.Command) ([]*object.Range, error) {
|
||||
|
@ -988,7 +998,7 @@ func printChecksum(cmd *cobra.Command, name string, recv func() (checksum.Checks
|
|||
cmd.Printf("%s: %s\n", name, strVal)
|
||||
}
|
||||
|
||||
func printObjectID(cmd *cobra.Command, recv func() (oidSDK.ID, bool)) {
|
||||
func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
|
||||
var strID string
|
||||
|
||||
id, ok := recv()
|
||||
|
@ -1044,8 +1054,8 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error {
|
|||
cmd.Printf("Split ID: %s\n", splitID)
|
||||
}
|
||||
|
||||
if oid, ok := obj.ParentID(); ok {
|
||||
cmd.Printf("Split ParentID: %s\n", oid)
|
||||
if par, ok := obj.ParentID(); ok {
|
||||
cmd.Printf("Split ParentID: %s\n", par)
|
||||
}
|
||||
|
||||
if prev, ok := obj.PreviousID(); ok {
|
||||
|
@ -1053,7 +1063,7 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error {
|
|||
}
|
||||
|
||||
for _, child := range obj.Children() {
|
||||
cmd.Printf("Split ChildID: %s\n", child.String())
|
||||
cmd.Printf("Split ChildID: %s\n", child)
|
||||
}
|
||||
|
||||
if signature := obj.Signature(); signature != nil {
|
||||
|
@ -1099,8 +1109,10 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
|
|||
}
|
||||
|
||||
func getObjectRange(cmd *cobra.Command, _ []string) {
|
||||
objAddr, err := getObjectAddress(cmd)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
var cnr cid.ID
|
||||
var obj oid.ID
|
||||
|
||||
common.ExitOnErr(cmd, "", readObjectAddress(cmd, &cnr, &obj))
|
||||
|
||||
ranges, err := getRangeList(cmd)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
@ -1127,9 +1139,14 @@ func getObjectRange(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.PayloadRangePrm
|
||||
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, &obj, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
|
||||
var addr oid.Address
|
||||
addr.SetContainer(cnr)
|
||||
addr.SetObject(obj)
|
||||
|
||||
prm.SetAddress(addr)
|
||||
prm.SetRange(ranges[0])
|
||||
prm.SetPayloadWriter(out)
|
||||
|
||||
|
@ -1183,10 +1200,10 @@ func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error
|
|||
b.WriteString("Split ID: " + splitID.String() + "\n")
|
||||
}
|
||||
if link, ok := info.Link(); ok {
|
||||
b.WriteString("Linking object: " + link.String() + "\n")
|
||||
b.WriteString(fmt.Sprintf("Linking object: %s\n", link))
|
||||
}
|
||||
if last, ok := info.LastPart(); ok {
|
||||
b.WriteString("Last object: " + last.String() + "\n")
|
||||
b.WriteString(fmt.Sprintf("Last object: %s\n", last))
|
||||
}
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
storagegroupAPI "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/user"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -141,12 +141,15 @@ func init() {
|
|||
type sgHeadReceiver struct {
|
||||
cmd *cobra.Command
|
||||
key *ecdsa.PrivateKey
|
||||
ownerID *user.ID
|
||||
ownerID user.ID
|
||||
prm internalclient.HeadObjectPrm
|
||||
}
|
||||
|
||||
func (c sgHeadReceiver) Head(addr *addressSDK.Address) (interface{}, error) {
|
||||
prepareSessionPrmWithOwner(c.cmd, addr, c.key, c.ownerID, &c.prm)
|
||||
func (c sgHeadReceiver) Head(addr oid.Address) (interface{}, error) {
|
||||
obj := addr.Object()
|
||||
|
||||
prepareSessionPrmWithOwner(c.cmd, addr.Container(), &obj, c.key, c.ownerID, &c.prm)
|
||||
|
||||
c.prm.SetAddress(addr)
|
||||
|
||||
res, err := internalclient.HeadObject(c.prm)
|
||||
|
@ -169,10 +172,12 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
ownerID, err := getOwnerID(pk)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
cnr, err := getCID(cmd)
|
||||
var cnr cid.ID
|
||||
|
||||
err = readCID(cmd, &cnr)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
members := make([]oidSDK.ID, len(sgMembers))
|
||||
members := make([]oid.ID, len(sgMembers))
|
||||
|
||||
for i := range sgMembers {
|
||||
err = members[i].DecodeString(sgMembers[i])
|
||||
|
@ -184,9 +189,7 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
putPrm internalclient.PutObjectPrm
|
||||
)
|
||||
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(*cnr)
|
||||
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, pk, ownerID, &putPrm)
|
||||
prepareSessionPrmWithOwner(cmd, cnr, nil, pk, *ownerID, &putPrm)
|
||||
prepareObjectPrm(cmd, &headPrm, &putPrm)
|
||||
|
||||
headPrm.SetRawFlag(true)
|
||||
|
@ -194,7 +197,7 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
sg, err := storagegroup.CollectMembers(sgHeadReceiver{
|
||||
cmd: cmd,
|
||||
key: pk,
|
||||
ownerID: ownerID,
|
||||
ownerID: *ownerID,
|
||||
prm: headPrm,
|
||||
}, cnr, members)
|
||||
common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
|
||||
|
@ -203,7 +206,7 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
common.ExitOnErr(cmd, "could not marshal storage group: %w", err)
|
||||
|
||||
obj := object.New()
|
||||
obj.SetContainerID(*cnr)
|
||||
obj.SetContainerID(cnr)
|
||||
obj.SetOwnerID(ownerID)
|
||||
obj.SetType(object.TypeStorageGroup)
|
||||
|
||||
|
@ -217,32 +220,34 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
cmd.Printf(" ID: %s\n CID: %s\n", res.ID(), cnr)
|
||||
}
|
||||
|
||||
func getSGID() (*oidSDK.ID, error) {
|
||||
var oid oidSDK.ID
|
||||
err := oid.DecodeString(sgID)
|
||||
func getSGID() (*oid.ID, error) {
|
||||
var obj oid.ID
|
||||
err := obj.DecodeString(sgID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse storage group ID: %w", err)
|
||||
}
|
||||
|
||||
return &oid, nil
|
||||
return &obj, nil
|
||||
}
|
||||
|
||||
func getSG(cmd *cobra.Command, _ []string) {
|
||||
cnr, err := getCID(cmd)
|
||||
var cnr cid.ID
|
||||
|
||||
err := readCID(cmd, &cnr)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
id, err := getSGID()
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
addr := addressSDK.NewAddress()
|
||||
addr.SetContainerID(*cnr)
|
||||
addr.SetObjectID(*id)
|
||||
var addr oid.Address
|
||||
addr.SetContainer(cnr)
|
||||
addr.SetObject(*id)
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
var prm internalclient.GetObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, addr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, id, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(addr)
|
||||
prm.SetPayloadWriter(buf)
|
||||
|
@ -263,20 +268,20 @@ func getSG(cmd *cobra.Command, _ []string) {
|
|||
cmd.Println("Members:")
|
||||
|
||||
for i := range members {
|
||||
cmd.Printf("\t%s\n", members[i].String())
|
||||
cmd.Printf("\t%s\n", members[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func listSG(cmd *cobra.Command, _ []string) {
|
||||
cnr, err := getCID(cmd)
|
||||
var cnr cid.ID
|
||||
|
||||
err := readCID(cmd, &cnr)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(*cnr)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareSessionPrm(cmd, cnr, nil, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(cnr)
|
||||
prm.SetFilters(storagegroup.SearchQuery())
|
||||
|
@ -289,41 +294,34 @@ func listSG(cmd *cobra.Command, _ []string) {
|
|||
cmd.Printf("Found %d storage groups.\n", len(ids))
|
||||
|
||||
for i := range ids {
|
||||
cmd.Println(ids[i].String())
|
||||
cmd.Println(ids[i])
|
||||
}
|
||||
}
|
||||
|
||||
func delSG(cmd *cobra.Command, _ []string) {
|
||||
cnr, err := getCID(cmd)
|
||||
var cnr cid.ID
|
||||
|
||||
err := readCID(cmd, &cnr)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
id, err := getSGID()
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
addr := addressSDK.NewAddress()
|
||||
addr.SetContainerID(*cnr)
|
||||
addr.SetObjectID(*id)
|
||||
var addr oid.Address
|
||||
addr.SetContainer(cnr)
|
||||
addr.SetObject(*id)
|
||||
|
||||
var prm internalclient.DeleteObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, addr, &prm)
|
||||
prepareSessionPrm(cmd, cnr, id, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetAddress(addr)
|
||||
|
||||
res, err := internalclient.DeleteObject(prm)
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
tombstone := res.TombstoneAddress()
|
||||
|
||||
var strID string
|
||||
|
||||
idTomb, ok := tombstone.ObjectID()
|
||||
if ok {
|
||||
strID = idTomb.String()
|
||||
} else {
|
||||
strID = "<empty>"
|
||||
}
|
||||
tomb := res.Tombstone()
|
||||
|
||||
cmd.Println("Storage group removed successfully.")
|
||||
cmd.Printf(" Tombstone: %s\n", strID)
|
||||
cmd.Printf(" Tombstone: %s\n", tomb)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue