Skip to content

Commit

Permalink
cli: add dump-bin-put
Browse files Browse the repository at this point in the history
This command is used for keep container with blocks for
blockfetcher updated.

Close #3578

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Sep 27, 2024
1 parent 9a38360 commit 13e075a
Show file tree
Hide file tree
Showing 2 changed files with 401 additions and 0 deletions.
364 changes: 364 additions & 0 deletions cli/server/dump_bin_put.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,364 @@
package server

import (
"bytes"
"context"
"fmt"
"log"
"strconv"
"sync"
"time"

"github.com/google/uuid"
"github.com/nspcc-dev/neo-go/cli/cmdargs"
"github.com/nspcc-dev/neo-go/cli/options"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/services/oracle/neofs"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-sdk-go/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/object/slicer"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/urfave/cli/v2"
)

const (
searchBatchSize = 10000 // Number of objects to search in a batch for finding max block in container.
maxParallelSearches = 40 // Control the number of concurrent searches for index files generation.
indexFileSize = 128000 // Size of each index file.
)

func downloadPut(ctx *cli.Context) error {
if err := cmdargs.EnsureNone(ctx); err != nil {
return err

Check warning on line 39 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L37-L39

Added lines #L37 - L39 were not covered by tests
}

rpcNeoFS := ctx.String("rpc-neofs")
containerIDStr := ctx.String("container")
attribute := ctx.String("block-attribute")
indexFileAttribute := ctx.String("index-attribute")
acc, _, err := options.GetAccFromContext(ctx)
if err != nil {
return fmt.Errorf("failed to load wallet: %w", err)

Check warning on line 48 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L42-L48

Added lines #L42 - L48 were not covered by tests
}

var containerID cid.ID
if err = containerID.DecodeString(containerIDStr); err != nil {
return fmt.Errorf("failed to decode container ID: %w", err)

Check warning on line 53 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L51-L53

Added lines #L51 - L53 were not covered by tests
}

clientSDK, err := neofs.GetSDKClient(context.Background(), rpcNeoFS, 10*time.Minute)
if err != nil {
return fmt.Errorf("failed to create NeoFS client: %w", err)

Check warning on line 58 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L56-L58

Added lines #L56 - L58 were not covered by tests
}
defer clientSDK.Close()

Check warning on line 60 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L60

Added line #L60 was not covered by tests

sessionToken, err := createSessionToken(*acc, containerID)
if err != nil {
return fmt.Errorf("failed to create session token: %w", err)

Check warning on line 64 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L62-L64

Added lines #L62 - L64 were not covered by tests
}

endpoint := ctx.String(options.RPCEndpointFlag)
rpcClient, err := rpcclient.New(ctx.Context, endpoint, rpcclient.Options{
DialTimeout: 50 * time.Second,
RequestTimeout: 50 * time.Second,
})
if err != nil {
return fmt.Errorf("failed to create RPC client: %w", err)

Check warning on line 73 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L67-L73

Added lines #L67 - L73 were not covered by tests
}
err = rpcClient.Init()
if err != nil {
return fmt.Errorf("failed to initialize RPC client: %w", err)

Check warning on line 77 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L75-L77

Added lines #L75 - L77 were not covered by tests
}

currentBlockHeight, err := rpcClient.GetBlockCount()
if err != nil {
return fmt.Errorf("failed to get current block height from RPC: %w", err)

Check warning on line 82 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L80-L82

Added lines #L80 - L82 were not covered by tests
}
log.Println("Current block height:", currentBlockHeight)

Check warning on line 84 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L84

Added line #L84 was not covered by tests

maxBlockIndex, err := fetchMaxBlockIndex(ctx.Context, clientSDK, containerID, acc.PrivateKey(), uint(currentBlockHeight), attribute)
if err != nil {
return fmt.Errorf("failed to fetch max block index from container: %w", err)

Check warning on line 88 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L86-L88

Added lines #L86 - L88 were not covered by tests
}
log.Println("Max block index in NeoFS:", maxBlockIndex)
if maxBlockIndex == 0 {
maxBlockIndex = -1

Check warning on line 92 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L90-L92

Added lines #L90 - L92 were not covered by tests
}

if maxBlockIndex > int(currentBlockHeight) {
return fmt.Errorf("no new blocks to upload. Max index in NeoFS: %d, current height: %d", maxBlockIndex, currentBlockHeight)

Check warning on line 96 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L95-L96

Added lines #L95 - L96 were not covered by tests
}

for blockIndex := maxBlockIndex + 1; blockIndex <= int(currentBlockHeight); blockIndex++ {
blockData, err := fetchBlockData(rpcClient, uint(blockIndex))
if err != nil {
return fmt.Errorf("failed to fetch block %d: %w", blockIndex, err)

Check warning on line 102 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L99-L102

Added lines #L99 - L102 were not covered by tests
}

err = uploadBObjWithSlicer(ctx.Context, clientSDK, *acc, containerID, blockData, attribute, strconv.Itoa(blockIndex), sessionToken)
if err != nil {
return fmt.Errorf("failed to upload block %d: %w", blockIndex, err)

Check warning on line 107 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L105-L107

Added lines #L105 - L107 were not covered by tests
}

if blockIndex%1000 == 0 {
log.Printf("Successfully uploaded block: %d", blockIndex)

Check warning on line 111 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L110-L111

Added lines #L110 - L111 were not covered by tests
}
}

err = updateIndexFiles(ctx, clientSDK, containerID, *acc, uint(currentBlockHeight), indexFileAttribute, attribute)
if err != nil {
return fmt.Errorf("failed to update index files after upload: %w", err)

Check warning on line 117 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L115-L117

Added lines #L115 - L117 were not covered by tests
}

log.Println("Upload completed successfully.")
return nil

Check warning on line 121 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L120-L121

Added lines #L120 - L121 were not covered by tests
}

