From 1c655816c9d3015e04c20445e4a4a1d8a19f9a84 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Fri, 20 Oct 2023 10:33:24 +0300 Subject: [PATCH] [#747] client: Refactor PrmObjectPutInit usage Signed-off-by: Airat Arifullin --- cmd/frostfs-cli/internal/client/client.go | 27 +++++++------------ pkg/services/object/internal/client/client.go | 22 +++++---------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index 9cb7c816..b370ff3a 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -387,30 +387,23 @@ func (x *PutObjectPrm) PrepareLocally() { } func (x *PutObjectPrm) convertToSDKPrm(ctx context.Context) (client.PrmObjectPutInit, error) { - var putPrm client.PrmObjectPutInit - if !x.prepareLocally && x.sessionToken != nil { - putPrm.WithinSession(*x.sessionToken) + putPrm := client.PrmObjectPutInit{ + XHeaders: x.xHeaders, + BearerToken: x.bearerToken, + Local: x.local, + CopiesNumber: x.copyNum, } - if x.bearerToken != nil { - putPrm.WithBearerToken(*x.bearerToken) - } - - if x.local { - putPrm.MarkLocal() - } - - putPrm.WithXHeaders(x.xHeaders...) - putPrm.SetCopiesNumberByVectors(x.copyNum) - if x.prepareLocally { res, err := x.cli.NetworkInfo(ctx, client.PrmNetworkInfo{}) if err != nil { return client.PrmObjectPutInit{}, err } - putPrm.WithObjectMaxSize(res.Info().MaxObjectSize()) - putPrm.WithEpochSource(epochSource(res.Info().CurrentEpoch())) - putPrm.WithoutHomomorphicHash(res.Info().HomomorphicHashingDisabled()) + putPrm.MaxSize = res.Info().MaxObjectSize() + putPrm.EpochSource = epochSource(res.Info().CurrentEpoch()) + putPrm.WithoutHomomorphHash = res.Info().HomomorphicHashingDisabled() + } else { + putPrm.Session = x.sessionToken } return putPrm, nil } diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index 27548862..e0a7e562 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -392,24 +392,14 @@ func PutObject(ctx context.Context, prm PutObjectPrm) (*PutObjectRes, error) { ctx, span := tracing.StartSpanFromContext(ctx, "client.PutObject") defer span.End() - var prmCli client.PrmObjectPutInit - - prmCli.MarkLocal() - - if prm.key != nil { - prmCli.UseKey(*prm.key) + prmCli := client.PrmObjectPutInit{ + XHeaders: prm.xHeaders, + BearerToken: prm.tokenBearer, + Session: prm.tokenSession, + Local: true, + Key: prm.key, } - if prm.tokenSession != nil { - prmCli.WithinSession(*prm.tokenSession) - } - - if prm.tokenBearer != nil { - prmCli.WithBearerToken(*prm.tokenBearer) - } - - prmCli.WithXHeaders(prm.xHeaders...) - w, err := prm.cli.ObjectPutInit(ctx, prmCli) if err != nil { return nil, fmt.Errorf("init object writing on client: %w", err)