Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating config-gen and error messages #8122

Merged
merged 6 commits into from Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,7 +9,7 @@ const (
SUDO_PASSWORD_SUCCESS_MESSAGE = "SSH user sudo password is valid for the node: "
SSH_USER_FAILURE_TITLE = "SSH user unaccessible"
SSH_USER_ERROR_MESSAGE = "SSH user is unaccessible for the node with IP: "
SSH_USER_RESOLUTION_MESSAGE = "Give SSH access to the user with the give key on the node: "
SSH_USER_RESOLUTION_MESSAGE = "Give SSH access to the user with the given key on the node: "
SUDO_PASSWORD_FAILURE_TITLE = "Sudo password invalid"
SUDO_PASSWORD_ERROR_MESSAGE = "SSH user sudo password is invalid for the node with IP: "
SUDO_PASSWORD_FAILURE_RESOLUTION_MESSAGE = "Ensure you have provided the correct sudo password and the user has sudo access on the node: "
Expand Down
Expand Up @@ -201,7 +201,7 @@ func TestCheckSshConnection(t *testing.T) {
Passed: false,
SuccessMsg: "",
ErrorMsg: "SSH user is unaccessible for the node with IP: " + nodeIp,
ResolutionMsg: "Give SSH access to the user with the give key on the node: " + nodeIp,
ResolutionMsg: "Give SSH access to the user with the given key on the node: " + nodeIp,
},
{
Title: FailureSudoPassword,
Expand Down
250 changes: 173 additions & 77 deletions lib/config/genconfig/awshaprovisionconfig.go

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions lib/config/genconfig/awshaprovisionconfig_test.go
Expand Up @@ -5,10 +5,12 @@ import (
"errors"
"fmt"
"io"
"net/http"
"os"
"testing"

"github.com/chef/automate/lib/config"
"github.com/chef/automate/lib/httputils"
"github.com/chef/automate/lib/io/fileutils"
"github.com/chef/automate/lib/ioutils"
"github.com/chef/automate/lib/pmt"
Expand Down Expand Up @@ -47,6 +49,8 @@ func TestPromptsCidrAWSManaged(t *testing.T) {
enableCustomCerts := false
input(b, "\r")

input(b, moveDown+"\r")

awsProfile := "default"
input(b, "\r")

Expand Down Expand Up @@ -145,6 +149,9 @@ func TestPromptsCidrAWSManaged(t *testing.T) {
osDefaultCerts := true
input(b, "\r")

// To not skip role cred
input(b, moveDown+"\r")

osSnapshotRoleArn := "arn-os-snapshot-role"
input(b, osSnapshotRoleArn+"\r")

Expand Down Expand Up @@ -208,6 +215,21 @@ func TestPromptsCidrAWSManaged(t *testing.T) {
Prompt: p,
FileUtils: mfsu,
Config: &config.HaDeployConfig{},
httpRequestClient: &httputils.MockHTTPClient{
MakeRequestWithHeadersfunc: func(requestMethod, url string, body interface{}, headerkey, headerValue string) (*http.Response, []byte, error) {
if url == TOKEN_URLS {
return &http.Response{
StatusCode: 200,
}, []byte("dummytoken"), nil
}
return &http.Response{StatusCode: 200}, []byte(`{
"Code" : "Success",
"LastUpdated" : "2023-08-09T11:23:21Z",
"InstanceProfileArn" : "arn:aws:iam::1234:instance-profile/bastion-role-user",
"InstanceProfileId" : "AIPARHU"
}`), nil
},
},
}

err := c.Prompts()
Expand Down Expand Up @@ -1124,6 +1146,21 @@ func testPromptsCidrAWSManagedErrRun(t *testing.T, upto int) {
Prompt: p,
FileUtils: mfsu,
Config: &config.HaDeployConfig{},
httpRequestClient: &httputils.MockHTTPClient{
MakeRequestWithHeadersfunc: func(requestMethod, url string, body interface{}, headerkey, headerValue string) (*http.Response, []byte, error) {
if url == TOKEN_URLS {
return &http.Response{
StatusCode: 200,
}, []byte("dummytoken"), nil
}
return &http.Response{StatusCode: 200}, []byte(`{
"Code" : "Success",
"LastUpdated" : "2023-08-09T11:23:21Z",
"InstanceProfileArn" : "arn:aws:iam::1234:instance-profile/bastion-role-user",
"InstanceProfileId" : "AIPARHU"
}`), nil
},
},
}

err := c.Prompts()
Expand Down Expand Up @@ -1156,6 +1193,9 @@ func callInput(upto int, b *bytes.Buffer) {
if upto >= 5 {
input(b, "\r")
}
if upto >= 5 {
input(b, moveDown+"\r")
}
if upto >= 6 {
input(b, "\r")
}
Expand Down
38 changes: 19 additions & 19 deletions lib/config/genconfig/hadeployconfig.go
Expand Up @@ -94,7 +94,7 @@ func (c *HaDeployConfigGen) Prompts() (err error) {
}

func (c *HaDeployConfigGen) PromptCustomCerts() (err error) {
noCustomCerts, err := c.Prompt.Confirm("Will you use custom certs for any service like Automate, Chef Infra Server, PostgreSQL, OpenSearch", "no", "yes")
noCustomCerts, err := c.Prompt.Confirm("Use custom certs for one or all service like Automate, Chef Infra Server, PostgreSQL, OpenSearch", "no", "yes")
if err != nil {
return
}
Expand All @@ -117,7 +117,7 @@ func (c *HaDeployConfigGen) SetDefaultValuesForDBNodes() {
}

func (c *HaDeployConfigGen) PromptExternalDb() (hasExternalDb bool, err error) {
hasExternalDb, err = c.Prompt.Confirm("Are you going to use External Databases, like AWS RDS and AWS OpenSearch", "yes", "no")
hasExternalDb, err = c.Prompt.Confirm("Use External Databases for PostgresQL and OpenSearch", "yes", "no")
if err != nil {
return
}
Expand All @@ -143,7 +143,7 @@ func (c *HaDeployConfigGen) PromptExternalDb() (hasExternalDb bool, err error) {
}

func (c *HaDeployConfigGen) PromptExternalDbType() (err error) {
isAWSManaged, err := c.Prompt.Confirm("Type of External DB you will use", "AWS Managed", "Self Managed")
isAWSManaged, err := c.Prompt.Confirm("Type of External DB", "AWS Managed", "Self Managed")
if err != nil {
return
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func (c *HaDeployConfigGen) GetExternalOsType() (dbType string) {
}

func (c *HaDeployConfigGen) PromptExternalPostgresqlInstanceUrl() (err error) {
pgUrl, err := c.Prompt.InputStringRegex(c.GetExternalPgType()+" URL:<port>", URL_REQUIRED_PORT_REGEX)
pgUrl, err := c.Prompt.InputStringRegex(c.GetExternalPgType()+" [Eg: pgdomain.com:5432]", URL_REQUIRED_PORT_REGEX)
if err != nil {
return
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (c *HaDeployConfigGen) PromptExternalPostgresqlDbUserPassword() (err error)
func (c *HaDeployConfigGen) PromptExternalPostgresqlRootCert() (err error) {
if c.Config.External.Database.Type == "aws" {
awsDefaultCert := false
awsDefaultCert, err = c.Prompt.Confirm("Do you want to use Default AWS Cert to connect with AWS Managed RDS PostgreSQL URL", "yes", "no")
awsDefaultCert, err = c.Prompt.Confirm("Use Default AWS Cert to connect with AWS Managed RDS PostgreSQL URL", "yes", "no")
if err != nil {
return
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (c *HaDeployConfigGen) PromptExternalPostgresqlRootCert() (err error) {
}

func (c *HaDeployConfigGen) PromptExternalOpenSearchDomainName() (err error) {
domainName, err := c.Prompt.InputStringRequired(c.GetExternalOsType() + " Domain Name")
domainName, err := c.Prompt.InputStringRequired(c.GetExternalOsType() + " Domain Name [Eg: chef-opensearch]")
if err != nil {
return
}
Expand All @@ -346,7 +346,7 @@ func (c *HaDeployConfigGen) PromptExternalOpenSearchDomainName() (err error) {
}

func (c *HaDeployConfigGen) PromptExternalOpenSearchDomainUrl() (err error) {
domainUrl, err := c.Prompt.InputStringRegex(c.GetExternalOsType()+" Domain URL", URL_OPTIONAL_PORT_REGEX)
domainUrl, err := c.Prompt.InputStringRegex(c.GetExternalOsType()+" Domain URL [Eg: chef-opensearch.myosdomain.com]", URL_OPTIONAL_PORT_REGEX)
if err != nil {
return
}
Expand All @@ -356,7 +356,7 @@ func (c *HaDeployConfigGen) PromptExternalOpenSearchDomainUrl() (err error) {
}

func (c *HaDeployConfigGen) PromptExternalOpenSearchUser() (err error) {
user, err := c.Prompt.InputStringRequired(c.GetExternalOsType() + " Username")
user, err := c.Prompt.InputStringRequired(c.GetExternalOsType() + " Username [Eg: admin]")
if err != nil {
return
}
Expand All @@ -378,7 +378,7 @@ func (c *HaDeployConfigGen) PromptExternalOpenSearchPassword() (err error) {
func (c *HaDeployConfigGen) PromptExternalOpenSearchRootCert() (err error) {
if c.Config.External.Database.Type == "aws" {
awsDefaultCert := false
awsDefaultCert, err = c.Prompt.Confirm("Do you want to use Default AWS Cert to connect with AWS Managed OpenSearch Domain URL", "yes", "no")
awsDefaultCert, err = c.Prompt.Confirm("Use Default AWS Cert to connect with AWS Managed OpenSearch Domain URL", "yes", "no")
if err != nil {
return
}
Expand Down Expand Up @@ -778,13 +778,13 @@ func (c *HaDeployConfigGen) PromptNodeIp(msg string) (ip string, err error) {

func (c *HaDeployConfigGen) PromptHaveCustomCerts(nodeType string) (customCerts, customCertsPerNode bool, err error) {
if c.HasCustomCerts {
customCerts, err = c.Prompt.Confirm("Do you have custom certs for "+nodeType+" Nodes", "yes", "no")
customCerts, err = c.Prompt.Confirm("Use custom certs for "+nodeType+" Nodes", "yes", "no")
if err != nil {
return
}

if customCerts {
commonCerts, err1 := c.Prompt.Confirm("Do each "+nodeType+" Node have same Certs", "yes", "no")
commonCerts, err1 := c.Prompt.Confirm("Use same Certs for all "+nodeType+" Node", "yes", "no")
if err1 != nil {
return commonCerts, customCertsPerNode, err1
}
Expand Down Expand Up @@ -892,7 +892,7 @@ func (c *HaDeployConfigGen) PromptAutomateCerts(hasCustomCerts, hasCustomCertsPe
}

func (c *HaDeployConfigGen) PromptChefInfraServerFqdn() (err error) {
chefInfraServerFqdn, err := c.Prompt.InputStringRegex("Chef Infra Server FQDN", FQDN_REGEX)
chefInfraServerFqdn, err := c.Prompt.InputStringRegex("Chef Infra Server FQDN [Eg: my-infraserver-domain.com]", FQDN_REGEX)
if err != nil {
return
}
Expand All @@ -902,7 +902,7 @@ func (c *HaDeployConfigGen) PromptChefInfraServerFqdn() (err error) {
}

func (c *HaDeployConfigGen) PromptChefInfraServerFqdnRootCa() (err error) {
chefInfraServerFqdnRootCaFilePath, err := c.Prompt.InputExistingFilePath("Chef Infra Server FQDN Root CA File Path")
chefInfraServerFqdnRootCaFilePath, err := c.Prompt.InputExistingFilePath("Chef Infra Server FQDN Root CA File Path [Eg: /home/ubuntu/fqdn2-root-ca.pem]")
if err != nil {
return
}
Expand All @@ -921,7 +921,7 @@ func (c *HaDeployConfigGen) PromptChefInfraServerFqdnRootCa() (err error) {
}

func (c *HaDeployConfigGen) PromptAutomateFqdn() (err error) {
automateFqdn, err := c.Prompt.InputStringRegex("Automate FQDN", FQDN_REGEX)
automateFqdn, err := c.Prompt.InputStringRegex("Automate FQDN [Eg: my-automate-domain.com]", FQDN_REGEX)
if err != nil {
return
}
Expand All @@ -931,7 +931,7 @@ func (c *HaDeployConfigGen) PromptAutomateFqdn() (err error) {
}

func (c *HaDeployConfigGen) PromptAutomateFqdnRootCa() (err error) {
automateFqdnRootCaFilePath, err := c.Prompt.InputExistingFilePath("Automate FQDN Root CA File Path")
automateFqdnRootCaFilePath, err := c.Prompt.InputExistingFilePath("Automate FQDN Root CA File Path [Eg: /home/ubuntu/fqdn2-root-ca.pem]")
if err != nil {
return
}
Expand Down Expand Up @@ -980,7 +980,7 @@ func (c *HaDeployConfigGen) PromptSshPort() (err error) {
}

func (c *HaDeployConfigGen) PromptSshKey() (err error) {
sshKeyFile, err := c.Prompt.InputExistingFilePathDefault("SSH Key File", "~/.ssh/id_rsa")
sshKeyFile, err := c.Prompt.InputExistingFilePath("SSH Key File Path [*.pem downloaded for SSH Key Pair from AWS]")
if err != nil {
return
}
Expand Down Expand Up @@ -1021,11 +1021,11 @@ func (c *HaDeployConfigGen) DefaultExistingInfraValues() {
}

func (c *HaDeployConfigGen) PromptBackup() (err error) {
isBackupNeeded, err := c.Prompt.Confirm("Backup need to be configured during deployment", "yes", "no")
isBackupNeeded, err := c.Prompt.Confirm("Configured backup during deployment", "yes", "no")
if isBackupNeeded {
c.Config.InitArchitecture().InitExistingInfra().BackupMount = "/mnt/automate_backups"

_, backupOption, err1 := c.Prompt.Select("Which backup option will you use", AWS_S3, MINIO, OBJECT_STORE, FILE_SYSTEM, NFS, EFS)
_, backupOption, err1 := c.Prompt.Select("Choose backup option", AWS_S3, MINIO, OBJECT_STORE, FILE_SYSTEM, NFS, EFS)
if err1 != nil {
return err1
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ func (c *HaDeployConfigGen) PromptBackup() (err error) {

func (c *HaDeployConfigGen) PromptObjectStorageSettings(backupOption string) (err error) {

bucketName, err := c.Prompt.InputStringRegex("Backup bucket name", BUCKET_NAME_REGEX)
bucketName, err := c.Prompt.InputStringRegex("Bucket name", BUCKET_NAME_REGEX)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions lib/config/hadeployconfig.go
Expand Up @@ -149,9 +149,9 @@ type ConfigAwsSettings struct {
ManagedOpensearchUsername string `toml:"managed_opensearch_username,omitempty"`
ManagedOpensearchUserPassword string `toml:"managed_opensearch_user_password,omitempty"`
ManagedOpensearchCertificate string `toml:"managed_opensearch_certificate,omitempty"`
AwsOsSnapshotRoleArn string `toml:"aws_os_snapshot_role_arn,omitempty"`
OsSnapshotUserAccessKeyID string `toml:"os_snapshot_user_access_key_id,omitempty"`
OsSnapshotUserAccessKeySecret string `toml:"os_snapshot_user_access_key_secret,omitempty"`
AwsOsSnapshotRoleArn string `toml:"aws_os_snapshot_role_arn"`
OsSnapshotUserAccessKeyID string `toml:"os_snapshot_user_access_key_id"`
OsSnapshotUserAccessKeySecret string `toml:"os_snapshot_user_access_key_secret"`
ManagedRdsInstanceURL string `toml:"managed_rds_instance_url,omitempty"`
ManagedRdsSuperuserUsername string `toml:"managed_rds_superuser_username,omitempty"`
ManagedRdsSuperuserPassword string `toml:"managed_rds_superuser_password,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions lib/pmt/prompt.go
Expand Up @@ -15,10 +15,11 @@ import (
)

const (
FAIL_MSG = "prompt failed %v"
INVALID_INT = "invalid int"
PARSE_INT_FAIL = "parse int failed %v"
REGEX_CHECK_FAIL = "regex check failed (%v) "
FAIL_MSG = "prompt failed %v"
INVALID_INT = "invalid int"
PARSE_INT_FAIL = "parse int failed %v"
REGEX_CHECK_FAIL = "input value failed to matched with expected pattern (%v)"
REGEX_CHECK_FAIL_WITH_SAMPLE_STRING = "regex check failed. Sample Value: %v"
)
const esc = "\033["
const moveDown = esc + "1B"
Expand Down