cmd/uplink: Fix error on interactive setup when --config-dir flag is used. (#2033)
Uplink CLI was returning an error when the `--config-dir` flag was used with interactive `setup` command because the directory used for storing the encryption key file was the default configuration directory rather than the value set in the flag. This changes make the setup process to use the same directory, than the one informed by the `--config-dir` flag value, for storing encryption key file. On the other hand, the default value for the encryption key file path which was set with the purpose of showing it in the help message has been removed because the cfgstruct doesn't show it unless that the flag is set to the Cobra root CMD, so it was useless. Also show the absolute path where the encryption key file has been saved when the interactive setup command ends satisfactorily as it's equally done with the configuration file.
This commit is contained in:
parent
8b31c4b91f
commit
69cf6caa62
@ -29,10 +29,9 @@ var (
|
||||
Annotations: map[string]string{"type": "setup"},
|
||||
}
|
||||
|
||||
setupCfg UplinkFlags
|
||||
confDir string
|
||||
encryptionKeyFilepath string
|
||||
defaults cfgstruct.BindOpt
|
||||
setupCfg UplinkFlags
|
||||
confDir string
|
||||
defaults cfgstruct.BindOpt
|
||||
|
||||
// Error is the default uplink setup errs class
|
||||
Error = errs.Class("uplink setup error")
|
||||
@ -44,9 +43,6 @@ func init() {
|
||||
defaults = cfgstruct.DefaultsFlag(RootCmd)
|
||||
RootCmd.AddCommand(setupCmd)
|
||||
cfgstruct.BindSetup(setupCmd.Flags(), &setupCfg, defaults, cfgstruct.ConfDir(confDir))
|
||||
|
||||
defaultEncryptionKeyFilepath := filepath.Join(defaultConfDir, ".encryption.key")
|
||||
cfgstruct.SetupFlag(zap.L(), setupCmd, &encryptionKeyFilepath, "enc.key-filepath", defaultEncryptionKeyFilepath, "path to the file which contains the encryption key")
|
||||
}
|
||||
|
||||
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
@ -76,10 +72,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
// value in the config file but commented out.
|
||||
usedEncryptionKeyFilepath := setupCfg.Enc.KeyFilepath
|
||||
if usedEncryptionKeyFilepath == "" {
|
||||
usedEncryptionKeyFilepath, err = filepath.Abs(encryptionKeyFilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usedEncryptionKeyFilepath = filepath.Join(setupDir, ".encryption.key")
|
||||
}
|
||||
|
||||
if setupCfg.NonInteractive {
|
||||
@ -201,7 +194,9 @@ Please enter numeric choice or enter satellite address manually [1]: `)
|
||||
|
||||
// if there is an error with this we cannot do that much and the setup process
|
||||
// has ended OK, so we ignore it.
|
||||
_, _ = fmt.Println(`
|
||||
_, _ = fmt.Printf(`
|
||||
Your encryption key is saved to: %s
|
||||
|
||||
Your Uplink CLI is configured and ready to use!
|
||||
|
||||
Some things to try next:
|
||||
@ -209,7 +204,7 @@ Some things to try next:
|
||||
* Run 'uplink --help' to see the operations that can be performed
|
||||
|
||||
* See https://github.com/storj/docs/blob/master/Uplink-CLI.md#usage for some example commands
|
||||
`)
|
||||
`, usedEncryptionKeyFilepath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user