[#1101] *: Adopt interface changes of API client from SDK library

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-01-21 19:53:06 +03:00 committed by Alex Vanin
parent 674f520da7
commit 4f3323f084
14 changed files with 94 additions and 246 deletions

View file

@ -3,7 +3,6 @@ package internal
import (
"context"
"io"
"math"
"github.com/nspcc-dev/neofs-sdk-go/accounting"
"github.com/nspcc-dev/neofs-sdk-go/client"
@ -18,12 +17,12 @@ import (
// BalanceOfPrm groups parameters of BalanceOf operation.
type BalanceOfPrm struct {
commonPrm
ownerIDPrm
client.GetBalancePrm
}
// BalanceOfRes groups resulting values of BalanceOf operation.
type BalanceOfRes struct {
cliRes *client.BalanceOfRes
cliRes *client.GetBalanceRes
}
// Balance returns current balance.
@ -35,9 +34,7 @@ func (x BalanceOfRes) Balance() *accounting.Decimal {
//
// Returns any error prevented the operation from completing correctly in error return.
func BalanceOf(prm BalanceOfPrm) (res BalanceOfRes, err error) {
res.cliRes, err = prm.cli.GetBalance(context.Background(), prm.ownerID,
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.GetBalance(context.Background(), prm.GetBalancePrm)
return
}
@ -45,7 +42,7 @@ func BalanceOf(prm BalanceOfPrm) (res BalanceOfRes, err error) {
// ListContainersPrm groups parameters of ListContainers operation.
type ListContainersPrm struct {
commonPrm
ownerIDPrm
client.ContainerListPrm
}
// ListContainersRes groups resulting values of ListContainers operation.
@ -55,16 +52,14 @@ type ListContainersRes struct {
// IDList returns list of identifiers of user's containers.
func (x ListContainersRes) IDList() []*cid.ID {
return x.cliRes.IDList()
return x.cliRes.Containers()
}
// ListContainers requests list of NeoFS user's containers.
//
// Returns any error prevented the operation from completing correctly in error return.
func ListContainers(prm ListContainersPrm) (res ListContainersRes, err error) {
res.cliRes, err = prm.cli.ListContainers(context.Background(), prm.ownerID,
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.ListContainers(context.Background(), prm.ContainerListPrm)
return
}
@ -72,14 +67,7 @@ func ListContainers(prm ListContainersPrm) (res ListContainersRes, err error) {
// PutContainerPrm groups parameters of PutContainer operation.
type PutContainerPrm struct {
commonPrm
sessionTokenPrm
cnr *container.Container
}
// SetContainer sets container structure.
func (x *PutContainerPrm) SetContainer(cnr *container.Container) {
x.cnr = cnr
client.ContainerPutPrm
}
// PutContainerRes groups resulting values of PutContainer operation.
@ -101,10 +89,7 @@ func (x PutContainerRes) ID() *cid.ID {
//
// Returns any error prevented the operation from completing correctly in error return.
func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) {
res.cliRes, err = prm.cli.PutContainer(context.Background(), prm.cnr,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
)
res.cliRes, err = prm.cli.PutContainer(context.Background(), prm.ContainerPutPrm)
return
}
@ -112,7 +97,12 @@ func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) {
// GetContainerPrm groups parameters of GetContainer operation.
type GetContainerPrm struct {
commonPrm
containerIDPrm
cliPrm client.ContainerGetPrm
}
// SetContainer sets identifier of the container to be read.
func (x *GetContainerPrm) SetContainer(id cid.ID) {
x.cliPrm.SetContainer(id)
}
// GetContainerRes groups resulting values of GetContainer operation.
@ -129,9 +119,7 @@ func (x GetContainerRes) Container() *container.Container {
//
// Returns any error prevented the operation from completing correctly in error return.
func GetContainer(prm GetContainerPrm) (res GetContainerRes, err error) {
res.cliRes, err = prm.cli.GetContainer(context.Background(), prm.cnrID,
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.GetContainer(context.Background(), prm.cliPrm)
return
}
@ -139,8 +127,7 @@ func GetContainer(prm GetContainerPrm) (res GetContainerRes, err error) {
// DeleteContainerPrm groups parameters of DeleteContainerPrm operation.
type DeleteContainerPrm struct {
commonPrm
sessionTokenPrm
containerIDPrm
client.ContainerDeletePrm
}
// DeleteContainerRes groups resulting values of DeleteContainer operation.
@ -155,10 +142,7 @@ type DeleteContainerRes struct{}
//
// Returns any error prevented the operation from completing correctly in error return.
func DeleteContainer(prm DeleteContainerPrm) (res DeleteContainerRes, err error) {
_, err = prm.cli.DeleteContainer(context.Background(), prm.cnrID,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
)
_, err = prm.cli.DeleteContainer(context.Background(), prm.ContainerDeletePrm)
return
}
@ -166,7 +150,7 @@ func DeleteContainer(prm DeleteContainerPrm) (res DeleteContainerRes, err error)
// EACLPrm groups parameters of EACL operation.
type EACLPrm struct {
commonPrm
containerIDPrm
client.EACLPrm
}
// EACLRes groups resulting values of EACL operation.
@ -183,9 +167,7 @@ func (x EACLRes) EACL() *eacl.Table {
//
// Returns any error prevented the operation from completing correctly in error return.
func EACL(prm EACLPrm) (res EACLRes, err error) {
res.cliRes, err = prm.cli.EACL(context.Background(), prm.cnrID,
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.EACL(context.Background(), prm.EACLPrm)
return
}
@ -193,14 +175,7 @@ func EACL(prm EACLPrm) (res EACLRes, err error) {
// SetEACLPrm groups parameters of SetEACL operation.
type SetEACLPrm struct {
commonPrm
sessionTokenPrm
eaclTable *eacl.Table
}
// SetEACLTable sets eACL table structure.
func (x *SetEACLPrm) SetEACLTable(table *eacl.Table) {
x.eaclTable = table
client.SetEACLPrm
}
// SetEACLRes groups resulting values of SetEACL operation.
@ -215,10 +190,7 @@ type SetEACLRes struct{}
//
// Returns any error prevented the operation from completing correctly in error return.
func SetEACL(prm SetEACLPrm) (res SetEACLRes, err error) {
_, err = prm.cli.SetEACL(context.Background(), prm.eaclTable,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
)
_, err = prm.cli.SetEACL(context.Background(), prm.SetEACLPrm)
return
}
@ -226,6 +198,7 @@ func SetEACL(prm SetEACLPrm) (res SetEACLRes, err error) {
// NetworkInfoPrm groups parameters of NetworkInfo operation.
type NetworkInfoPrm struct {
commonPrm
client.NetworkInfoPrm
}
// NetworkInfoRes groups resulting values of NetworkInfo operation.
@ -242,9 +215,7 @@ func (x NetworkInfoRes) NetworkInfo() *netmap.NetworkInfo {
//
// Returns any error prevented the operation from completing correctly in error return.
func NetworkInfo(prm NetworkInfoPrm) (res NetworkInfoRes, err error) {
res.cliRes, err = prm.cli.NetworkInfo(context.Background(),
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.NetworkInfo(context.Background(), prm.NetworkInfoPrm)
return
}
@ -252,6 +223,7 @@ func NetworkInfo(prm NetworkInfoPrm) (res NetworkInfoRes, err error) {
// NodeInfoPrm groups parameters of NodeInfo operation.
type NodeInfoPrm struct {
commonPrm
client.EndpointInfoPrm
}
// NodeInfoRes groups resulting values of NodeInfo operation.
@ -261,21 +233,19 @@ type NodeInfoRes struct {
// NodeInfo returns information about the node from netmap.
func (x NodeInfoRes) NodeInfo() *netmap.NodeInfo {
return x.cliRes.Info().NodeInfo()
return x.cliRes.NodeInfo()
}
// LatestVersion returns latest NeoFS API version in use.
func (x NodeInfoRes) LatestVersion() *version.Version {
return x.cliRes.Info().LatestVersion()
return x.cliRes.LatestVersion()
}
// NodeInfo requests information about the remote server from NeoFS netmap.
//
// Returns any error prevented the operation from completing correctly in error return.
func NodeInfo(prm NodeInfoPrm) (res NodeInfoRes, err error) {
res.cliRes, err = prm.cli.EndpointInfo(context.Background(),
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.EndpointInfo(context.Background(), prm.EndpointInfoPrm)
return
}
@ -283,6 +253,7 @@ func NodeInfo(prm NodeInfoPrm) (res NodeInfoRes, err error) {
// CreateSessionPrm groups parameters of CreateSession operation.
type CreateSessionPrm struct {
commonPrm
client.CreateSessionPrm
}
// CreateSessionRes groups resulting values of CreateSession operation.
@ -297,16 +268,14 @@ func (x CreateSessionRes) ID() []byte {
// SessionKey returns public session key in a binary format.
func (x CreateSessionRes) SessionKey() []byte {
return x.cliRes.SessionKey()
return x.cliRes.PublicKey()
}
// CreateSession opens new unlimited session with the remote node.
//
// Returns any error prevented the operation from completing correctly in error return.
func CreateSession(prm CreateSessionPrm) (res CreateSessionRes, err error) {
res.cliRes, err = prm.cli.CreateSession(context.Background(), math.MaxUint64,
client.WithKey(prm.privKey),
)
res.cliRes, err = prm.cli.CreateSession(context.Background(), prm.CreateSessionPrm)
return
}
@ -350,7 +319,6 @@ func PutObject(prm PutObjectPrm) (res PutObjectRes, err error) {
putPrm.WithPayloadReader(prm.rdr)
res.cliRes, err = prm.cli.PutObject(context.Background(), &putPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -383,7 +351,6 @@ func DeleteObject(prm DeleteObjectPrm) (res DeleteObjectRes, err error) {
delPrm.WithAddress(prm.objAddr)
res.cliRes, err = prm.cli.DeleteObject(context.Background(), &delPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -423,7 +390,6 @@ func GetObject(prm GetObjectPrm) (res GetObjectRes, err error) {
getPrm.WithRawFlag(prm.raw)
res.cliRes, err = prm.cli.GetObject(context.Background(), &getPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -472,7 +438,6 @@ func HeadObject(prm HeadObjectPrm) (res HeadObjectRes, err error) {
}
res.cliRes, err = prm.cli.HeadObject(context.Background(), &cliPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -513,7 +478,6 @@ func SearchObjects(prm SearchObjectsPrm) (res SearchObjectsRes, err error) {
cliPrm.WithContainerID(prm.cnrID)
res.cliRes, err = prm.cli.SearchObjects(context.Background(), &cliPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -574,7 +538,6 @@ func HashPayloadRanges(prm HashPayloadRangesPrm) (res HashPayloadRangesRes, err
}
res.cliRes, err = prm.cli.HashObjectPayloadRanges(context.Background(), &cliPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)
@ -615,7 +578,6 @@ func PayloadRange(prm PayloadRangePrm) (res PayloadRangeRes, err error) {
cliPrm.WithRange(prm.rng)
_, err = prm.cli.ObjectPayloadRangeData(context.Background(), &cliPrm, append(prm.opts,
client.WithKey(prm.privKey),
client.WithSession(prm.sessionToken),
client.WithBearer(prm.bearerToken),
)...)

View file

@ -1,13 +1,11 @@
package internal
import (
"crypto/ecdsa"
"io"
"github.com/nspcc-dev/neofs-sdk-go/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/token"
)
@ -16,8 +14,6 @@ import (
type commonPrm struct {
cli *client.Client
privKey *ecdsa.PrivateKey
}
// SetClient sets base client for NeoFS API communication.
@ -25,20 +21,6 @@ func (x *commonPrm) SetClient(cli *client.Client) {
x.cli = cli
}
// SetKey sets private key to sign the request(s).
func (x *commonPrm) SetKey(key *ecdsa.PrivateKey) {
x.privKey = key
}
type ownerIDPrm struct {
ownerID *owner.ID
}
// SetOwner sets identifier of NeoFS user.
func (x *ownerIDPrm) SetOwner(id *owner.ID) {
x.ownerID = id
}
type containerIDPrm struct {
cnrID *cid.ID
}

View file

@ -50,7 +50,7 @@ var accountingBalanceCmd = &cobra.Command{
var prm internalclient.BalanceOfPrm
prepareAPIClientWithKey(cmd, key, &prm)
prm.SetOwner(oid)
prm.SetAccount(*oid)
res, err := internalclient.BalanceOf(prm)
exitOnErr(cmd, errf("rpc error: %w", err))

View file

@ -125,7 +125,7 @@ var listContainersCmd = &cobra.Command{
var prm internalclient.ListContainersPrm
prepareAPIClientWithKey(cmd, key, &prm)
prm.SetOwner(oid)
prm.SetAccount(*oid)
res, err := internalclient.ListContainers(prm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -161,22 +161,35 @@ It will be stored in sidechain when inner ring will accepts it.`,
tok, err := getSessionToken(sessionTokenPath)
exitOnErr(cmd, err)
key, err := getKey()
exitOnErr(cmd, err)
var idOwner *owner.ID
if idOwner = tok.OwnerID(); idOwner == nil {
idOwner = owner.NewIDFromPublicKey(&key.PublicKey)
}
cnr := container.New()
cnr.SetVersion(versionSDK.Current())
cnr.SetPlacementPolicy(placementPolicy)
cnr.SetBasicACL(basicACL)
cnr.SetAttributes(attributes)
cnr.SetNonceUUID(nonce)
cnr.SetSessionToken(tok)
cnr.SetOwnerID(tok.OwnerID())
cnr.SetOwnerID(idOwner)
var (
putPrm internalclient.PutContainerPrm
getPrm internalclient.GetContainerPrm
)
prepareAPIClient(cmd, &putPrm, &getPrm)
putPrm.SetContainer(cnr)
putPrm.SetSessionToken(tok)
prepareAPIClientWithKey(cmd, key, &putPrm, &getPrm)
putPrm.SetContainer(*cnr)
if tok != nil {
putPrm.SetSessionToken(*tok)
}
res, err := internalclient.PutContainer(putPrm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -188,7 +201,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
if containerAwait {
cmd.Println("awaiting...")
getPrm.SetContainerID(id)
getPrm.SetContainer(*id)
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
@ -223,8 +236,11 @@ Only owner of the container has a permission to remove container.`,
)
prepareAPIClient(cmd, &delPrm, &getPrm)
delPrm.SetContainerID(id)
delPrm.SetSessionToken(tok)
delPrm.SetContainer(*id)
if tok != nil {
delPrm.SetSessionToken(*tok)
}
_, err = internalclient.DeleteContainer(delPrm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -234,7 +250,7 @@ Only owner of the container has a permission to remove container.`,
if containerAwait {
cmd.Println("awaiting...")
getPrm.SetContainerID(id)
getPrm.SetContainer(*id)
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
@ -301,7 +317,7 @@ var getContainerInfoCmd = &cobra.Command{
var prm internalclient.GetContainerPrm
prepareAPIClient(cmd, &prm)
prm.SetContainerID(id)
prm.SetContainer(*id)
res, err := internalclient.GetContainer(prm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -342,7 +358,7 @@ var getExtendedACLCmd = &cobra.Command{
var eaclPrm internalclient.EACLPrm
prepareAPIClient(cmd, &eaclPrm)
eaclPrm.SetContainerID(id)
eaclPrm.SetContainer(*id)
res, err := internalclient.EACL(eaclPrm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -405,8 +421,11 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
)
prepareAPIClient(cmd, &setEACLPrm, &getEACLPrm)
setEACLPrm.SetSessionToken(tok)
setEACLPrm.SetEACLTable(eaclTable)
setEACLPrm.SetTable(*eaclTable)
if tok != nil {
setEACLPrm.SetSessionToken(*tok)
}
_, err = internalclient.SetEACL(setEACLPrm)
exitOnErr(cmd, errf("rpc error: %w", err))
@ -417,7 +436,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
cmd.Println("awaiting...")
getEACLPrm.SetContainerID(id)
getEACLPrm.SetContainer(*id)
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)

View file

@ -303,7 +303,6 @@ func getEndpointAddress(endpointFlag string) (addr network.Address, err error) {
type clientWithKey interface {
SetClient(*client.Client)
SetKey(*ecdsa.PrivateKey)
}
// reads private key from command args and call prepareAPIClientWithKey with it.
@ -321,7 +320,6 @@ func prepareAPIClientWithKey(cmd *cobra.Command, key *ecdsa.PrivateKey, dst ...c
for _, d := range dst {
d.SetClient(cli)
d.SetKey(key)
}
}