Move changes from neofs-sdk-go #3
8 changed files with 80 additions and 24 deletions
|
@ -136,9 +136,10 @@ func (b Token) WriteToV2(m *acl.BearerToken) {
|
|||
}
|
||||
|
||||
// SetExp sets "exp" (expiration time) claim which identifies the
|
||||
// expiration time (in NeoFS epochs) on or after which the Token MUST NOT be
|
||||
// accepted for processing. The processing of the "exp" claim requires that the
|
||||
// current epoch MUST be before the expiration epoch listed in the "exp" claim.
|
||||
// expiration time (in NeoFS epochs) after which the Token MUST NOT be
|
||||
// accepted for processing. The processing of the "exp" claim requires
|
||||
// that the current epoch MUST be before or equal to the expiration epoch
|
||||
// listed in the "exp" claim.
|
||||
//
|
||||
// Naming is inspired by https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4.
|
||||
//
|
||||
|
@ -179,7 +180,7 @@ func (b *Token) SetIat(iat uint64) {
|
|||
//
|
||||
// See also SetExp, SetNbf, SetIat.
|
||||
func (b Token) InvalidAt(epoch uint64) bool {
|
||||
return !b.lifetimeSet || b.nbf > epoch || b.iat > epoch || b.exp <= epoch
|
||||
return !b.lifetimeSet || b.nbf > epoch || b.iat > epoch || b.exp < epoch
|
||||
}
|
||||
|
||||
// SetEACLTable sets eacl.Table that replaces the one from the issuer's
|
||||
|
|
|
@ -220,7 +220,7 @@ func TestToken_InvalidAt(t *testing.T) {
|
|||
require.True(t, val.InvalidAt(1))
|
||||
require.False(t, val.InvalidAt(2))
|
||||
require.False(t, val.InvalidAt(3))
|
||||
require.True(t, val.InvalidAt(4))
|
||||
require.False(t, val.InvalidAt(4))
|
||||
require.True(t, val.InvalidAt(5))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/acl"
|
||||
|
@ -27,6 +28,16 @@ type PrmObjectHash struct {
|
|||
csAlgo v2refs.ChecksumType
|
||||
|
||||
addr v2refs.Address
|
||||
|
||||
keySet bool
|
||||
key ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
// UseKey specifies private key to sign the requests.
|
||||
// If key is not provided, then Client default key is used.
|
||||
func (x *PrmObjectHash) UseKey(key ecdsa.PrivateKey) {
|
||||
x.keySet = true
|
||||
x.key = key
|
||||
}
|
||||
|
||||
// MarkLocal tells the server to execute the operation locally.
|
||||
|
@ -176,7 +187,12 @@ func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectH
|
|||
c.prepareRequest(&req, &prm.meta)
|
||||
req.SetBody(&prm.body)
|
||||
|
||||
err := signature.SignServiceMessage(&c.prm.key, &req)
|
||||
key := c.prm.key
|
||||
if prm.keySet {
|
||||
key = prm.key
|
||||
}
|
||||
|
||||
err := signature.SignServiceMessage(&key, &req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sign request: %w", err)
|
||||
}
|
||||
|
|
|
@ -33,12 +33,18 @@ func (t *Tombstone) ToV2() *tombstone.Tombstone {
|
|||
return (*tombstone.Tombstone)(t)
|
||||
}
|
||||
|
||||
// ExpirationEpoch return number of tombstone expiration epoch.
|
||||
// ExpirationEpoch returns the last NeoFS epoch
|
||||
// number of the tombstone lifetime.
|
||||
//
|
||||
// See also SetExpirationEpoch.
|
||||
func (t *Tombstone) ExpirationEpoch() uint64 {
|
||||
return (*tombstone.Tombstone)(t).GetExpirationEpoch()
|
||||
}
|
||||
|
||||
// SetExpirationEpoch sets number of tombstone expiration epoch.
|
||||
// SetExpirationEpoch sets the last NeoFS epoch
|
||||
// number of the tombstone lifetime.
|
||||
//
|
||||
// See also ExpirationEpoch.
|
||||
func (t *Tombstone) SetExpirationEpoch(v uint64) {
|
||||
(*tombstone.Tombstone)(t).SetExpirationEpoch(v)
|
||||
}
|
||||
|
|
30
pool/pool.go
30
pool/pool.go
|
@ -230,6 +230,7 @@ type wrapperPrm struct {
|
|||
streamTimeout time.Duration
|
||||
errorThreshold uint32
|
||||
responseInfoCallback func(sdkClient.ResponseMetaInfo) error
|
||||
poolRequestInfoCallback func(RequestInfo)
|
||||
}
|
||||
|
||||
// setAddress sets endpoint to connect in NeoFS network.
|
||||
|
@ -258,6 +259,11 @@ func (x *wrapperPrm) setErrorThreshold(threshold uint32) {
|
|||
x.errorThreshold = threshold
|
||||
}
|
||||
|
||||
// setPoolRequestCallback sets callback that will be invoked after every pool response.
|
||||
func (x *wrapperPrm) setPoolRequestCallback(f func(RequestInfo)) {
|
||||
x.poolRequestInfoCallback = f
|
||||
}
|
||||
|
||||
// setResponseInfoCallback sets callback that will be invoked after every response.
|
||||
func (x *wrapperPrm) setResponseInfoCallback(f func(sdkClient.ResponseMetaInfo) error) {
|
||||
x.responseInfoCallback = f
|
||||
|
@ -964,9 +970,16 @@ func (c *clientStatusMonitor) methodsStatus() []statusSnapshot {
|
|||
return result
|
||||
}
|
||||
|
||||
func (c *clientStatusMonitor) incRequests(elapsed time.Duration, method MethodIndex) {
|
||||
func (c *clientWrapper) incRequests(elapsed time.Duration, method MethodIndex) {
|
||||
methodStat := c.methods[method]
|
||||
methodStat.incRequests(elapsed)
|
||||
if c.prm.poolRequestInfoCallback != nil {
|
||||
c.prm.poolRequestInfoCallback(RequestInfo{
|
||||
Address: c.prm.address,
|
||||
Method: method,
|
||||
Elapsed: elapsed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *clientStatusMonitor) handleError(st apistatus.Status, err error) error {
|
||||
|
@ -991,6 +1004,13 @@ func (c *clientStatusMonitor) handleError(st apistatus.Status, err error) error
|
|||
// to the given endpoint.
|
||||
type clientBuilder = func(endpoint string) client
|
||||
|
||||
// RequestInfo groups info about pool request.
|
||||
type RequestInfo struct {
|
||||
Address string
|
||||
Method MethodIndex
|
||||
Elapsed time.Duration
|
||||
}
|
||||
|
||||
// InitParameters contains values used to initialize connection Pool.
|
||||
type InitParameters struct {
|
||||
key *ecdsa.PrivateKey
|
||||
|
@ -1002,6 +1022,7 @@ type InitParameters struct {
|
|||
sessionExpirationDuration uint64
|
||||
errorThreshold uint32
|
||||
nodeParams []NodeParam
|
||||
requestCallback func(RequestInfo)
|
||||
|
||||
clientBuilder clientBuilder
|
||||
}
|
||||
|
@ -1050,6 +1071,12 @@ func (x *InitParameters) SetErrorThreshold(threshold uint32) {
|
|||
x.errorThreshold = threshold
|
||||
}
|
||||
|
||||
// SetRequestCallback makes the pool client to pass RequestInfo for each
|
||||
// request to f. Nil (default) means ignore RequestInfo.
|
||||
func (x *InitParameters) SetRequestCallback(f func(RequestInfo)) {
|
||||
x.requestCallback = f
|
||||
}
|
||||
|
||||
// AddNode append information about the node to which you want to connect.
|
||||
func (x *InitParameters) AddNode(nodeParam NodeParam) {
|
||||
x.nodeParams = append(x.nodeParams, nodeParam)
|
||||
|
@ -1651,6 +1678,7 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) {
|
|||
prm.setDialTimeout(params.nodeDialTimeout)
|
||||
prm.setStreamTimeout(params.nodeStreamTimeout)
|
||||
prm.setErrorThreshold(params.errorThreshold)
|
||||
prm.setPoolRequestCallback(params.requestCallback)
|
||||
prm.setResponseInfoCallback(func(info sdkClient.ResponseMetaInfo) error {
|
||||
cache.updateEpoch(info.Epoch())
|
||||
return nil
|
||||
|
|
|
@ -219,10 +219,11 @@ func (x *commonData) unmarshalJSON(data []byte, r contextReader) error {
|
|||
return x.readFromV2(m, false, r)
|
||||
}
|
||||
|
||||
// SetExp sets "exp" (expiration time) claim which identifies the expiration time
|
||||
// (in NeoFS epochs) on or after which the session MUST NOT be accepted for
|
||||
// SetExp sets "exp" (expiration time) claim which identifies the expiration
|
||||
// time (in NeoFS epochs) after which the session MUST NOT be accepted for
|
||||
// processing. The processing of the "exp" claim requires that the current
|
||||
// epoch MUST be before the expiration epoch listed in the "exp" claim.
|
||||
// epoch MUST be before or equal to the expiration epoch listed in the "exp"
|
||||
// claim.
|
||||
//
|
||||
// Naming is inspired by https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4.
|
||||
//
|
||||
|
@ -258,7 +259,7 @@ func (x *commonData) SetIat(iat uint64) {
|
|||
}
|
||||
|
||||
func (x commonData) expiredAt(epoch uint64) bool {
|
||||
return !x.lifetimeSet || x.exp <= epoch
|
||||
return !x.lifetimeSet || x.exp < epoch
|
||||
}
|
||||
|
||||
// InvalidAt asserts "exp", "nbf" and "iat" claims.
|
||||
|
|
|
@ -153,7 +153,8 @@ func TestContainerProtocolV2(t *testing.T) {
|
|||
assert: func(val session.Container) {
|
||||
require.True(t, val.InvalidAt(1))
|
||||
require.False(t, val.InvalidAt(2))
|
||||
require.True(t, val.InvalidAt(3))
|
||||
require.False(t, val.InvalidAt(3))
|
||||
require.True(t, val.InvalidAt(4))
|
||||
},
|
||||
breakSign: func(m *v2session.Token) {
|
||||
lt := m.GetBody().GetLifetime()
|
||||
|
@ -410,7 +411,8 @@ func TestContainer_InvalidAt(t *testing.T) {
|
|||
require.True(t, x.InvalidAt(nbf-1))
|
||||
require.True(t, x.InvalidAt(iat-1))
|
||||
require.False(t, x.InvalidAt(iat))
|
||||
require.True(t, x.InvalidAt(exp))
|
||||
require.False(t, x.InvalidAt(exp))
|
||||
require.True(t, x.InvalidAt(exp+1))
|
||||
}
|
||||
|
||||
func TestContainer_ID(t *testing.T) {
|
||||
|
|
|
@ -175,7 +175,8 @@ func TestObjectProtocolV2(t *testing.T) {
|
|||
assert: func(val session.Object) {
|
||||
require.True(t, val.InvalidAt(1))
|
||||
require.False(t, val.InvalidAt(2))
|
||||
require.True(t, val.InvalidAt(3))
|
||||
require.False(t, val.InvalidAt(3))
|
||||
require.True(t, val.InvalidAt(4))
|
||||
},
|
||||
breakSign: func(m *v2session.Token) {
|
||||
lt := m.GetBody().GetLifetime()
|
||||
|
@ -520,7 +521,8 @@ func TestObject_InvalidAt(t *testing.T) {
|
|||
require.True(t, x.InvalidAt(nbf-1))
|
||||
require.True(t, x.InvalidAt(iat-1))
|
||||
require.False(t, x.InvalidAt(iat))
|
||||
require.True(t, x.InvalidAt(exp))
|
||||
require.False(t, x.InvalidAt(exp))
|
||||
require.True(t, x.InvalidAt(exp+1))
|
||||
}
|
||||
|
||||
func TestObject_ID(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue