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

Commit 114e34e

Browse files
Merge pull request #369 from secrethub/feature/remove-unauthenticated-client
Remove unauthenticated client
2 parents b24de2d + c1f2527 commit 114e34e

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

internals/secrethub/app.go

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

177177
// Commands
178-
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
178+
NewInitCommand(app.io, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
179179
NewSignUpCommand(app.io).Register(app.cli)
180180
NewWriteCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
181181
NewReadCommand(app.io, app.clientFactory.NewClient).Register(app.cli)

internals/secrethub/client_factory.go

Lines changed: 0 additions & 12 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-
NewUnauthenticatedClient() (secrethub.ClientInterface, error)
2423
Register(FlagRegisterer)
2524
}
2625

@@ -89,17 +88,6 @@ func (f *clientFactory) NewClientWithCredentials(provider credentials.Provider)
8988
return client, nil
9089
}
9190

92-
func (f *clientFactory) NewUnauthenticatedClient() (secrethub.ClientInterface, error) {
93-
options := f.baseClientOptions()
94-
95-
client, err := secrethub.NewClient(options...)
96-
if err != nil {
97-
return nil, err
98-
}
99-
100-
return client, nil
101-
}
102-
10391
func (f *clientFactory) baseClientOptions() []secrethub.ClientOption {
10492
options := []secrethub.ClientOption{
10593
secrethub.WithConfigDir(f.store.ConfigDir()),

internals/secrethub/client_factory_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/secrethub/secrethub-go/internals/api"
910
"github.com/secrethub/secrethub-go/internals/assert"
11+
"github.com/secrethub/secrethub-go/internals/auth"
1012
"github.com/secrethub/secrethub-go/pkg/secrethub/credentials"
13+
httpclient "github.com/secrethub/secrethub-go/pkg/secrethub/internals/http"
1114

1215
"github.com/secrethub/secrethub-cli/internals/cli/ui"
1316
)
@@ -42,10 +45,24 @@ func TestNewClientFactory_ProxyAddress(t *testing.T) {
4245
proxyAddress: proxyAddress,
4346
}
4447

45-
client, err := factory.NewUnauthenticatedClient()
48+
client, err := factory.NewClientWithCredentials(dummyCredential{})
4649
assert.OK(t, err)
4750

48-
_, _ = client.Users().Create("test", "test@test.test", "test", credentials.CreateKey())
51+
_, _ = client.Me().GetUser()
4952
assert.OK(t, err)
5053
assert.Equal(t, proxyReceivedRequest, true)
5154
}
55+
56+
type dummyCredential struct {
57+
}
58+
59+
type nopDecrypter struct {
60+
}
61+
62+
func (n nopDecrypter) Unwrap(ciphertext *api.EncryptedData) ([]byte, error) {
63+
return nil, nil
64+
}
65+
66+
func (d dummyCredential) Provide(client *httpclient.Client) (auth.Authenticator, credentials.Decrypter, error) {
67+
return auth.NopAuthenticator{}, nopDecrypter{}, nil
68+
}

internals/secrethub/init.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ type InitCommand struct {
2525
setupCode string
2626
force bool
2727
io ui.IO
28-
newUnauthenticatedClient newClientFunc
2928
newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error)
3029
credentialStore CredentialConfig
3130
progressPrinter progress.Printer
3231
}
3332

3433
// NewInitCommand creates a new InitCommand.
35-
func NewInitCommand(io ui.IO, newUnauthenticatedClient newClientFunc, newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error), credentialStore CredentialConfig) *InitCommand {
34+
func NewInitCommand(io ui.IO, newClientWithCredentials func(credentials.Provider) (secrethub.ClientInterface, error), credentialStore CredentialConfig) *InitCommand {
3635
return &InitCommand{
3736
io: io,
38-
newUnauthenticatedClient: newUnauthenticatedClient,
3937
newClientWithCredentials: newClientWithCredentials,
4038
credentialStore: credentialStore,
4139
progressPrinter: progress.NewPrinter(io.Output(), 500*time.Millisecond),

0 commit comments

Comments
 (0)