From 2da8396a9fce37c5df10f9e63e2d6807f77f72c3 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 31 May 2022 20:02:35 +0300 Subject: [PATCH] [#1454] cli/util: Support container sessions in `sign session-token` Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/util/sign_session.go | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-cli/modules/util/sign_session.go b/cmd/neofs-cli/modules/util/sign_session.go index f9713ff7..1b4f1f7f 100644 --- a/cmd/neofs-cli/modules/util/sign_session.go +++ b/cmd/neofs-cli/modules/util/sign_session.go @@ -1,6 +1,8 @@ package util import ( + "crypto/ecdsa" + "encoding/json" "errors" "fmt" "os" @@ -38,8 +40,26 @@ func signSessionToken(cmd *cobra.Command, _ []string) { common.ExitOnErr(cmd, "", errors.New("missing session token flag")) } - var stok session.Object - common.ReadSessionToken(cmd, &stok, signFromFlag) + type iTokenSession interface { + json.Marshaler + json.Unmarshaler + Sign(ecdsa.PrivateKey) error + } + var errLast error + var stok iTokenSession + + for _, el := range [...]iTokenSession{ + new(session.Object), + new(session.Container), + } { + errLast = common.ReadSessionTokenErr(el, fPath) + if errLast == nil { + stok = el + break + } + } + + common.ExitOnErr(cmd, "", errLast) pk := key.GetOrGenerate(cmd)