From bce92168c14689fff9264b3849348a361103444b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 3 Jun 2021 17:38:33 +0300 Subject: [PATCH] [#587] cmd/neofs-cli: Make session token parser reusable containerSessionToken() actually parses any session token. We can reuse this function to resign session token when it takes filepath as an argument, instead of public variable. Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/container.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 2d430b630..6cc13db99 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -161,7 +161,7 @@ It will be stored in sidechain when inner ring will accepts it.`, return err } - tok, err := containerSessionToken() + tok, err := getSessionToken(sessionTokenPath) if err != nil { return err } @@ -224,7 +224,7 @@ Only owner of the container has a permission to remove container.`, return err } - tok, err := containerSessionToken() + tok, err := getSessionToken(sessionTokenPath) if err != nil { return err } @@ -477,7 +477,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`, return err } - tok, err := containerSessionToken() + tok, err := getSessionToken(sessionTokenPath) if err != nil { return err } @@ -595,12 +595,13 @@ func init() { } } -func containerSessionToken() (*session.Token, error) { +// getSessionToken reads `` as JSON file with session token and parses it. +func getSessionToken(path string) (*session.Token, error) { // try to read session token from file var tok *session.Token - if sessionTokenPath != "" { - data, err := ioutil.ReadFile(sessionTokenPath) + if path != "" { + data, err := ioutil.ReadFile(path) if err != nil { return nil, err }