Skip to content

Commit cdd045a

Browse files
authored
feat(cli): better ux in account validation (#187)
This change will add a better user-experience to the lacework configure command so that if the user provides the complete URL as the account name we will subtract the account and notify the end-user: ``` $ lacework configure Passing '.lacework.net' domain not required. Using 'tech-ally' ▸ Account: tech-ally ▸ Access Key ID: TECHALLY_1234567890 ▸ Secret Access Key: (*****************************91f3) You are all set! ``` Closes #86 Signed-off-by: Salim Afiune Maya <[email protected]>
1 parent b206cf1 commit cdd045a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cli/cmd/configure.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"fmt"
2525
"io/ioutil"
2626
"path"
27+
"regexp"
28+
"strings"
2729

2830
"github.com/AlecAivazis/survey/v2"
2931
"github.com/BurntSushi/toml"
@@ -147,6 +149,23 @@ func promptConfigureSetup() error {
147149
Validate: promptRequiredStringLen(1,
148150
"The account subdomain of URL is required. (i.e. <ACCOUNT>.lacework.net)",
149151
),
152+
Transform: func(ans interface{}) interface{} {
153+
answer, ok := ans.(string)
154+
if ok && strings.Contains(answer, ".lacework.net") {
155+
// if the provided account is the full URL ACCOUNT.lacework.net
156+
// subtract the account name and inform the user
157+
rx, err := regexp.Compile(`\.lacework\.net.*`)
158+
if err == nil {
159+
accountSplit := rx.Split(answer, -1)
160+
if len(accountSplit) != 0 {
161+
cli.OutputHuman("Passing '.lacework.net' domain not required. Using '%s'\n", accountSplit[0])
162+
return accountSplit[0]
163+
}
164+
}
165+
}
166+
167+
return ans
168+
},
150169
},
151170
{
152171
Name: "api_key",

integration/configure_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ func TestConfigureCommandErrors(t *testing.T) {
242242
c.ExpectString("Account:")
243243
c.SendLine("")
244244
c.ExpectString("The account subdomain of URL is required")
245-
c.SendLine("my-account")
245+
c.SendLine("my-account.lacework.net") // if the full URL was provided we transform it and inform the user
246+
c.ExpectString("Passing '.lacework.net' domain not required. Using 'my-account'")
246247
c.ExpectString("Access Key ID:")
247248
c.SendLine("")
248249
c.ExpectString("The API access key id must have more than 55 characters")

0 commit comments

Comments
 (0)