[#406] cli: Pass context to internal client

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-05-24 16:51:57 +03:00 committed by Evgenii Stratonikov
parent 63473d0806
commit 9562123c49
24 changed files with 83 additions and 82 deletions

View file

@ -41,7 +41,7 @@ var accountingBalanceCmd = &cobra.Command{
prm.SetClient(cli)
prm.SetAccount(idUser)
res, err := internalclient.BalanceOf(prm)
res, err := internalclient.BalanceOf(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
// print to stdout

View file

@ -48,7 +48,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
var prm internalclient.NetMapSnapshotPrm
prm.SetClient(cli)
resmap, err := internalclient.NetMapSnapshot(prm)
resmap, err := internalclient.NetMapSnapshot(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "unable to get netmap snapshot to validate container placement, "+
"use --force option to skip this check: %w", err)
@ -96,7 +96,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
syncContainerPrm.SetClient(cli)
syncContainerPrm.SetContainer(&cnr)
_, err = internalclient.SyncContainerSettings(syncContainerPrm)
_, err = internalclient.SyncContainerSettings(cmd.Context(), syncContainerPrm)
commonCmd.ExitOnErr(cmd, "syncing container's settings rpc error: %w", err)
var putPrm internalclient.PutContainerPrm
@ -107,7 +107,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
putPrm.WithinSession(*tok)
}
res, err := internalclient.PutContainer(putPrm)
res, err := internalclient.PutContainer(cmd.Context(), putPrm)
commonCmd.ExitOnErr(cmd, "put container rpc error: %w", err)
id := res.ID()
@ -124,7 +124,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
_, err := internalclient.GetContainer(getPrm)
_, err := internalclient.GetContainer(cmd.Context(), getPrm)
if err == nil {
cmd.Println("container has been persisted on sidechain")
return

View file

@ -34,7 +34,7 @@ Only owner of the container has a permission to remove container.`,
getPrm.SetClient(cli)
getPrm.SetContainer(id)
resGet, err := internalclient.GetContainer(getPrm)
resGet, err := internalclient.GetContainer(cmd.Context(), getPrm)
commonCmd.ExitOnErr(cmd, "can't get the container: %w", err)
owner := resGet.Container().Owner()
@ -72,7 +72,7 @@ Only owner of the container has a permission to remove container.`,
common.PrintVerbose(cmd, "Searching for LOCK objects...")
res, err := internalclient.SearchObjects(searchPrm)
res, err := internalclient.SearchObjects(cmd.Context(), searchPrm)
commonCmd.ExitOnErr(cmd, "can't search for LOCK objects: %w", err)
if len(res.IDList()) != 0 {
@ -91,7 +91,7 @@ Only owner of the container has a permission to remove container.`,
delPrm.WithinSession(*tok)
}
_, err := internalclient.DeleteContainer(delPrm)
_, err := internalclient.DeleteContainer(cmd.Context(), delPrm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
cmd.Println("container delete method invoked")
@ -106,7 +106,7 @@ Only owner of the container has a permission to remove container.`,
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
_, err := internalclient.GetContainer(getPrm)
_, err := internalclient.GetContainer(cmd.Context(), getPrm)
if err != nil {
cmd.Println("container has been removed:", containerID)
return

View file

@ -151,7 +151,7 @@ func getContainer(cmd *cobra.Command) (container.Container, *ecdsa.PrivateKey) {
prm.SetClient(cli)
prm.SetContainer(id)
res, err := internalclient.GetContainer(prm)
res, err := internalclient.GetContainer(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
cnr = res.Container()

View file

@ -24,7 +24,7 @@ var getExtendedACLCmd = &cobra.Command{
eaclPrm.SetClient(cli)
eaclPrm.SetContainer(id)
res, err := internalclient.EACL(eaclPrm)
res, err := internalclient.EACL(cmd.Context(), eaclPrm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
eaclTable := res.EACL()

View file

@ -49,7 +49,7 @@ var listContainersCmd = &cobra.Command{
prm.SetClient(cli)
prm.SetAccount(idUser)
res, err := internalclient.ListContainers(prm)
res, err := internalclient.ListContainers(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
var prmGet internalclient.GetContainerPrm
@ -63,7 +63,7 @@ var listContainersCmd = &cobra.Command{
}
prmGet.SetContainer(cnrID)
res, err := internalclient.GetContainer(prmGet)
res, err := internalclient.GetContainer(cmd.Context(), prmGet)
if err != nil {
cmd.Printf(" failed to read attributes: %v\n", err)
continue

View file

@ -51,7 +51,7 @@ var listContainerObjectsCmd = &cobra.Command{
prmSearch.SetContainerID(id)
prmSearch.SetFilters(*filters)
res, err := internalclient.SearchObjects(prmSearch)
res, err := internalclient.SearchObjects(cmd.Context(), prmSearch)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
objectIDs := res.IDList()
@ -65,7 +65,7 @@ var listContainerObjectsCmd = &cobra.Command{
addr.SetObject(objectIDs[i])
prmHead.SetAddress(addr)
resHead, err := internalclient.HeadObject(prmHead)
resHead, err := internalclient.HeadObject(cmd.Context(), prmHead)
if err == nil {
attrs := resHead.Header().Attributes()
for i := range attrs {

View file

@ -31,7 +31,7 @@ var containerNodesCmd = &cobra.Command{
var prm internalclient.NetMapSnapshotPrm
prm.SetClient(cli)
resmap, err := internalclient.NetMapSnapshot(prm)
resmap, err := internalclient.NetMapSnapshot(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "unable to get netmap snapshot", err)
var id cid.ID

View file

@ -38,7 +38,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
if !flagVarsSetEACL.noPreCheck {
cmd.Println("Checking the ability to modify access rights in the container...")
extendable, err := internalclient.IsACLExtendable(cli, id)
extendable, err := internalclient.IsACLExtendable(cmd.Context(), cli, id)
commonCmd.ExitOnErr(cmd, "Extensibility check failure: %w", err)
if !extendable {
@ -56,7 +56,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
setEACLPrm.WithinSession(*tok)
}
_, err := internalclient.SetEACL(setEACLPrm)
_, err := internalclient.SetEACL(cmd.Context(), setEACLPrm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
if containerAwait {
@ -72,7 +72,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
res, err := internalclient.EACL(getEACLPrm)
res, err := internalclient.EACL(cmd.Context(), getEACLPrm)
if err == nil {
// compare binary values because EACL could have been set already
table := res.EACL()

View file

@ -19,7 +19,7 @@ var getEpochCmd = &cobra.Command{
var prm internalclient.NetworkInfoPrm
prm.SetClient(cli)
res, err := internalclient.NetworkInfo(prm)
res, err := internalclient.NetworkInfo(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
netInfo := res.NetworkInfo()

View file

@ -23,7 +23,7 @@ var netInfoCmd = &cobra.Command{
var prm internalclient.NetworkInfoPrm
prm.SetClient(cli)
res, err := internalclient.NetworkInfo(prm)
res, err := internalclient.NetworkInfo(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
netInfo := res.NetworkInfo()

View file

@ -25,7 +25,7 @@ var nodeInfoCmd = &cobra.Command{
var prm internalclient.NodeInfoPrm
prm.SetClient(cli)
res, err := internalclient.NodeInfo(prm)
res, err := internalclient.NodeInfo(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
prettyPrintNodeInfo(cmd, res.NodeInfo())

View file

@ -19,7 +19,7 @@ var snapshotCmd = &cobra.Command{
var prm internalclient.NetMapSnapshotPrm
prm.SetClient(cli)
res, err := internalclient.NetMapSnapshot(prm)
res, err := internalclient.NetMapSnapshot(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.PrettyPrintNetMap(cmd, res.NetMap(), false)

View file

@ -65,7 +65,7 @@ func deleteObject(cmd *cobra.Command, _ []string) {
Prepare(cmd, &prm)
prm.SetAddress(objAddr)
res, err := internalclient.DeleteObject(prm)
res, err := internalclient.DeleteObject(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
tomb := res.Tombstone()

View file

@ -90,7 +90,7 @@ func getObject(cmd *cobra.Command, _ []string) {
})
}
res, err := internalclient.GetObject(prm)
res, err := internalclient.GetObject(cmd.Context(), prm)
if p != nil {
p.Finish()
}

View file

@ -75,7 +75,7 @@ func getObjectHash(cmd *cobra.Command, _ []string) {
headPrm.SetAddress(objAddr)
// get hash of full payload through HEAD (may be user can do it through dedicated command?)
res, err := internalclient.HeadObject(headPrm)
res, err := internalclient.HeadObject(cmd.Context(), headPrm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
var cs checksum.Checksum
@ -108,7 +108,7 @@ func getObjectHash(cmd *cobra.Command, _ []string) {
hashPrm.TZ()
}
res, err := internalclient.HashPayloadRanges(hashPrm)
res, err := internalclient.HashPayloadRanges(cmd.Context(), hashPrm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
hs := res.HashList()

View file

@ -64,7 +64,7 @@ func getObjectHeader(cmd *cobra.Command, _ []string) {
prm.SetAddress(objAddr)
prm.SetMainOnlyFlag(mainOnly)
res, err := internalclient.HeadObject(prm)
res, err := internalclient.HeadObject(cmd.Context(), prm)
if err != nil {
if ok := printSplitInfoErr(cmd, err); ok {
return

View file

@ -104,7 +104,7 @@ var objectLockCmd = &cobra.Command{
Prepare(cmd, &prm)
prm.SetHeader(obj)
res, err := internalclient.PutObject(prm)
res, err := internalclient.PutObject(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "Store lock object in FrostFS: %w", err)
cmd.Printf("Lock object ID: %s\n", res.ID())

View file

@ -131,7 +131,7 @@ func putObject(cmd *cobra.Command, _ []string) {
prm.SetCopiesNumberByVectors(cn)
}
res, err := internalclient.PutObject(prm)
res, err := internalclient.PutObject(cmd.Context(), prm)
if p != nil {
p.Finish()
}

View file

@ -87,7 +87,7 @@ func getObjectRange(cmd *cobra.Command, _ []string) {
prm.SetRange(ranges[0])
prm.SetPayloadWriter(out)
_, err = internalclient.PayloadRange(prm)
_, err = internalclient.PayloadRange(cmd.Context(), prm)
if err != nil {
if ok := printSplitInfoErr(cmd, err); ok {
return

View file

@ -61,7 +61,7 @@ func searchObject(cmd *cobra.Command, _ []string) {
prm.SetContainerID(cnr)
prm.SetFilters(sf)
res, err := internalclient.SearchObjects(prm)
res, err := internalclient.SearchObjects(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
ids := res.IDList()

View file

@ -278,7 +278,7 @@ func OpenSessionViaClient(cmd *cobra.Command, dst SessionPrm, cli *client.Client
common.PrintVerbose(cmd, "Opening remote session with the node...")
err := sessionCli.CreateSession(&tok, cli, sessionLifetime)
err := sessionCli.CreateSession(cmd.Context(), &tok, cli, sessionLifetime)
commonCmd.ExitOnErr(cmd, "open remote session: %w", err)
common.PrintVerbose(cmd, "Session successfully opened.")
@ -354,7 +354,7 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
Prepare(cmd, &prmHead)
_, err := internal.HeadObject(prmHead)
_, err := internal.HeadObject(cmd.Context(), prmHead)
var errSplit *object.SplitInfoError
@ -396,7 +396,7 @@ func tryGetSplitMembersByLinkingObject(cmd *cobra.Command, splitInfo *object.Spl
prmHead.SetRawFlag(false)
// client is already set
res, err := internal.HeadObject(prmHead)
res, err := internal.HeadObject(cmd.Context(), prmHead)
if err == nil {
children := res.Header().Children()
@ -425,7 +425,7 @@ func tryGetSplitMembersBySplitID(cmd *cobra.Command, splitInfo *object.SplitInfo
prm.SetClient(cli)
prm.SetFilters(query)
res, err := internal.SearchObjects(prm)
res, err := internal.SearchObjects(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "failed to search objects by split ID: %w", err)
parts := res.IDList()
@ -463,7 +463,7 @@ func tryRestoreChainInReverse(cmd *cobra.Command, splitInfo *object.SplitInfo, p
addrObj.SetObject(idMember)
prmHead.SetAddress(addrObj)
res, err = internal.HeadObject(prmHead)
res, err = internal.HeadObject(cmd.Context(), prmHead)
commonCmd.ExitOnErr(cmd, "failed to read split chain member's header: %w", err)
idMember, ok = res.Header().PreviousID()
@ -490,7 +490,7 @@ func tryRestoreChainInReverse(cmd *cobra.Command, splitInfo *object.SplitInfo, p
prmSearch.SetContainerID(cnr)
prmSearch.SetFilters(query)
resSearch, err := internal.SearchObjects(prmSearch)
resSearch, err := internal.SearchObjects(cmd.Context(), prmSearch)
commonCmd.ExitOnErr(cmd, "failed to find object children: %w", err)
list := resSearch.IDList()

View file

@ -1,6 +1,7 @@
package session
import (
"context"
"fmt"
"os"
@ -64,7 +65,7 @@ func createSession(cmd *cobra.Command, _ []string) {
var tok session.Object
err = CreateSession(&tok, c, lifetime)
err = CreateSession(cmd.Context(), &tok, c, lifetime)
commonCmd.ExitOnErr(cmd, "can't create session: %w", err)
var data []byte
@ -86,11 +87,11 @@ func createSession(cmd *cobra.Command, _ []string) {
// number of epochs.
//
// Fills ID, lifetime and session key.
func CreateSession(dst *session.Object, c *client.Client, lifetime uint64) error {
func CreateSession(ctx context.Context, dst *session.Object, c *client.Client, lifetime uint64) error {
var netInfoPrm internalclient.NetworkInfoPrm
netInfoPrm.SetClient(c)
ni, err := internalclient.NetworkInfo(netInfoPrm)
ni, err := internalclient.NetworkInfo(ctx, netInfoPrm)
if err != nil {
return fmt.Errorf("can't fetch network info: %w", err)
}
@ -102,7 +103,7 @@ func CreateSession(dst *session.Object, c *client.Client, lifetime uint64) error
sessionPrm.SetClient(c)
sessionPrm.SetExp(exp)
sessionRes, err := internalclient.CreateSession(sessionPrm)
sessionRes, err := internalclient.CreateSession(ctx, sessionPrm)
if err != nil {
return fmt.Errorf("can't open session: %w", err)
}