From 3d770a1171814e33de7f6420d1637ad8c03f30c8 Mon Sep 17 00:00:00 2001 From: Salim Afiune Date: Tue, 12 Jan 2021 14:29:14 +0100 Subject: [PATCH] feat(cli): add account check to catch http(s):// (#288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have found out that users are trying to pass the full URL as the account setting when running the `configure` command: ``` $ lacework configure ▸ Account: http://my-account.lacework.net/ ``` This change is adding a check to catch when users pass the prefix `http://` or `https://`. Signed-off-by: Salim Afiune Maya --- cli/cmd/configure.go | 15 ++++++++++++--- integration/configure_unix_test.go | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cli/cmd/configure.go b/cli/cmd/configure.go index 0fcfb1e67..aee022a7f 100644 --- a/cli/cmd/configure.go +++ b/cli/cmd/configure.go @@ -231,16 +231,25 @@ func promptConfigureSetup() error { Transform: func(ans interface{}) interface{} { answer, ok := ans.(string) if ok && strings.Contains(answer, ".lacework.net") { - // if the provided account is the full URL ACCOUNT.lacework.net + // if the provided account is the full URL https://ACCOUNT.lacework.net + // remove the prefix https:// or http:// + rx, err := regexp.Compile(`(http://|https://)`) + if err == nil { + answer = rx.ReplaceAllString(answer, "") + } + + // if the provided account is the full domain ACCOUNT.lacework.net // subtract the account name and inform the user - rx, err := regexp.Compile(`\.lacework\.net.*`) + rx, err = regexp.Compile(`\.lacework\.net.*`) if err == nil { accountSplit := rx.Split(answer, -1) if len(accountSplit) != 0 { - cli.OutputHuman("Passing '.lacework.net' domain not required. Using '%s'\n", accountSplit[0]) + cli.OutputHuman("Passing full 'lacework.net' domain not required. Using '%s'\n", accountSplit[0]) return accountSplit[0] } } + + return answer } return ans diff --git a/integration/configure_unix_test.go b/integration/configure_unix_test.go index 19619a619..aff834430 100644 --- a/integration/configure_unix_test.go +++ b/integration/configure_unix_test.go @@ -194,8 +194,8 @@ func TestConfigureCommandErrors(t *testing.T) { c.ExpectString("Account:") c.SendLine("") c.ExpectString("The account subdomain of URL is required") - c.SendLine("my-account.lacework.net") // if the full URL was provided we transform it and inform the user - c.ExpectString("Passing '.lacework.net' domain not required. Using 'my-account'") + c.SendLine("https://my-account.lacework.net") // if the full URL was provided we transform it and inform the user + c.ExpectString("Passing full 'lacework.net' domain not required. Using 'my-account'") c.ExpectString("Access Key ID:") c.SendLine("") c.ExpectString("The API access key id must have more than 55 characters")