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

Commit 702e2f9

Browse files
committed
Remove with setup code option and make setup code a credential provider
This commit also makes the cli point to the version of the client containing the required changes.
1 parent 5c020c2 commit 702e2f9

5 files changed

Lines changed: 6 additions & 19 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/pkg/errors v0.9.1 // indirect
1919
github.com/secrethub/demo-app v0.1.0
20-
github.com/secrethub/secrethub-go v0.30.1-0.20200812121649-846d80e97296
20+
github.com/secrethub/secrethub-go v0.30.1-0.20200814123323-7aac428a99e4
2121
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2222
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
2323
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ github.com/secrethub/secrethub-go v0.30.1-0.20200812113929-edff110cddfc h1:dN6YU
168168
github.com/secrethub/secrethub-go v0.30.1-0.20200812113929-edff110cddfc/go.mod h1:ZIco8Y0G0Pi0Vb7pQROjvEKgSreZiRMLhAbzWUneUSQ=
169169
github.com/secrethub/secrethub-go v0.30.1-0.20200812121649-846d80e97296 h1:IsbGXusKlVYSThYYepv80H0S9dXYOWMHDSNgoEamt1c=
170170
github.com/secrethub/secrethub-go v0.30.1-0.20200812121649-846d80e97296/go.mod h1:ZIco8Y0G0Pi0Vb7pQROjvEKgSreZiRMLhAbzWUneUSQ=
171+
github.com/secrethub/secrethub-go v0.30.1-0.20200814123323-7aac428a99e4 h1:zIOs8q0BK5pI55Fa8y3MMuxIfD7nAv9sh+3GbOiT6hM=
172+
github.com/secrethub/secrethub-go v0.30.1-0.20200814123323-7aac428a99e4/go.mod h1:ZIco8Y0G0Pi0Vb7pQROjvEKgSreZiRMLhAbzWUneUSQ=
171173
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
172174
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
173175
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/secrethub/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (app *App) registerCommands() {
173173
NewEnvCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
174174

175175
// Commands
176-
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.clientFactory.NewClientWithSetupCode, app.credentialStore).Register(app.cli)
176+
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
177177
NewSignUpCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.credentialStore).Register(app.cli)
178178
NewWriteCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
179179
NewReadCommand(app.io, app.clientFactory.NewClient).Register(app.cli)

internals/secrethub/client_factory.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type ClientFactory interface {
2020
// NewClient returns a new SecretHub client.
2121
NewClient() (secrethub.ClientInterface, error)
2222
NewClientWithCredentials(credentials.Provider) (secrethub.ClientInterface, error)
23-
NewClientWithSetupCode(code string) (secrethub.ClientInterface, error)
2423
NewUnauthenticatedClient() (secrethub.ClientInterface, error)
2524
Register(FlagRegisterer)
2625
}
@@ -89,18 +88,6 @@ func (f *clientFactory) NewClientWithCredentials(provider credentials.Provider)
8988
return client, nil
9089
}
9190

92-
func (f *clientFactory) NewClientWithSetupCode(code string) (secrethub.ClientInterface, error) {
93-
options := f.baseClientOptions()
94-
options = append(options, secrethub.WithSetupCode(code))
95-
96-
client, err := secrethub.NewClient(options...)
97-
if err != nil {
98-
return nil, err
99-
}
100-
101-
return client, nil
102-
}
103-
10491
func (f *clientFactory) NewUnauthenticatedClient() (secrethub.ClientInterface, error) {
10592
options := f.baseClientOptions()
10693

internals/secrethub/init.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ type InitCommand struct {
2424
io ui.IO
2525
newUnauthenticatedClient newClientFunc
2626
newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error)
27-
newClientWithSetupCode func(string) (secrethub.ClientInterface, error)
2827
credentialStore CredentialConfig
2928
progressPrinter progress.Printer
3029
}
3130

3231
// NewInitCommand creates a new InitCommand.
33-
func NewInitCommand(io ui.IO, newUnauthenticatedClient newClientFunc, newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error), newClientWithSetupCode func(string) (secrethub.ClientInterface, error), credentialStore CredentialConfig) *InitCommand {
32+
func NewInitCommand(io ui.IO, newUnauthenticatedClient newClientFunc, newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error), credentialStore CredentialConfig) *InitCommand {
3433
return &InitCommand{
3534
io: io,
3635
newUnauthenticatedClient: newUnauthenticatedClient,
3736
newClientWithCredentials: newClientWithCredentials,
38-
newClientWithSetupCode: newClientWithSetupCode,
3937
credentialStore: credentialStore,
4038
progressPrinter: progress.NewPrinter(io.Output(), 500*time.Millisecond),
4139
}
@@ -159,7 +157,7 @@ func (cmd *InitCommand) Run() error {
159157
fmt.Fprint(cmd.io.Output(), "Setting up your account...")
160158
cmd.progressPrinter.Start()
161159

162-
client, err := cmd.newClientWithSetupCode(setupCode)
160+
client, err := cmd.newClientWithCredentials(credentials.NewSetupCode(setupCode))
163161
if err != nil {
164162
cmd.progressPrinter.Stop()
165163
return err

0 commit comments

Comments
 (0)