forked from TrueCloudLab/frostfs-sdk-go
client: Set contextCall.err if missed session params
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
c97f834c6b
commit
0c7bfc2afe
4 changed files with 51 additions and 4 deletions
|
@ -7,10 +7,13 @@ import (
|
||||||
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
// interface of NeoFS API server. Exists for test purposes only.
|
// interface of NeoFS API server. Exists for test purposes only.
|
||||||
type neoFSAPIServer interface {
|
type neoFSAPIServer interface {
|
||||||
|
createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, error)
|
||||||
|
|
||||||
netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error)
|
netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,3 +36,12 @@ func (x *coreServer) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRe
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *coreServer) createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, error) {
|
||||||
|
resp, err := rpcapi.CreateSession(cli, req, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, rpcErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
|
@ -4,9 +4,30 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errMissingResponseField missingResponseFieldErr
|
||||||
|
)
|
||||||
|
|
||||||
|
type missingResponseFieldErr struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e missingResponseFieldErr) Error() string {
|
||||||
|
return fmt.Sprintf("missing %s field in the response", e.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e missingResponseFieldErr) Is(target error) bool {
|
||||||
|
switch target.(type) {
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
case missingResponseFieldErr, *missingResponseFieldErr:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// returns error describing missing field with the given name.
|
// returns error describing missing field with the given name.
|
||||||
func newErrMissingResponseField(name string) error {
|
func newErrMissingResponseField(name string) error {
|
||||||
return fmt.Errorf("missing %s field in the response", name)
|
return missingResponseFieldErr{name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns error describing invalid field (according to the NeoFS protocol)
|
// returns error describing invalid field (according to the NeoFS protocol)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||||
|
@ -28,7 +29,11 @@ type serverNetMap struct {
|
||||||
signer neofscrypto.Signer
|
signer neofscrypto.Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *serverNetMap) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
|
func (x *serverNetMap) createSession(*client.Client, *session.CreateRequest, ...client.CallOption) (*session.CreateResponse, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *serverNetMap) netMapSnapshot(_ context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
|
||||||
err := verifyServiceMessage(&req)
|
err := verifyServiceMessage(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||||
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||||
|
@ -116,13 +115,23 @@ func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResS
|
||||||
cc.req = &req
|
cc.req = &req
|
||||||
cc.statusRes = &res
|
cc.statusRes = &res
|
||||||
cc.call = func() (responseV2, error) {
|
cc.call = func() (responseV2, error) {
|
||||||
return rpcapi.CreateSession(&c.c, &req, client.WithContext(ctx))
|
return c.server.createSession(&c.c, &req, client.WithContext(ctx))
|
||||||
}
|
}
|
||||||
cc.result = func(r responseV2) {
|
cc.result = func(r responseV2) {
|
||||||
resp := r.(*v2session.CreateResponse)
|
resp := r.(*v2session.CreateResponse)
|
||||||
|
|
||||||
body := resp.GetBody()
|
body := resp.GetBody()
|
||||||
|
|
||||||
|
if len(body.GetID()) == 0 {
|
||||||
|
cc.err = newErrMissingResponseField("session id")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(body.GetSessionKey()) == 0 {
|
||||||
|
cc.err = newErrMissingResponseField("session key")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
res.setID(body.GetID())
|
res.setID(body.GetID())
|
||||||
res.setSessionKey(body.GetSessionKey())
|
res.setSessionKey(body.GetSessionKey())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue