-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.go
81 lines (65 loc) · 1.96 KB
/
configure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cloud
import (
"fmt"
"github.com/spf13/cobra"
"github.com/appbricks/cloud-builder/auth"
"github.com/mevansam/gocloud/provider"
"github.com/mevansam/goforms/forms"
"github.com/mevansam/goforms/ux"
cbcli_auth "github.com/appbricks/cloud-builder-cli/auth"
cbcli_config "github.com/appbricks/cloud-builder-cli/config"
cbcli_utils "github.com/appbricks/cloud-builder-cli/utils"
)
var configureCommand = &cobra.Command{
Use: "configure [cloud]",
Short: "Configure cloud credentials.",
Long: `
Recipe resources are created in the public cloud using your cloud
credentials. This requires that you have a valid cloud account in one
or more of the clouds the recipe can be launched in. This sub-command
can be used to configure your cloud credentials for the cloud
environments you wish to target.
`,
PreRun: cbcli_auth.AssertAuthorized(auth.NewRoleMask(auth.Admin), nil),
Run: func(cmd *cobra.Command, args []string) {
ConfigureCloud(args[0])
},
Args: cobra.ExactArgs(1),
}
func ConfigureCloud(name string) {
var (
err error
provider provider.CloudProvider
inputForm forms.InputForm
)
if provider, err = cbcli_config.Config.TargetContext().GetCloudProvider(name); err == nil && provider != nil {
if inputForm, err = provider.InputForm(); err != nil {
cbcli_utils.ShowErrorAndExit(err.Error())
}
if err = ux.GetFormInput(inputForm,
"Cloud Provider Configuration",
"CONFIGURATION DATA INPUT",
2, 80, "provider",
); err != nil {
cbcli_utils.ShowErrorAndExit(err.Error())
}
cbcli_config.Config.TargetContext().SaveCloudProvider(provider)
fmt.Print("\nConfiguration input saved\n\n")
return
}
if err != nil {
cbcli_utils.ShowErrorAndExit(err.Error())
} else {
cbcli_utils.ShowErrorAndExit(
fmt.Sprintf(
"Unknown cloud IaaS name \"%s\" given to the configure "+
"command.Run 'cb cloud list' to get list of available clouds.",
name,
),
)
}
}
func init() {
flags := showCommand.Flags()
flags.SortFlags = false
}