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