From e91d40e250cbf6453c6b9c1655df1a08d53b1dd3 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Mon, 13 Nov 2023 15:18:07 +0300 Subject: [PATCH] [#189] client: Make PrmInit fields public for client Signed-off-by: Airat Arifullin --- client/accounting.go | 2 +- client/client.go | 20 +++++++++++++------- client/client_test.go | 5 +++-- client/common.go | 8 ++++---- client/container_delete.go | 4 ++-- client/container_eacl.go | 2 +- client/container_get.go | 2 +- client/container_list.go | 2 +- client/container_put.go | 4 ++-- client/container_set_eacl.go | 4 ++-- client/container_space.go | 2 +- client/netmap.go | 6 +++--- client/object_delete.go | 2 +- client/object_get.go | 6 +++--- client/object_hash.go | 2 +- client/object_put_raw.go | 2 +- client/object_put_single.go | 2 +- client/object_put_transformer.go | 6 +++--- client/object_search.go | 2 +- client/session.go | 4 ++-- pool/pool.go | 14 ++++++++------ 21 files changed, 55 insertions(+), 46 deletions(-) diff --git a/client/accounting.go b/client/accounting.go index 402554f2..d0aa6539 100644 --- a/client/accounting.go +++ b/client/accounting.go @@ -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) } diff --git a/client/client.go b/client/client.go index ba57b41d..c111f02f 100644 --- a/client/client.go +++ b/client/client.go @@ -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. diff --git a/client/client_test.go b/client/client_test.go index 16f66e2d..1f055444 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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) diff --git a/client/common.go b/client/common.go index 0df18063..c67084ad 100644 --- a/client/common.go +++ b/client/common.go @@ -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 diff --git a/client/container_delete.go b/client/container_delete.go index f750c902..6d4b3450 100644 --- a/client/container_delete.go +++ b/client/container_delete.go @@ -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) } diff --git a/client/container_eacl.go b/client/container_eacl.go index d577b7a7..87d32d1b 100644 --- a/client/container_eacl.go +++ b/client/container_eacl.go @@ -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) } diff --git a/client/container_get.go b/client/container_get.go index 4477973c..a6dd6f2c 100644 --- a/client/container_get.go +++ b/client/container_get.go @@ -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) } diff --git a/client/container_list.go b/client/container_list.go index ebe27c3b..0fb91c22 100644 --- a/client/container_list.go +++ b/client/container_list.go @@ -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) } diff --git a/client/container_put.go b/client/container_put.go index 6ff4e5f3..e5b8f18e 100644 --- a/client/container_put.go +++ b/client/container_put.go @@ -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) } diff --git a/client/container_set_eacl.go b/client/container_set_eacl.go index 8ad808f2..b1493348 100644 --- a/client/container_set_eacl.go +++ b/client/container_set_eacl.go @@ -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) } diff --git a/client/container_space.go b/client/container_space.go index 793f5f4d..dda5acc4 100644 --- a/client/container_space.go +++ b/client/container_space.go @@ -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) } diff --git a/client/netmap.go b/client/netmap.go index c06f9404..f2c2e064 100644 --- a/client/netmap.go +++ b/client/netmap.go @@ -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) } diff --git a/client/object_delete.go b/client/object_delete.go index 3f72e0cb..a9fe8e86 100644 --- a/client/object_delete.go +++ b/client/object_delete.go @@ -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 } diff --git a/client/object_get.go b/client/object_get.go index 03b91d22..363c1ec0 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -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) diff --git a/client/object_hash.go b/client/object_hash.go index e65e9480..108e0ce0 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -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 } diff --git a/client/object_put_raw.go b/client/object_put_raw.go index 06690522..dd210a8c 100644 --- a/client/object_put_raw.go +++ b/client/object_put_raw.go @@ -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 } diff --git a/client/object_put_single.go b/client/object_put_single.go index 0ae6bf8e..8eaeca99 100644 --- a/client/object_put_single.go +++ b/client/object_put_single.go @@ -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 } diff --git a/client/object_put_transformer.go b/client/object_put_transformer.go index 357e94f0..c671b553 100644 --- a/client/object_put_transformer.go +++ b/client/object_put_transformer.go @@ -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 diff --git a/client/object_search.go b/client/object_search.go index 760a6d06..aa02542b 100644 --- a/client/object_search.go +++ b/client/object_search.go @@ -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) diff --git a/client/session.go b/client/session.go index 03ed5e8b..b49c67bc 100644 --- a/client/session.go +++ b/client/session.go @@ -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) } diff --git a/pool/pool.go b/pool/pool.go index c871689a..da8f0992 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -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)