forked from TrueCloudLab/frostfs-node
[#747] client: Refactor PrmObjectPutInit usage
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
12b7cf2533
commit
58b6224dd8
2 changed files with 16 additions and 33 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue