[#747] client: Refactor PrmObjectPutInit usage

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2023-10-20 10:33:24 +03:00 committed by Evgenii Stratonikov
parent 12b7cf2533
commit 58b6224dd8
2 changed files with 16 additions and 33 deletions

View file

@ -387,30 +387,23 @@ func (x *PutObjectPrm) PrepareLocally() {
} }
func (x *PutObjectPrm) convertToSDKPrm(ctx context.Context) (client.PrmObjectPutInit, error) { func (x *PutObjectPrm) convertToSDKPrm(ctx context.Context) (client.PrmObjectPutInit, error) {
var putPrm client.PrmObjectPutInit putPrm := client.PrmObjectPutInit{
if !x.prepareLocally && x.sessionToken != nil { XHeaders: x.xHeaders,
putPrm.WithinSession(*x.sessionToken) 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 { if x.prepareLocally {
res, err := x.cli.NetworkInfo(ctx, client.PrmNetworkInfo{}) res, err := x.cli.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil { if err != nil {
return client.PrmObjectPutInit{}, err return client.PrmObjectPutInit{}, err
} }
putPrm.WithObjectMaxSize(res.Info().MaxObjectSize()) putPrm.MaxSize = res.Info().MaxObjectSize()
putPrm.WithEpochSource(epochSource(res.Info().CurrentEpoch())) putPrm.EpochSource = epochSource(res.Info().CurrentEpoch())
putPrm.WithoutHomomorphicHash(res.Info().HomomorphicHashingDisabled()) putPrm.WithoutHomomorphHash = res.Info().HomomorphicHashingDisabled()
} else {
putPrm.Session = x.sessionToken
} }
return putPrm, nil return putPrm, nil
} }

View file

@ -392,24 +392,14 @@ func PutObject(ctx context.Context, prm PutObjectPrm) (*PutObjectRes, error) {
ctx, span := tracing.StartSpanFromContext(ctx, "client.PutObject") ctx, span := tracing.StartSpanFromContext(ctx, "client.PutObject")
defer span.End() defer span.End()
var prmCli client.PrmObjectPutInit prmCli := client.PrmObjectPutInit{
XHeaders: prm.xHeaders,
prmCli.MarkLocal() BearerToken: prm.tokenBearer,
Session: prm.tokenSession,
if prm.key != nil { Local: true,
prmCli.UseKey(*prm.key) 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) w, err := prm.cli.ObjectPutInit(ctx, prmCli)
if err != nil { if err != nil {
return nil, fmt.Errorf("init object writing on client: %w", err) return nil, fmt.Errorf("init object writing on client: %w", err)