// fetchMaxBlockIndex searches for the maximum block index in the container.
func fetchMaxBlockIndex(ctx context.Context, clientSDK *client.Client, containerID cid.ID, priv *keys.PrivateKey, currentHeight uint, attributeKey string) (int, error) {
height := int(currentHeight)
var (
finalResult int
finalErr error
)

Check warning on line 130 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L125-L130

Added lines #L125 - L130 were not covered by tests

searchBatch := func(start, end int) (int, bool, error) {
prm := client.PrmObjectSearch{}
filters := object.NewSearchFilters()
filters.AddFilter(attributeKey, fmt.Sprintf("%d", start), object.MatchNumGE)
filters.AddFilter(attributeKey, fmt.Sprintf("%d", end), object.MatchNumLE)
prm.SetFilters(filters)

Check warning on line 137 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L132-L137

Added lines #L132 - L137 were not covered by tests

objectIDs, err := neofs.ObjectSearch(ctx, clientSDK, priv, containerID.String(), prm)
if err != nil {
return 0, false, fmt.Errorf("failed to search objects from %d to %d: %w", start, end, err)

Check warning on line 141 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L139-L141

Added lines #L139 - L141 were not covered by tests
}

numOIDs := len(objectIDs)
log.Printf("Found %d blocks between %d and %d", numOIDs, start, end)

Check warning on line 145 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L144-L145

Added lines #L144 - L145 were not covered by tests

if numOIDs == 0 {
return 0, false, nil // Keep searching.

Check warning on line 148 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L147-L148

Added lines #L147 - L148 were not covered by tests
}

// Return the max block index found in this batch
maxInBatch := start + numOIDs - 1

Check warning on line 152 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L152

Added line #L152 was not covered by tests

// Stop immediately after finding the first non-empty batch
return maxInBatch, true, nil

Check warning on line 155 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L155

Added line #L155 was not covered by tests
}

for height >= 0 {
startIndex := height - searchBatchSize + 1
if startIndex < 0 {
startIndex = 0

Check warning on line 161 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L158-L161

Added lines #L158 - L161 were not covered by tests
}

maxInBatch, foundNonEmptyBatch, err := searchBatch(startIndex, height)
if err != nil {
finalErr = err
break

Check warning on line 167 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L164-L167

Added lines #L164 - L167 were not covered by tests
}

if maxInBatch > finalResult {
finalResult = maxInBatch

Check warning on line 171 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L170-L171

Added lines #L170 - L171 were not covered by tests
}

// Stop the search as soon as we find any valid blocks
if foundNonEmptyBatch {
break

Check warning on line 176 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L175-L176

Added lines #L175 - L176 were not covered by tests
}

height -= searchBatchSize

Check warning on line 179 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L179

Added line #L179 was not covered by tests
}

if finalErr != nil {
return 0, finalErr

Check warning on line 183 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L182-L183

Added lines #L182 - L183 were not covered by tests
}

return finalResult, nil

Check warning on line 186 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L186

Added line #L186 was not covered by tests
}

func fetchBlockData(rpcClient *rpcclient.Client, index uint) ([]byte, error) {
if index%1000 == 0 {
log.Println("Fetching block", index)

Check warning on line 191 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L189-L191

Added lines #L189 - L191 were not covered by tests
}
block, err := rpcClient.GetBlockByIndex(uint32(index))
if err != nil {
return nil, fmt.Errorf("failed to fetch block %d: %w", index, err)

Check warning on line 195 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L193-L195

Added lines #L193 - L195 were not covered by tests
}

var buf bytes.Buffer
bw := io.NewBinWriterFromIO(&buf)

Check warning on line 199 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L198-L199

Added lines #L198 - L199 were not covered by tests

block.EncodeBinary(bw)

Check warning on line 201 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L201

Added line #L201 was not covered by tests

if bw.Err != nil {
return nil, fmt.Errorf("failed to encode block %d: %w", index, bw.Err)

Check warning on line 204 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L203-L204

Added lines #L203 - L204 were not covered by tests
}

return buf.Bytes(), nil

Check warning on line 207 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L207

Added line #L207 was not covered by tests
}

func uploadBObjWithSlicer(ctx context.Context, clientSDK *client.Client, account wallet.Account, containerID cid.ID, objData []byte, attributeKey, attributeValue string, sessionToken *session.Object) error {
signer := user.NewAutoIDSignerRFC6979(account.PrivateKey().PrivateKey)
var ownerID user.ID
ownerID.SetScriptHash(account.PrivateKey().GetScriptHash())

Check warning on line 213 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L210-L213

Added lines #L210 - L213 were not covered by tests

slc, err := slicer.New(ctx, clientSDK, signer, containerID, ownerID, sessionToken)
if err != nil {
return fmt.Errorf("failed to create slicer: %w", err)

Check warning on line 217 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L215-L217

Added lines #L215 - L217 were not covered by tests
}

attrs := []object.Attribute{
*object.NewAttribute(attributeKey, attributeValue),

Check warning on line 221 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L220-L221

Added lines #L220 - L221 were not covered by tests
}

_, err = slc.Put(ctx, bytes.NewReader(objData), attrs)
if err != nil {
return fmt.Errorf("failed to slice and upload block data: %w", err)

Check warning on line 226 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L224-L226

Added lines #L224 - L226 were not covered by tests
}

return nil

Check warning on line 229 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L229

Added line #L229 was not covered by tests
}

// updateIndexFiles updates the index files in the container.
func updateIndexFiles(ctx *cli.Context, clientSDK *client.Client, containerID cid.ID, account wallet.Account, currentHeight uint, attributeKey string, blockAttributeKey string) error {
log.Println("Updating index files...")

Check warning on line 234 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L233-L234

Added lines #L233 - L234 were not covered by tests

prm := client.PrmObjectSearch{}
filters := object.NewSearchFilters()
filters.AddFilter(attributeKey, fmt.Sprintf("%d", 0), object.MatchNumGE)
prm.SetFilters(filters)

Check warning on line 239 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L236-L239

Added lines #L236 - L239 were not covered by tests

objectIDs, err := neofs.ObjectSearch(ctx.Context, clientSDK, account.PrivateKey(), containerID.String(), prm)
if err != nil {
return fmt.Errorf("no OIDs found for index files: %w", err)

Check warning on line 243 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L241-L243

Added lines #L241 - L243 were not covered by tests
}

existingIndexCount := uint(len(objectIDs))
expectedIndexCount := currentHeight / uint(indexFileSize)

Check warning on line 247 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L246-L247

Added lines #L246 - L247 were not covered by tests

if existingIndexCount == expectedIndexCount {
return nil

Check warning on line 250 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L249-L250

Added lines #L249 - L250 were not covered by tests
}

var buf bytes.Buffer
fileIndex := int(existingIndexCount)

Check warning on line 254 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L253-L254

Added lines #L253 - L254 were not covered by tests

ctxWithCancel, cancel := context.WithCancel(ctx.Context)
defer cancel()

Check warning on line 257 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L256-L257

Added lines #L256 - L257 were not covered by tests

workerPool := make(chan struct{}, maxParallelSearches)
errCh := make(chan error, 1)
wg := sync.WaitGroup{}

Check warning on line 261 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L259-L261

Added lines #L259 - L261 were not covered by tests

for i := existingIndexCount; i < expectedIndexCount; i++ {
startIndex := i * indexFileSize
endIndex := startIndex + indexFileSize
if endIndex > currentHeight {
return fmt.Errorf("end index %d exceeds current height %d", endIndex, currentHeight)

Check warning on line 267 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L263-L267

Added lines #L263 - L267 were not covered by tests
}

blockOids := make([]oid.ID, indexFileSize)
for j := startIndex; j < endIndex; j++ {
select {
case <-ctxWithCancel.Done():
return <-errCh
default:

Check warning on line 275 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L270-L275

Added lines #L270 - L275 were not covered by tests
}

wg.Add(1)
workerPool <- struct{}{}

Check warning on line 279 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L278-L279

Added lines #L278 - L279 were not covered by tests

go func(index uint) {
defer wg.Done()
defer func() { <-workerPool }()

Check warning on line 283 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L281-L283

Added lines #L281 - L283 were not covered by tests

oidBlock, err := searchBlockOID(ctx, clientSDK, account, containerID, blockAttributeKey, index)
if err != nil {
select {
case errCh <- fmt.Errorf("failed to search for block OID at index %d: %w", index, err):
cancel()
default:

Check warning on line 290 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L285-L290

Added lines #L285 - L290 were not covered by tests
}
return

Check warning on line 292 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L292

Added line #L292 was not covered by tests
}
blockOids[index-startIndex] = oidBlock
if index%1000 == 0 {
log.Println("Found block OID", index)

Check warning on line 296 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L294-L296

Added lines #L294 - L296 were not covered by tests
}
}(j)
}
wg.Wait()

Check warning on line 300 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L300

Added line #L300 was not covered by tests

select {
case err := <-errCh:
return err
default:

Check warning on line 305 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L302-L305

Added lines #L302 - L305 were not covered by tests
}

for _, oidBlock := range blockOids {
oidBytes := make([]byte, 32)
oidBlock.Encode(oidBytes)
buf.Write(oidBytes)

Check warning on line 311 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L308-L311

Added lines #L308 - L311 were not covered by tests
}
err = uploadBObjWithSlicer(ctx.Context, clientSDK, account, containerID, buf.Bytes(), attributeKey, strconv.Itoa(fileIndex), nil)
if err != nil {
return fmt.Errorf("failed to upload index file %d: %w", fileIndex, err)

Check warning on line 315 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L313-L315

Added lines #L313 - L315 were not covered by tests
}
log.Printf("Uploaded index file %d", fileIndex)

Check warning on line 317 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L317

Added line #L317 was not covered by tests

fileIndex++
buf.Reset()

Check warning on line 320 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L319-L320

Added lines #L319 - L320 were not covered by tests
}

return nil

Check warning on line 323 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L323

Added line #L323 was not covered by tests
}

