cmd/uplink: 'uplink access inspect' for displaying access fields

https://storjlabs.atlassian.net/browse/V3-3492

Change-Id: Id75aad869f8d06444f970f1da50e784179993894
This commit is contained in:
Michal Niewrzal 2020-01-13 14:52:53 +01:00
parent c51f9a22e2
commit 6c4e3b64df

71
cmd/uplink/cmd/access.go Normal file
View File

@ -0,0 +1,71 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
libuplink "storj.io/storj/lib/uplink"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/process"
)
var inspectCfg AccessConfig
func init() {
// We skip the use of addCmd here because we only want the configuration options listed
// above, and addCmd adds a whole lot more than we want.
accessCmd := &cobra.Command{
Use: "access",
Short: "Set of commands to manage access.",
}
inspectCmd := &cobra.Command{
Use: "inspect [ACCESS]",
Short: "Inspect allows you to explode a serialized access into it's constituent parts.",
RunE: accessInspect,
Args: cobra.MaximumNArgs(1),
}
RootCmd.AddCommand(accessCmd)
accessCmd.AddCommand(inspectCmd)
process.Bind(inspectCmd, &inspectCfg, defaults, cfgstruct.ConfDir(getConfDir()))
}
func accessInspect(cmd *cobra.Command, args []string) (err error) {
var access *libuplink.Scope
if len(args) == 0 {
access, err = inspectCfg.GetAccess()
if err != nil {
return err
}
} else {
firstArg := args[0]
access, err = inspectCfg.GetNamedAccess(firstArg)
if err != nil {
return err
}
if access == nil {
if access, err = libuplink.ParseScope(firstArg); err != nil {
return err
}
}
}
serializedAPIKey := access.APIKey.Serialize()
serializedEncAccess, err := access.EncryptionAccess.Serialize()
if err != nil {
return err
}
fmt.Println("=========== ACCESS INFO ==================================================================")
fmt.Println("Satellite :", access.SatelliteAddr)
fmt.Println("API Key :", serializedAPIKey)
fmt.Println("Encryption Access:", serializedEncAccess)
return nil
}