forked from TrueCloudLab/frostfs-sdk-go
[#83] pkg/client: Support status returns
Make all `Client` methods to return structured values and error. Parse v2 status messages in all RPC and provide status getter from all result structures. Returns status failures as status result instead of error. Interface changes: * all methods return `<method>Res` structure; * rename some methods to be more clear; * unify TZ and SHA256 objecy payload hashing in single method. Behavior changes: * client doesn't verify object header structure received via Object.Head. If the caller was tied to verification, now it must do it explicitly. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9dcff95a29
commit
bf78cddf69
8 changed files with 835 additions and 372 deletions
|
@ -10,18 +10,41 @@ import (
|
|||
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
)
|
||||
|
||||
// Session contains session-related methods.
|
||||
type Session interface {
|
||||
// CreateSession creates session using provided expiration time.
|
||||
CreateSession(context.Context, uint64, ...CallOption) (*session.Token, error)
|
||||
CreateSession(context.Context, uint64, ...CallOption) (*CreateSessionRes, error)
|
||||
}
|
||||
|
||||
var errMalformedResponseBody = errors.New("malformed response body")
|
||||
|
||||
func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*session.Token, error) {
|
||||
type CreateSessionRes struct {
|
||||
statusRes
|
||||
|
||||
id []byte
|
||||
|
||||
sessionKey []byte
|
||||
}
|
||||
|
||||
func (x *CreateSessionRes) setID(id []byte) {
|
||||
x.id = id
|
||||
}
|
||||
|
||||
func (x CreateSessionRes) ID() []byte {
|
||||
return x.id
|
||||
}
|
||||
|
||||
func (x *CreateSessionRes) setSessionKey(key []byte) {
|
||||
x.sessionKey = key
|
||||
}
|
||||
|
||||
func (x CreateSessionRes) SessionKey() []byte {
|
||||
return x.sessionKey
|
||||
}
|
||||
|
||||
func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*CreateSessionRes, error) {
|
||||
// apply all available options
|
||||
callOptions := c.defaultCallOptions()
|
||||
|
||||
|
@ -55,25 +78,30 @@ func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts
|
|||
return nil, fmt.Errorf("transport error: %w", err)
|
||||
}
|
||||
|
||||
// handle response meta info
|
||||
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
res = new(CreateSessionRes)
|
||||
procPrm processResponseV2Prm
|
||||
procRes processResponseV2Res
|
||||
)
|
||||
|
||||
err = v2signature.VerifyServiceMessage(resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't verify response message: %w", err)
|
||||
procPrm.callOpts = callOptions
|
||||
procPrm.resp = resp
|
||||
|
||||
procRes.statusRes = res
|
||||
|
||||
// process response in general
|
||||
if c.processResponseV2(&procRes, procPrm) {
|
||||
if procRes.cliErr != nil {
|
||||
return nil, procRes.cliErr
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
body := resp.GetBody()
|
||||
if body == nil {
|
||||
return nil, errMalformedResponseBody
|
||||
}
|
||||
|
||||
sessionToken := session.NewToken()
|
||||
sessionToken.SetID(body.GetID())
|
||||
sessionToken.SetSessionKey(body.GetSessionKey())
|
||||
sessionToken.SetOwnerID(ownerID)
|
||||
res.setID(body.GetID())
|
||||
res.setSessionKey(body.GetSessionKey())
|
||||
|
||||
return sessionToken, nil
|
||||
return res, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue