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

Commit

Permalink
Merge pull request #218 from secrethub/feature/make-setup-code-creden…
Browse files Browse the repository at this point in the history
…tial-provider

Remove the with setup code option and make setup code credential provider
  • Loading branch information
florisvdg authored Aug 28, 2020
2 parents 66d0364 + 88f5c0d commit 9cec7ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
16 changes: 0 additions & 16 deletions pkg/secrethub/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net/url"
"time"

"github.com/secrethub/secrethub-go/internals/api"

"github.com/secrethub/secrethub-go/pkg/secrethub/configdir"
"github.com/secrethub/secrethub-go/pkg/secrethub/credentials"
httpclient "github.com/secrethub/secrethub-go/pkg/secrethub/internals/http"
Expand Down Expand Up @@ -80,17 +78,3 @@ func WithCredentials(provider credentials.Provider) ClientOption {
return nil
}
}

// WithSetupCode configures the client to use the provided setup code for authentication.
func WithSetupCode(setupCode string) ClientOption {
return func(c *Client) error {
err := api.ValidateSetupCode(setupCode)
if err != nil {
return err
}

setupCodeAuthenticator := credentials.NewSetupCode(setupCode)
c.httpClient.Options(httpclient.WithAuthenticator(setupCodeAuthenticator))
return nil
}
}
8 changes: 8 additions & 0 deletions pkg/secrethub/credentials/setup_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ import (
"fmt"
"net/http"

httpclient "github.com/secrethub/secrethub-go/pkg/secrethub/internals/http"

"github.com/secrethub/secrethub-go/internals/auth"
)

type SetupCode struct {
code string
}

// Provide implements the Provider interface for the setup code.
// Note that no decrypter is ever returned as setup codes cannot be used to decrypt secrets.
func (s *SetupCode) Provide(client *httpclient.Client) (auth.Authenticator, Decrypter, error) {
return s, nil, nil
}

func NewSetupCode(code string) *SetupCode {
return &SetupCode{
code: code,
Expand Down

0 comments on commit 9cec7ef

Please sign in to comment.