Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoeg committed Nov 5, 2023
1 parent ae03a80 commit ab7769b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/artifact/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func pushCommand(options *Options) *cobra.Command {
if clientID == "" {
return errors.New("no HAMCTL_OAUTH_CLIENT_SECRET env var set")
}
daemonGate := httpinternal.NewDaemonGate(clientID, clientSecret, idpURL)
releaseManagerClient.Auth = &daemonGate
authenticator := httpinternal.NewClientAuthenticator(clientID, clientSecret, idpURL)
releaseManagerClient.Auth = &authenticator

artifactID, err = flow.PushArtifactToReleaseManager(ctx, &releaseManagerClient, options.FileName, options.RootPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/daemon/command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func StartDaemon() *cobra.Command {
return errors.New("no HAMCTL_OAUTH_CLIENT_SECRET env var set")
}

daemonGate := httpinternal.NewDaemonGate(clientID, clientSecret, idpURL)
client.Auth = &daemonGate
authenticator := httpinternal.NewClientAuthenticator(clientID, clientSecret, idpURL)
client.Auth = &authenticator

exporter := &kubernetes.ReleaseManagerExporter{
Log: log.With("type", "k8s-exporter"),
Expand Down
4 changes: 2 additions & 2 deletions cmd/hamctl/command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"github.com/spf13/cobra"
)

func Login(gate http.Gate) *cobra.Command {
func Login(authenticator http.UserAuthenticator) *cobra.Command {
return &cobra.Command{
Use: "login",
Short: `Log into the configured IdP`,
Args: cobra.ExactArgs(0),
RunE: func(c *cobra.Command, args []string) error {
return gate.Authenticate()
return authenticator.Login()
},
}
}
2 changes: 1 addition & 1 deletion cmd/hamctl/command/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

type NoAuthClient struct{}

func (NoAuthClient) AuthenticatedClient(ctx context.Context) (*http.Client, error) {
func (NoAuthClient) Access(ctx context.Context) (*http.Client, error) {
return &http.Client{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/hamctl/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewRoot(version *string) (*cobra.Command, error) {
return nil, errors.New("no HAMCTL_OAUTH_CLIENT_ID env var set")
}

gate := http.NewGate(clientID, idpURL)
authenticator := http.NewUserAuthenticator(clientID, idpURL)

var service string
client := http.Client{
Expand Down Expand Up @@ -82,7 +82,7 @@ func NewRoot(version *string) (*cobra.Command, error) {
NewRollback(&client, &service, loggerFunc, SelectRollbackReleaseFunc, releaseClient),
NewStatus(&client, &service),
NewVersion(*version),
Login(gate),
Login(authenticator),
)
command.PersistentFlags().DurationVar(&client.Timeout, "http-timeout", 120*time.Second, "HTTP request timeout")
command.PersistentFlags().StringVar(&client.BaseURL, "http-base-url", "", "address of the http release manager server")
Expand Down
18 changes: 9 additions & 9 deletions internal/http/login.go → internal/http/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"golang.org/x/oauth2/clientcredentials"
)

type Gate struct {
type UserAuthenticator struct {
conf *oauth2.Config
}

func NewGate(clientID, idpURL string) Gate {
func NewUserAuthenticator(clientID, idpURL string) UserAuthenticator {
conf := &oauth2.Config{
ClientID: clientID,
Endpoint: oauth2.Endpoint{
Expand All @@ -26,12 +26,12 @@ func NewGate(clientID, idpURL string) Gate {
},
Scopes: []string{"openid profile"},
}
return Gate{
return UserAuthenticator{
conf: conf,
}
}

func (g *Gate) Authenticate() error {
func (g *UserAuthenticator) Login() error {
ctx := context.Background()
response, err := g.conf.DeviceAuth(ctx)
if err != nil {
Expand All @@ -50,7 +50,7 @@ func (g *Gate) Authenticate() error {
return storeAccessToken(token)
}

func (g *Gate) AuthenticatedClient(ctx context.Context) (*http.Client, error) {
func (g *UserAuthenticator) Access(ctx context.Context) (*http.Client, error) {
token, err := readAccessToken()
if err != nil {
return nil, err
Expand Down Expand Up @@ -99,22 +99,22 @@ func storeAccessToken(token *oauth2.Token) error {
return nil
}

type DaemonGate struct {
type ClientAuthenticator struct {
conf *clientcredentials.Config
}

func NewDaemonGate(clientID, clientSecret, idpURL string) DaemonGate {
func NewClientAuthenticator(clientID, clientSecret, idpURL string) ClientAuthenticator {
conf := &clientcredentials.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: fmt.Sprintf("%s/v1/token", idpURL),
Scopes: []string{""},
}
return DaemonGate{
return ClientAuthenticator{
conf: conf,
}
}

func (g *DaemonGate) AuthenticatedClient(ctx context.Context) (*http.Client, error) {
func (g *ClientAuthenticator) Access(ctx context.Context) (*http.Client, error) {
return g.conf.Client(ctx), nil
}
4 changes: 2 additions & 2 deletions internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type Authenticator interface {
AuthenticatedClient(context context.Context) (*http.Client, error)
Access(context context.Context) (*http.Client, error)
}

type Client struct {
Expand Down Expand Up @@ -57,7 +57,7 @@ func (c *Client) URLWithQuery(path string, queryParams url.Values) (string, erro
// ErrorResponse object and returned as the error.
func (c *Client) Do(method string, path string, requestBody, responseBody interface{}) error {
ctx := context.Background()
client, err := c.Auth.AuthenticatedClient(ctx)
client, err := c.Auth.Access(ctx)
if err != nil {
return errors.Wrap(err, "please log in again to refresh the token")
}
Expand Down

0 comments on commit ab7769b

Please sign in to comment.