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"
|
||||
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/session"
|
||||
)
|
||||
|
||||
// interface of NeoFS API server. Exists for test purposes only.
|
||||
type neoFSAPIServer interface {
|
||||
createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, 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
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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.
|
||||
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)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
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"
|
||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||
|
@ -28,7 +29,11 @@ type serverNetMap struct {
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
"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"
|
||||
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
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.statusRes = &res
|
||||
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) {
|
||||
resp := r.(*v2session.CreateResponse)
|
||||
|
||||
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.setSessionKey(body.GetSessionKey())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue