Skip to content

Commit

Permalink
[#1461] cli: Add context to GetCurrentEpoch helper
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell authored and fyrchik committed Jun 17, 2022
1 parent 6a508fa commit 398eb80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 1 addition & 5 deletions cmd/neofs-cli/internal/client/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/rand"
"errors"
"fmt"
"time"

"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/pkg/network"
Expand Down Expand Up @@ -60,7 +59,7 @@ func GetSDKClient(key *ecdsa.PrivateKey, addr network.Address) (*client.Client,
}

// GetCurrentEpoch returns current epoch.
func GetCurrentEpoch(endpoint string) (uint64, error) {
func GetCurrentEpoch(ctx context.Context, endpoint string) (uint64, error) {
var addr network.Address

if err := addr.FromString(endpoint); err != nil {
Expand All @@ -77,9 +76,6 @@ func GetCurrentEpoch(endpoint string) (uint64, error) {
return 0, err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

ni, err := c.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil {
return 0, err
Expand Down
7 changes: 6 additions & 1 deletion cmd/neofs-cli/modules/bearer/create.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package bearer

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"time"

internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
Expand Down Expand Up @@ -69,8 +71,11 @@ func createToken(cmd *cobra.Command, _ []string) error {
return err
}
if iatRelative || expRelative || nvbRelative {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

endpoint, _ := cmd.Flags().GetString(commonflags.RPC)
currEpoch, err := internalclient.GetCurrentEpoch(endpoint)
currEpoch, err := internalclient.GetCurrentEpoch(ctx, endpoint)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/neofs-cli/modules/object/lock.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package object

import (
"context"
"fmt"
"strconv"
"time"

objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
Expand Down Expand Up @@ -52,9 +54,12 @@ var objectLockCmd = &cobra.Command{
common.ExitOnErr(cmd, "Parsing expiration epoch: %w", err)

if relative {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

endpoint, _ := cmd.Flags().GetString(commonflags.RPC)

currEpoch, err := internalclient.GetCurrentEpoch(endpoint)
currEpoch, err := internalclient.GetCurrentEpoch(ctx, endpoint)
common.ExitOnErr(cmd, "Request current epoch: %w", err)

exp += currEpoch
Expand Down

0 comments on commit 398eb80

Please sign in to comment.