frostfs-api-go-pogpp/pkg/client/client.go
Leonard Lyubich b2ba0eef07 [#180] sdk/client: Implement methods that attach tokens to Client
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-28 12:15:49 +03:00

55 lines
930 B
Go

package client
import (
"crypto/ecdsa"
"errors"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
)
type (
Client struct {
key *ecdsa.PrivateKey
remoteNode TransportInfo
opts *clientOptions
sessionToken *token.SessionToken
bearerToken *token.BearerToken
}
TransportProtocol uint32
TransportInfo struct {
Version *pkg.Version
Protocol TransportProtocol
}
)
const (
Unknown TransportProtocol = iota
GRPC
)
var (
unsupportedProtocolErr = errors.New("unsupported transport protocol")
)
func New(key *ecdsa.PrivateKey, opts ...ClientOption) (*Client, error) {
clientOptions := defaultClientOptions()
for i := range opts {
opts[i].apply(clientOptions)
}
// todo: make handshake to check latest version
return &Client{
key: key,
remoteNode: TransportInfo{
Version: pkg.SDKVersion(),
Protocol: GRPC,
},
opts: clientOptions,
}, nil
}