[#189] client: Make PrmInit fields public for client

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2023-11-13 15:18:07 +03:00
parent ab75edd709
commit e91d40e250
21 changed files with 55 additions and 46 deletions

View file

@ -79,7 +79,7 @@ func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalance
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -144,21 +144,23 @@ func (c *Client) Close() error {
//
// See also Init.
type PrmInit struct {
disableFrostFSErrorResolution bool
DisableFrostFSErrorResolution bool
key ecdsa.PrivateKey
Key ecdsa.PrivateKey
cbRespInfo func(ResponseMetaInfo) error
ResponseInfoCallback func(ResponseMetaInfo) error
netMagic uint64
NetMagic uint64
}
// SetDefaultPrivateKey sets Client private key to be used for the protocol
// communication by default.
//
// Required for operations without custom key parametrization (see corresponding Prm* docs).
//
// Deprecated: Use PrmInit.Key instead.
func (x *PrmInit) SetDefaultPrivateKey(key ecdsa.PrivateKey) {
x.key = key
x.Key = key
}
// Deprecated: method is no-op. Option is default.
@ -169,14 +171,18 @@ func (x *PrmInit) ResolveFrostFSFailures() {
// FrostFS protocol only in resulting structure (see corresponding Res* docs).
// These errors are returned from each protocol operation. By default, statuses
// are resolved and returned as a Go built-in errors.
//
// Deprecated: Use PrmInit.DisableFrostFSErrorResolution instead.
func (x *PrmInit) DisableFrostFSFailuresResolution() {
x.disableFrostFSErrorResolution = true
x.DisableFrostFSErrorResolution = true
}
// SetResponseInfoCallback makes the Client to pass ResponseMetaInfo from each
// FrostFS server response to f. Nil (default) means ignore response meta info.
//
// Deprecated: Use PrmInit.ResponseInfoCallback instead.
func (x *PrmInit) SetResponseInfoCallback(f func(ResponseMetaInfo) error) {
x.cbRespInfo = f
x.ResponseInfoCallback = f
}
// PrmDial groups connection parameters for the Client.

View file

@ -29,8 +29,9 @@ func assertStatusErr(tb testing.TB, res interface{ Status() apistatus.Status })
}
func newClient(server frostFSAPIServer) *Client {
var prm PrmInit
prm.SetDefaultPrivateKey(*key)
prm := PrmInit{
Key: *key,
}
var c Client
c.Init(prm)

View file

@ -78,19 +78,19 @@ func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader)
meta.SetTTL(ttl)
meta.SetVersion(verV2)
meta.SetNetworkMagic(c.prm.netMagic)
meta.SetNetworkMagic(c.prm.NetMagic)
req.SetMetaHeader(meta)
}
// processResponse verifies response signature and converts status to an error if needed.
func (c *Client) processResponse(resp responseV2) (apistatus.Status, error) {
if c.prm.cbRespInfo != nil {
if c.prm.ResponseInfoCallback != nil {
rmi := ResponseMetaInfo{
key: resp.GetVerificationHeader().GetBodySignature().GetKey(),
epoch: resp.GetMetaHeader().GetEpoch(),
}
if err := c.prm.cbRespInfo(rmi); err != nil {
if err := c.prm.ResponseInfoCallback(rmi); err != nil {
return nil, fmt.Errorf("response callback error: %w", err)
}
}
@ -101,7 +101,7 @@ func (c *Client) processResponse(resp responseV2) (apistatus.Status, error) {
}
st := apistatus.FromStatusV2(resp.GetMetaHeader().GetStatus())
if !c.prm.disableFrostFSErrorResolution {
if !c.prm.DisableFrostFSErrorResolution {
return st, apistatus.ErrFromStatus(st)
}
return st, nil

View file

@ -52,7 +52,7 @@ func (prm *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteReque
var sig frostfscrypto.Signature
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.key), data)
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.Key), data)
if err != nil {
return nil, fmt.Errorf("calculate signature: %w", err)
}
@ -124,7 +124,7 @@ func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -85,7 +85,7 @@ func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResC
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -87,7 +87,7 @@ func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResCon
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -80,7 +80,7 @@ func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResC
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -64,7 +64,7 @@ func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, erro
var sig frostfscrypto.Signature
err := container.CalculateSignature(&sig, *x.Container, c.prm.key)
err := container.CalculateSignature(&sig, *x.Container, c.prm.Key)
if err != nil {
return nil, fmt.Errorf("calculate container signature: %w", err)
}
@ -132,7 +132,7 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -64,7 +64,7 @@ func (x *PrmContainerSetEACL) buildRequest(c *Client) (*v2container.SetExtendedA
var sig frostfscrypto.Signature
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.key), eaclV2.StableMarshal(nil))
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.Key), eaclV2.StableMarshal(nil))
if err != nil {
return nil, fmt.Errorf("calculate signature: %w", err)
}
@ -121,7 +121,7 @@ func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL)
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -77,7 +77,7 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounce
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -71,7 +71,7 @@ func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEnd
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}
@ -158,7 +158,7 @@ func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetwo
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}
@ -228,7 +228,7 @@ func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResN
req.SetBody(&body)
c.prepareRequest(&req, &meta)
err := signature.SignServiceMessage(&c.prm.key, &req)
err := signature.SignServiceMessage(&c.prm.Key, &req)
if err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -131,7 +131,7 @@ func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObj
return nil, err
}
key := c.prm.key
key := c.prm.Key
if prm.Key != nil {
key = *prm.Key
}

