[#1211] neofs-cli: Specify address in session token
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
1b5cb2dfe2
commit
99749ea042
3 changed files with 40 additions and 18 deletions
|
@ -19,6 +19,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"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/policy"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
|
@ -276,7 +277,9 @@ var listContainerObjectsCmd = &cobra.Command{
|
|||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(id)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(id)
|
||||
prm.SetFilters(*filters)
|
||||
|
|
|
@ -283,22 +283,23 @@ type clientKeySession interface {
|
|||
SetSessionToken(*session.Token)
|
||||
}
|
||||
|
||||
func prepareSessionPrm(cmd *cobra.Command, prms ...clientKeySession) {
|
||||
func prepareSessionPrm(cmd *cobra.Command, addr *addressSDK.Address, prms ...clientKeySession) {
|
||||
key, err := getKey()
|
||||
exitOnErr(cmd, errf("get private key: %w", err))
|
||||
|
||||
prepareSessionPrmWithKey(cmd, key, prms...)
|
||||
prepareSessionPrmWithKey(cmd, addr, key, prms...)
|
||||
}
|
||||
|
||||
func prepareSessionPrmWithKey(cmd *cobra.Command, key *ecdsa.PrivateKey, prms ...clientKeySession) {
|
||||
func prepareSessionPrmWithKey(cmd *cobra.Command, addr *addressSDK.Address, key *ecdsa.PrivateKey, prms ...clientKeySession) {
|
||||
ownerID, err := getOwnerID(key)
|
||||
exitOnErr(cmd, errf("owner ID from key: %w", err))
|
||||
|
||||
prepareSessionPrmWithOwner(cmd, key, ownerID, prms...)
|
||||
prepareSessionPrmWithOwner(cmd, addr, key, ownerID, prms...)
|
||||
}
|
||||
|
||||
func prepareSessionPrmWithOwner(
|
||||
cmd *cobra.Command,
|
||||
addr *addressSDK.Address,
|
||||
key *ecdsa.PrivateKey,
|
||||
ownerID *owner.ID,
|
||||
prms ...clientKeySession,
|
||||
|
@ -348,6 +349,7 @@ func prepareSessionPrmWithOwner(
|
|||
default:
|
||||
panic("invalid client parameter type")
|
||||
}
|
||||
objectContext.ApplyTo(addr)
|
||||
|
||||
tok := session.NewToken()
|
||||
tok.SetID(sessionRes.ID())
|
||||
|
@ -435,7 +437,9 @@ func putObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.PutObjectPrm
|
||||
|
||||
prepareSessionPrmWithOwner(cmd, key, ownerID, &prm)
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(cid)
|
||||
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, key, ownerID, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetHeader(obj.Object())
|
||||
prm.SetPayloadReader(f)
|
||||
|
@ -453,7 +457,7 @@ func deleteObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.DeleteObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
|
||||
|
@ -487,7 +491,7 @@ func getObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.GetObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
prm.SetPayloadWriter(out)
|
||||
|
@ -521,7 +525,7 @@ func getObjectHeader(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.HeadObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
prm.SetMainOnlyFlag(mainOnly)
|
||||
|
@ -548,7 +552,9 @@ func searchObject(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(cid)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(cid)
|
||||
prm.SetFilters(sf)
|
||||
|
@ -591,7 +597,7 @@ func getObjectHash(cmd *cobra.Command, _ []string) {
|
|||
objPrms = append(objPrms, &headPrm)
|
||||
}
|
||||
|
||||
prepareSessionPrm(cmd, sesPrms...)
|
||||
prepareSessionPrm(cmd, objAddr, sesPrms...)
|
||||
prepareObjectPrm(cmd, objPrms...)
|
||||
|
||||
tz := typ == hashTz
|
||||
|
@ -983,7 +989,7 @@ func getObjectRange(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.PayloadRangePrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, objAddr, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(objAddr)
|
||||
prm.SetRange(ranges[0])
|
||||
|
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
|
@ -11,6 +12,7 @@ import (
|
|||
objectSDK "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"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||
storagegroupAPI "github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -135,10 +137,14 @@ func init() {
|
|||
}
|
||||
|
||||
type sgHeadReceiver struct {
|
||||
cmd *cobra.Command
|
||||
key *ecdsa.PrivateKey
|
||||
ownerID *owner.ID
|
||||
prm internalclient.HeadObjectPrm
|
||||
}
|
||||
|
||||
func (c sgHeadReceiver) Head(addr *addressSDK.Address) (interface{}, error) {
|
||||
prepareSessionPrmWithOwner(c.cmd, addr, c.key, c.ownerID, &c.prm)
|
||||
c.prm.SetAddress(addr)
|
||||
|
||||
res, err := internalclient.HeadObject(c.prm)
|
||||
|
@ -181,12 +187,17 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
putPrm internalclient.PutObjectPrm
|
||||
)
|
||||
|
||||
prepareSessionPrmWithOwner(cmd, key, ownerID, &headPrm, &putPrm)
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(cid)
|
||||
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, key, ownerID, &putPrm)
|
||||
prepareObjectPrm(cmd, &headPrm, &putPrm)
|
||||
|
||||
headPrm.SetRawFlag(true)
|
||||
|
||||
sg, err := storagegroup.CollectMembers(sgHeadReceiver{
|
||||
cmd: cmd,
|
||||
key: key,
|
||||
ownerID: ownerID,
|
||||
prm: headPrm,
|
||||
}, cid, members)
|
||||
exitOnErr(cmd, errf("could not collect storage group members: %w", err))
|
||||
|
@ -234,7 +245,7 @@ func getSG(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.GetObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, addr, &prm)
|
||||
prepareObjectPrmRaw(cmd, &prm)
|
||||
prm.SetAddress(addr)
|
||||
prm.SetPayloadWriter(buf)
|
||||
|
@ -266,7 +277,9 @@ func listSG(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.SearchObjectsPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
sessionObjectCtxAddress := addressSDK.NewAddress()
|
||||
sessionObjectCtxAddress.SetContainerID(cid)
|
||||
prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetContainerID(cid)
|
||||
prm.SetFilters(storagegroup.SearchQuery())
|
||||
|
@ -296,7 +309,7 @@ func delSG(cmd *cobra.Command, _ []string) {
|
|||
|
||||
var prm internalclient.DeleteObjectPrm
|
||||
|
||||
prepareSessionPrm(cmd, &prm)
|
||||
prepareSessionPrm(cmd, addr, &prm)
|
||||
prepareObjectPrm(cmd, &prm)
|
||||
prm.SetAddress(addr)
|
||||
|
||||
|
|
Loading…
Reference in a new issue