[#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:
parent
1deea4e8c6
commit
b86b06c0ca
1 changed files with 13 additions and 2 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in a new issue