Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit b7b23ab

Browse files
authored
Merge pull request #225 from secrethub/feature/validate-bootstrap-code
Use new client function to validate backup code input
2 parents 7b61fe7 + 48414ce commit b7b23ab

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/mitchellh/mapstructure v1.1.2
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/secrethub/demo-app v0.1.0
19-
github.com/secrethub/secrethub-go v0.23.1-0.20191202095158-6e6ed56b9d3f
19+
github.com/secrethub/secrethub-go v0.23.1-0.20191202112815-8e4536fffb73
2020
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2121
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
2222
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
7272
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
7373
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
7474
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
75-
github.com/secrethub/secrethub-go v0.23.1-0.20191202095158-6e6ed56b9d3f h1:T09TTodgSY3+QQYyLOYdpAqGri2kjK1U04KN0Tak2HY=
76-
github.com/secrethub/secrethub-go v0.23.1-0.20191202095158-6e6ed56b9d3f/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
75+
github.com/secrethub/secrethub-go v0.23.1-0.20191202112815-8e4536fffb73 h1:TChbs2D26POGnhQ87QWCg17b3PQukTHPaxgGxAxxTgU=
76+
github.com/secrethub/secrethub-go v0.23.1-0.20191202112815-8e4536fffb73/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
7777
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
7878
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7979
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/secrethub/init.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"os"
7-
"regexp"
87
"time"
98

109
"github.com/secrethub/secrethub-cli/internals/cli/progress"
@@ -113,26 +112,15 @@ func (cmd *InitCommand) Run() error {
113112
}
114113
return signupCommand.Run()
115114
case InitModeBackupCode:
116-
filterFunc := func(code string) string {
117-
reg := regexp.MustCompile("[^a-zA-Z0-9]+")
118-
return reg.ReplaceAllString(code, "")
119-
}
120-
121115
backupCode := cmd.backupCode
122116

123117
if backupCode == "" {
124118
var err error
125-
backupCode, err = ui.AskAndValidate(cmd.io, "What is your backup code?\n", 3, func(code string) error {
126-
if len(filterFunc(code)) != 64 {
127-
return errors.New("code should consist of 64 hexadecimal characters")
128-
}
129-
return nil
130-
})
119+
backupCode, err = ui.AskAndValidate(cmd.io, "What is your backup code?\n", 3, credentials.ValidateBootstrapCode)
131120
if err != nil {
132121
return err
133122
}
134123
}
135-
backupCode = filterFunc(backupCode)
136124

137125
client, err := cmd.newClientWithoutCredentials(credentials.UseBackupCode(backupCode))
138126
if err != nil {

0 commit comments

Comments
 (0)