[#180] sdk/client: Implement methods that attach tokens to Client

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-27 15:55:19 +03:00 committed by Alex Vanin
parent 805ad54f41
commit b2ba0eef07
3 changed files with 23 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
)
type (
@ -13,6 +14,10 @@ type (
remoteNode TransportInfo
opts *clientOptions
sessionToken *token.SessionToken
bearerToken *token.BearerToken
}
TransportProtocol uint32

View file

@ -62,6 +62,8 @@ func (c Client) defaultCallOptions() callOptions {
return callOptions{
ttl: 2,
version: pkg.SDKVersion(),
session: c.sessionToken,
bearer: c.bearerToken,
}
}

View file

@ -110,3 +110,19 @@ func v2SessionClientFromOptions(opts *clientOptions) (cli *v2session.Client, err
return cli, nil
}
// AttachSessionToken attaches session token to client.
//
// Provided token is attached to all requests without WithSession option.
// Use WithSession(nil) option in order to send request without session token.
func (c *Client) AttachSessionToken(token *token.SessionToken) {
c.sessionToken = token
}
// AttachBearerToken attaches bearer token to client.
//
// Provided bearer is attached to all requests without WithBearer option.
// Use WithBearer(nil) option in order to send request without bearer token.
func (c *Client) AttachBearerToken(token *token.BearerToken) {
c.bearerToken = token
}