View file

@ -307,7 +307,7 @@ func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectRe
key := prm.Key
if key == nil {
key = &c.prm.key
key = &c.prm.Key
}
err = signature.SignServiceMessage(key, req)
@ -468,7 +468,7 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
return nil, err
}
key := c.prm.key
key := c.prm.Key
if prm.Key != nil {
key = *prm.Key
}
@ -776,7 +776,7 @@ func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*Obje
key := prm.Key
if key == nil {
key = &c.prm.key
key = &c.prm.Key
}
err = signature.SignServiceMessage(key, req)

View file

@ -172,7 +172,7 @@ func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectH
return nil, err
}
key := c.prm.key
key := c.prm.Key
if prm.Key != nil {
key = *prm.Key
}

View file

@ -28,7 +28,7 @@ func (c *Client) objectPutInitRaw(ctx context.Context, prm PrmObjectPutInit) (*o
return nil, fmt.Errorf("open stream: %w", err)
}
w.key = &c.prm.key
w.key = &c.prm.Key
if prm.Key != nil {
w.key = prm.Key
}

View file

@ -142,7 +142,7 @@ func (c *Client) ObjectPutSingle(ctx context.Context, prm PrmObjectPutSingle) (*
return nil, err
}
key := &c.prm.key
key := &c.prm.Key
if prm.Key != nil {
key = prm.Key
}

View file

@ -16,7 +16,7 @@ func (c *Client) objectPutInitTransformer(prm PrmObjectPutInit) (*objectWriterTr
client: c,
prm: prm,
}
key := &c.prm.key
key := &c.prm.Key
if prm.Key != nil {
key = prm.Key
}
@ -83,7 +83,7 @@ func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) err
wrt.WritePayloadChunk(ctx, o.Payload())
}
it.res, err = wrt.Close(ctx)
if err == nil && it.client.prm.disableFrostFSErrorResolution && !apistatus.IsSuccessful(it.res.st) {
if err == nil && it.client.prm.DisableFrostFSErrorResolution && !apistatus.IsSuccessful(it.res.st) {
err = apistatus.ErrFromStatus(it.res.st)
}
return err
@ -115,7 +115,7 @@ func (it *internalTarget) tryPutSingle(ctx context.Context, o *object.Object) (b
statusRes: res.statusRes,
obj: id,
}
if it.client.prm.disableFrostFSErrorResolution && !apistatus.IsSuccessful(it.res.st) {
if it.client.prm.DisableFrostFSErrorResolution && !apistatus.IsSuccessful(it.res.st) {
return true, apistatus.ErrFromStatus(it.res.st)
}
return true, nil

View file

@ -284,7 +284,7 @@ func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*Ob
key := prm.Key
if key == nil {
key = &c.prm.key
key = &c.prm.Key
}
err = signature.SignServiceMessage(key, req)

View file

@ -39,7 +39,7 @@ func (x *PrmSessionCreate) UseKey(key ecdsa.PrivateKey) {
}
func (x *PrmSessionCreate) buildRequest(c *Client) (*v2session.CreateRequest, error) {
ownerKey := c.prm.key.PublicKey
ownerKey := c.prm.Key.PublicKey
if x.Key != nil {
ownerKey = x.Key.PublicKey
}
@ -104,7 +104,7 @@ func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResS
return nil, err
}
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

View file

@ -316,9 +316,10 @@ func (x *wrapperPrm) setGRPCDialOptions(opts []grpc.DialOption) {
// newWrapper creates a clientWrapper that implements the client interface.
func newWrapper(prm wrapperPrm) *clientWrapper {
var cl sdkClient.Client
var prmInit sdkClient.PrmInit
prmInit.SetDefaultPrivateKey(prm.key)
prmInit.SetResponseInfoCallback(prm.responseInfoCallback)
prmInit := sdkClient.PrmInit{
Key: prm.key,
ResponseInfoCallback: prm.responseInfoCallback,
}
cl.Init(prmInit)
@ -371,9 +372,10 @@ func (c *clientWrapper) restartIfUnhealthy(ctx context.Context) (healthy, change
}
var cl sdkClient.Client
var prmInit sdkClient.PrmInit
prmInit.SetDefaultPrivateKey(c.prm.key)
prmInit.SetResponseInfoCallback(c.prm.responseInfoCallback)
prmInit := sdkClient.PrmInit{
Key: c.prm.key,
ResponseInfoCallback: c.prm.responseInfoCallback,
}
cl.Init(prmInit)