// searchBlockOID function to search for the OID of a specific block by index.
func searchBlockOID(ctx *cli.Context, clientSDK *client.Client, account wallet.Account, containerID cid.ID, blockAttributeKey string, blockIndex uint) (oid.ID, error) {
prm := client.PrmObjectSearch{}
filters := object.NewSearchFilters()
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", blockIndex), object.MatchStringEqual)
prm.SetFilters(filters)

Check warning on line 331 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L327-L331

Added lines #L327 - L331 were not covered by tests

objectIDs, err := neofs.ObjectSearch(ctx.Context, clientSDK, account.PrivateKey(), containerID.String(), prm)
if err != nil || len(objectIDs) == 0 {
return oid.ID{}, fmt.Errorf("no OIDs found for block index %d", blockIndex)

Check warning on line 335 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L333-L335

Added lines #L333 - L335 were not covered by tests
}
if len(objectIDs) > 1 {
log.Println("Multiple OIDs found for block index", blockIndex)

Check warning on line 338 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L337-L338

Added lines #L337 - L338 were not covered by tests
}
return objectIDs[0], nil

Check warning on line 340 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L340

Added line #L340 was not covered by tests
}

func createSessionToken(account wallet.Account, containerID cid.ID) (*session.Object, error) {
sessionToken := session.Object{}

Check warning on line 344 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L343-L344

Added lines #L343 - L344 were not covered by tests

sessionID := uuid.New()
sessionToken.SetID(sessionID)

Check warning on line 347 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L346-L347

Added lines #L346 - L347 were not covered by tests

pubKey := account.PublicKey()
authKey := neofsecdsa.PublicKey(*pubKey)
sessionToken.SetAuthKey(&authKey)

Check warning on line 351 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L349-L351

Added lines #L349 - L351 were not covered by tests

sessionToken.BindContainer(containerID)
sessionToken.ForVerb(session.VerbObjectPut)

Check warning on line 354 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L353-L354

Added lines #L353 - L354 were not covered by tests

sessionToken.SetExp(uint64(time.Now().Add(100 * time.Minute).Unix()))

Check warning on line 356 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L356

Added line #L356 was not covered by tests

signer := user.NewAutoIDSignerRFC6979(account.PrivateKey().PrivateKey)
if err := sessionToken.Sign(signer); err != nil {
return nil, fmt.Errorf("failed to sign session token: %w", err)

Check warning on line 360 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L358-L360

Added lines #L358 - L360 were not covered by tests
}

return &sessionToken, nil

Check warning on line 363 in cli/server/dump_bin_put.go

View check run for this annotation

Codecov / codecov/patch

cli/server/dump_bin_put.go#L363

Added line #L363 was not covered by tests
}
Loading

0 comments on commit 13e075a

Please sign in to comment.