[#1216] neofs-cli: Allow to use session token from file
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
a95bdb1811
commit
a254fd6bc8
1 changed files with 32 additions and 2 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -289,6 +290,23 @@ func init() {
|
||||||
initObjectHashCmd()
|
initObjectHashCmd()
|
||||||
initObjectRangeCmd()
|
initObjectRangeCmd()
|
||||||
initCommandObjectLock()
|
initCommandObjectLock()
|
||||||
|
|
||||||
|
for _, cmd := range []*cobra.Command{
|
||||||
|
objectPutCmd,
|
||||||
|
objectDelCmd,
|
||||||
|
objectGetCmd,
|
||||||
|
objectSearchCmd,
|
||||||
|
objectHeadCmd,
|
||||||
|
objectRangeCmd,
|
||||||
|
cmdObjectLock,
|
||||||
|
} {
|
||||||
|
cmd.Flags().StringVar(
|
||||||
|
&sessionTokenPath,
|
||||||
|
sessionTokenFlag,
|
||||||
|
"",
|
||||||
|
"path to a JSON-encoded container session token",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientKeySession interface {
|
type clientKeySession interface {
|
||||||
|
@ -320,8 +338,20 @@ func prepareSessionPrmWithOwner(
|
||||||
cli, err := getSDKClient(key)
|
cli, err := getSDKClient(key)
|
||||||
exitOnErr(cmd, errf("create API client: %w", err))
|
exitOnErr(cmd, errf("create API client: %w", err))
|
||||||
|
|
||||||
sessionToken, err := sessionCli.CreateSession(cli, ownerID, sessionTokenLifetime)
|
var sessionToken *session.Token
|
||||||
|
if tokenPath, _ := cmd.Flags().GetString(sessionTokenFlag); len(tokenPath) != 0 {
|
||||||
|
data, err := ioutil.ReadFile(tokenPath)
|
||||||
|
exitOnErr(cmd, errf("can't read session token: %w", err))
|
||||||
|
|
||||||
|
sessionToken = session.NewToken()
|
||||||
|
if err := sessionToken.Unmarshal(data); err != nil {
|
||||||
|
err = sessionToken.UnmarshalJSON(data)
|
||||||
|
exitOnErr(cmd, errf("can't unmarshal session token: %w", err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sessionToken, err = sessionCli.CreateSession(cli, ownerID, sessionTokenLifetime)
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
}
|
||||||
|
|
||||||
for i := range prms {
|
for i := range prms {
|
||||||
objectContext := session.NewObjectContext()
|
objectContext := session.NewObjectContext()
|
||||||
|
|
Loading…
Reference in a new issue