[#1101] neofs-cli: Set expiration in session token based on network info

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-02-07 12:33:27 +03:00 committed by Alex Vanin
parent 1deea4e8c6
commit b86b06c0ca

View file

@ -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))