forked from TrueCloudLab/frostfs-node
[#1461] cli: Add context to GetCurrentEpoch
helper
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
51afcc1182
commit
b1e54dec9f
3 changed files with 13 additions and 7 deletions
|
@ -7,7 +7,6 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
|
@ -60,7 +59,7 @@ func GetSDKClient(key *ecdsa.PrivateKey, addr network.Address) (*client.Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentEpoch returns current epoch.
|
// GetCurrentEpoch returns current epoch.
|
||||||
func GetCurrentEpoch(endpoint string) (uint64, error) {
|
func GetCurrentEpoch(ctx context.Context, endpoint string) (uint64, error) {
|
||||||
var addr network.Address
|
var addr network.Address
|
||||||
|
|
||||||
if err := addr.FromString(endpoint); err != nil {
|
if err := addr.FromString(endpoint); err != nil {
|
||||||
|
@ -77,9 +76,6 @@ func GetCurrentEpoch(endpoint string) (uint64, error) {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ni, err := c.NetworkInfo(ctx, client.PrmNetworkInfo{})
|
ni, err := c.NetworkInfo(ctx, client.PrmNetworkInfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package bearer
|
package bearer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"time"
|
||||||
|
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||||
|
@ -69,8 +71,11 @@ func createToken(cmd *cobra.Command, _ []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if iatRelative || expRelative || nvbRelative {
|
if iatRelative || expRelative || nvbRelative {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
endpoint, _ := cmd.Flags().GetString(commonflags.RPC)
|
endpoint, _ := cmd.Flags().GetString(commonflags.RPC)
|
||||||
currEpoch, err := internalclient.GetCurrentEpoch(endpoint)
|
currEpoch, err := internalclient.GetCurrentEpoch(ctx, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
||||||
|
@ -52,9 +54,12 @@ var objectLockCmd = &cobra.Command{
|
||||||
common.ExitOnErr(cmd, "Parsing expiration epoch: %w", err)
|
common.ExitOnErr(cmd, "Parsing expiration epoch: %w", err)
|
||||||
|
|
||||||
if relative {
|
if relative {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
endpoint, _ := cmd.Flags().GetString(commonflags.RPC)
|
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)
|
common.ExitOnErr(cmd, "Request current epoch: %w", err)
|
||||||
|
|
||||||
exp += currEpoch
|
exp += currEpoch
|
||||||
|
|
Loading…
Reference in a new issue