Skip to content

Commit

Permalink
Config show for each nodes from Bastion server
Browse files Browse the repository at this point in the history
Signed-off-by: Arvinth C <arvinth.chandrasekaran@progress.com>
  • Loading branch information
ArvinthC3000 committed Nov 25, 2022
1 parent e792e0d commit ebc62ed
Showing 1 changed file with 65 additions and 9 deletions.
74 changes: 65 additions & 9 deletions components/automate-cli/cmd/chef-automate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
automate-backend-ctl applied --svc=automate-ha-%s
`

GET_FRONTEND_CONFIGS = `sudo chef-automate config show`

dateFormat = "%Y%m%d%H%M%S"

postgresql = "postgresql"
Expand All @@ -70,7 +72,12 @@ func init() {
configCmd.AddCommand(patchConfigCmd)
configCmd.AddCommand(setConfigCmd)

showConfigCmd.Flags().BoolVarP(&configCmdFlags.overwriteFile, "overwrite", "o", false, "Overwrite existing config.toml")
showConfigCmd.Flags().BoolVarP(&configCmdFlags.overwriteFile, "overwrite", "O", false, "Overwrite existing config.toml [Standalone]")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.automate, "automate", "a", false, "Shows configurations from Automate node(HA)")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.chef_server, "chef_server", "c", false, "Shows configurations from Chef-server node(HA)")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.postgresql, "postgresql", "p", false, "Shows configurations from PostgresQL node")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.opensearch, "opensearch", "o", false, "Shows configurations from OpenSearch node")

patchConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.frontend, "frontend", "f", false, "Patch toml configuration to the all frontend nodes")
patchConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.frontend, "fe", false, "Patch toml configuration to the all frontend nodes[DUPLICATE]")

Expand Down Expand Up @@ -99,7 +106,7 @@ var showConfigCmd = &cobra.Command{
Short: "show the Chef Automate configuration",
Long: "Show the Chef Automate configuration. When given a filepath, the output will be written to the file instead of printed to STDOUT",
RunE: runShowCmd,
Args: cobra.RangeArgs(0, 1),
Args: cobra.RangeArgs(0, 2),
}

var patchConfigCmd = &cobra.Command{
Expand All @@ -118,6 +125,61 @@ var setConfigCmd = &cobra.Command{
}

func runShowCmd(cmd *cobra.Command, args []string) error {

if isA2HARBFileExist() {

infra, err := getAutomateHAInfraDetails()
if err != nil {
return err
}

sshUser := infra.Outputs.SSHUser.Value
sskKeyFile := infra.Outputs.SSHKeyFile.Value
sshPort := infra.Outputs.SSHPort.Value

sshConfig := &SSHConfig{
sshUser: sshUser,
sshKeyFile: sskKeyFile,
sshPort: sshPort,
}
sshUtil := NewSSHUtil(sshConfig)

writer.Bodyf("%v", configCmdFlags)
if configCmdFlags.overwriteFile {
writer.Error("Overwrite flag is not supported in HA")
// return errors.New("Node not mentioned")
}

var scriptCommand string
var hostIpArray []string
switch true {
case configCmdFlags.automate:
hostIpArray = append(hostIpArray, infra.Outputs.AutomatePrivateIps.Value[0])
scriptCommand = GET_FRONTEND_CONFIGS
case configCmdFlags.chef_server:
hostIpArray = append(hostIpArray, infra.Outputs.ChefServerPrivateIps.Value[0])
scriptCommand = GET_FRONTEND_CONFIGS
case configCmdFlags.postgresql:
hostIpArray = infra.Outputs.PostgresqlPrivateIps.Value
scriptCommand = fmt.Sprintf(GET_CONFIG, "postgresql")
case configCmdFlags.opensearch:
hostIpArray = infra.Outputs.OpensearchPrivateIps.Value
scriptCommand = fmt.Sprintf(GET_CONFIG, "opensearch")
default:
return errors.New("Unsupported flag")
}
for i := 0; i < len(hostIpArray); i++ {
sshUtil.getSSHConfig().hostIP = hostIpArray[i]
output, err := sshUtil.connectAndExecuteCommandOnRemote(scriptCommand, true)
if err != nil {
return err
}
writer.Success("Config on node IP: " + hostIpArray[i] + "\n")
writer.Println(output)
}

return nil
}
res, err := client.GetAutomateConfig(configCmdFlags.timeout)
if err != nil {
return err
Expand Down Expand Up @@ -540,17 +602,11 @@ func getConfigForArgsPostgresqlOrOpenSearch(args []string, remoteService string)
}
return dest, nil
}

return nil, nil

}

// isConfigChanged checks if configuration is changed
func isConfigChanged(src interface{}, dest interface{}) bool {
if reflect.DeepEqual(src, dest) {
return false
}
return true
return !reflect.DeepEqual(src, dest)
}

// getExistingAndRequestedConfigForPostgres get requested and existing config for postgresql
Expand Down

0 comments on commit ebc62ed

Please sign in to comment.