From b86b06c0ca873a8f2e39e2dc7532e065c74915de Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 7 Feb 2022 12:33:27 +0300 Subject: [PATCH] [#1101] neofs-cli: Set expiration in session token based on network info Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/object.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 281d5f2385..9e047aedd9 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -37,6 +37,8 @@ const ( const bearerTokenFlag = "bearer" +const sessionTokenLifetime = 10 // in epochs + var ( // objectCmd represents the object command objectCmd = &cobra.Command{ @@ -299,10 +301,14 @@ func prepareSessionPrmWithOwner( ownerID *owner.ID, prms ...clientKeySession, ) { - var sessionPrm internalclient.CreateSessionPrm + var ( + sessionPrm internalclient.CreateSessionPrm + netInfoPrm internalclient.NetworkInfoPrm + ) - cws := make([]clientWithKey, 1, len(prms)+1) + cws := make([]clientWithKey, 2, len(prms)+2) cws[0] = &sessionPrm + cws[1] = &netInfoPrm for i := range prms { cws = append(cws, prms[i]) @@ -310,6 +316,11 @@ func prepareSessionPrmWithOwner( prepareAPIClientWithKey(cmd, key, cws...) + ni, err := internalclient.NetworkInfo(netInfoPrm) + exitOnErr(cmd, errf("read network info: %w", err)) + + sessionPrm.SetExp(ni.NetworkInfo().CurrentEpoch() + sessionTokenLifetime) + sessionRes, err := internalclient.CreateSession(sessionPrm) exitOnErr(cmd, errf("open session: %w", err))