/
secretsHa.go
75 lines (67 loc) · 1.76 KB
/
secretsHa.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
// Copyright © 2017 Chef Software
package main
import (
"errors"
"strings"
"github.com/chef/automate/components/automate-cli/pkg/docs"
"github.com/chef/automate/components/automate-cli/pkg/status"
"github.com/spf13/cobra"
)
func init() {
secretsCmd.SetUsageTemplate(secretsHelpDocs)
RootCmd.AddCommand(secretsCmd)
}
var secretsCmd = &cobra.Command{
Use: "secrets",
Short: "Set secrets to Automate HA",
Long: "Set secrets for Automate sudo password and admin password in HA mode.",
Annotations: map[string]string{
NoCheckVersionAnnotation: NoCheckVersionAnnotation,
docs.Compatibility: docs.CompatiblewithHA,
},
Args: cobra.RangeArgs(0, 2),
RunE: runSecretsConfigCmd,
}
func runSecretsConfigCmd(cmd *cobra.Command, args []string) error {
if !isA2HARBFileExist() {
return errors.New(AUTOMATE_HA_INVALID_BASTION)
}
operation := ""
for _, v := range args {
if v == "init" {
operation = "init"
break
}
if v == "set" {
operation = "set"
break
}
}
if operation == "init" {
response, err := writer.Prompt("your key might get rotated, Would you like to create a new key or rotate the existing credentials? y/n")
if err != nil {
return err
}
if !strings.Contains(response, "y") {
return errors.New("canceled secrets init")
}
}
if operation == "set" {
response, err := writer.Prompt("Enter secret: ")
if err != nil {
return err
}
args = append(args, response)
}
return executeSecretsCommand(args)
}
func executeSecretsCommand(args []string) error {
if isA2HARBFileExist() {
if len(args) == 0 {
writer.Print("please refer \n" + secretsHelpDocs)
return nil
}
return executeAutomateClusterCtlCommand("secrets", args, secretsHelpDocs)
}
return status.New(status.InvalidCommandArgsError, secretsHelpDocs)
}