Update Wizard to allow more easily addition of satellites and move package to cmd folder (#2340)

This commit is contained in:
Stefan Benten 2019-06-25 20:25:31 +02:00 committed by GitHub
parent 2cc01c7899
commit 57ef352b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 14 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/storj/cmd/internal/wizard"
"storj.io/storj/internal/fpath" "storj.io/storj/internal/fpath"
libuplink "storj.io/storj/lib/uplink" libuplink "storj.io/storj/lib/uplink"
"storj.io/storj/pkg/cfgstruct" "storj.io/storj/pkg/cfgstruct"
@ -275,17 +276,17 @@ func (flags GatewayFlags) openProject(ctx context.Context) (*libuplink.Project,
func (flags GatewayFlags) interactive( func (flags GatewayFlags) interactive(
cmd *cobra.Command, setupDir string, encryptionKeyFilepath string, overrides map[string]interface{}, cmd *cobra.Command, setupDir string, encryptionKeyFilepath string, overrides map[string]interface{},
) error { ) error {
satelliteAddress, err := cfgstruct.PromptForSatellite(cmd) satelliteAddress, err := wizard.PromptForSatellite(cmd)
if err != nil { if err != nil {
return Error.Wrap(err) return Error.Wrap(err)
} }
apiKey, err := cfgstruct.PromptForAPIKey() apiKey, err := wizard.PromptForAPIKey()
if err != nil { if err != nil {
return Error.Wrap(err) return Error.Wrap(err)
} }
humanReadableKey, err := cfgstruct.PromptForEncryptionKey() humanReadableKey, err := wizard.PromptForEncryptionKey()
if err != nil { if err != nil {
return Error.Wrap(err) return Error.Wrap(err)
} }

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc. // Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information // See LICENSE for copying information
package cfgstruct package wizard
import ( import (
"bytes" "bytes"
@ -54,16 +54,25 @@ func applyDefaultHostAndPortToAddr(address, defaultAddress string) (string, erro
// PromptForSatellite handles user input for a satellite address to be used with wizards // PromptForSatellite handles user input for a satellite address to be used with wizards
func PromptForSatellite(cmd *cobra.Command) (string, error) { func PromptForSatellite(cmd *cobra.Command) (string, error) {
_, err := fmt.Print(` satellites := []string{"us-central-1.tardigrade.io", "europe-west-1.tardigrade.io", "asia-east-1.tardigrade.io"}
Pick satellite to use:
[1] us-central-1.tardigrade.io _, err := fmt.Print("Pick a satellite to use:\n")
[2] europe-west-1.tardigrade.io
[3] asia-east-1.tardigrade.io
Please enter numeric choice or enter satellite address manually [1]: `)
if err != nil { if err != nil {
return "", err return "", err
} }
satellites := []string{"us-central-1.tardigrade.io", "europe-west-1.tardigrade.io", "asia-east-1.tardigrade.io"}
for iterator, value := range satellites {
_, err := fmt.Printf("\t[%d] %s\n", iterator+1, value)
if err != nil {
return "", nil
}
}
_, err = fmt.Print("Please enter numeric choice or enter satellite address manually [1]: ")
if err != nil {
return "", err
}
var satelliteAddress string var satelliteAddress string
n, err := fmt.Scanln(&satelliteAddress) n, err := fmt.Scanln(&satelliteAddress)
if err != nil { if err != nil {

View File

@ -14,6 +14,7 @@ import (
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/storj/cmd/internal/wizard"
"storj.io/storj/internal/fpath" "storj.io/storj/internal/fpath"
"storj.io/storj/pkg/cfgstruct" "storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/process" "storj.io/storj/pkg/process"
@ -116,17 +117,17 @@ func cmdSetupNonInteractive(cmd *cobra.Command, setupDir string, encryptionKeyFi
// or to a default path whose directory tree exists. // or to a default path whose directory tree exists.
func cmdSetupInteractive(cmd *cobra.Command, setupDir string, encryptionKeyFilepath string) error { func cmdSetupInteractive(cmd *cobra.Command, setupDir string, encryptionKeyFilepath string) error {
satelliteAddress, err := cfgstruct.PromptForSatellite(cmd) satelliteAddress, err := wizard.PromptForSatellite(cmd)
if err != nil { if err != nil {
return err return err
} }
apiKey, err := cfgstruct.PromptForAPIKey() apiKey, err := wizard.PromptForAPIKey()
if err != nil { if err != nil {
return err return err
} }
humanReadableKey, err := cfgstruct.PromptForEncryptionKey() humanReadableKey, err := wizard.PromptForEncryptionKey()
if err != nil { if err != nil {
return err return err
} }