Compare commits

...

2 commits

Author SHA1 Message Date
1c655816c9 [#747] client: Refactor PrmObjectPutInit usage
All checks were successful
DCO action / DCO (pull_request) Successful in 3m58s
Vulncheck / Vulncheck (pull_request) Successful in 4m55s
Build / Build Components (1.20) (pull_request) Successful in 5m33s
Build / Build Components (1.21) (pull_request) Successful in 5m29s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m5s
Tests and linters / Tests with -race (pull_request) Successful in 6m31s
Tests and linters / Staticcheck (pull_request) Successful in 6m58s
Tests and linters / Lint (pull_request) Successful in 7m50s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m9s
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2023-10-20 10:33:24 +03:00
3664253588 [#747] client: Refactor PrmObjectPutSingle usage
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2023-10-20 10:25:23 +03:00
4 changed files with 24 additions and 51 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
} }

2
go.mod
View file

@ -6,7 +6,7 @@ require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.0 git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.0
git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.0 git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.0
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230928142024-84b9d29fc98c git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231019083813-5804128ff3d5
git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/hrw v1.2.1
git.frostfs.info/TrueCloudLab/tzhash v1.8.0 git.frostfs.info/TrueCloudLab/tzhash v1.8.0
github.com/cheggaaa/pb v1.0.29 github.com/cheggaaa/pb v1.0.29

BIN
go.sum

Binary file not shown.

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)
@ -449,25 +439,15 @@ func PutObjectSingle(ctx context.Context, prm PutObjectPrm) (*PutObjectRes, erro
return nil, errors.New("missing object id") return nil, errors.New("missing object id")
} }
var prmCli client.PrmObjectPutSingle prmCli := client.PrmObjectPutSingle{
XHeaders: prm.xHeaders,
prmCli.ExecuteLocal() BearerToken: prm.tokenBearer,
Session: prm.tokenSession,
if prm.key != nil { Local: true,
prmCli.UseKey(prm.key) Key: prm.key,
Object: prm.obj,
} }
if prm.tokenSession != nil {
prmCli.WithinSession(*prm.tokenSession)
}
if prm.tokenBearer != nil {
prmCli.WithBearerToken(*prm.tokenBearer)
}
prmCli.WithXHeaders(prm.xHeaders...)
prmCli.SetObject(prm.obj.ToV2())
res, err := prm.cli.ObjectPutSingle(ctx, prmCli) res, err := prm.cli.ObjectPutSingle(ctx, prmCli)
if err != nil { if err != nil {
ReportError(prm.cli, err) ReportError(prm.cli, err)