Skip to content

Commit

Permalink
Rename structs, add periods to comments and update AuthToken comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jamyct committed Oct 28, 2024
1 parent 19ad9c2 commit 78d0797
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/authtoken/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var (
configPath string
)

func parseArgs() (authtoken.AuthTokenProvider, error) {
var tokenProvider authtoken.AuthTokenProvider
func parseArgs() (authtoken.Provider, error) {
var tokenProvider authtoken.Provider
rootCmd := &cobra.Command{Use: "refreshtoken", Args: cobra.NoArgs}
rootCmd.PersistentFlags().StringVar(&configPath, "file-path", "/config/token", "token file path")

Expand Down
18 changes: 9 additions & 9 deletions pkg/authtoken/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import (
"time"
)

// An AuthToken is an authorization token for the fleet
// An AuthToken is an authentication token used to communicate with the hub API server.
type AuthToken struct {
Token string // name of token
ExpiresOn time.Time // expiration time of token
}

// AuthTokenProvider defines a method for fetching an AuthToken
type AuthTokenProvider interface {
// FetchToken fetches an AuthToken
// It returns an error if it is unable to fetch an AuthToken for the given input context
// Provider defines a method for fetching an AuthToken.
type Provider interface {
// FetchToken fetches an AuthToken.
// It returns an error if it is unable to fetch an AuthToken for the given input context.
FetchToken(ctx context.Context) (AuthToken, error)
}

// AuthTokenWriter defines a method for writing an AuthToken
type AuthTokenWriter interface {
// WriteToken writes an AuthToken
// It returns an error if it is unable to write the AuthToken
// Writer defines a method for writing an AuthToken.
type Writer interface {
// WriteToken writes an AuthToken.
// It returns an error if it is unable to write the AuthToken.
WriteToken(token AuthToken) error
}
2 changes: 1 addition & 1 deletion pkg/authtoken/providers/azure/azure_msi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type AuthTokenProvider struct {
Scope string
}

func New(clientID, scope string) authtoken.AuthTokenProvider {
func New(clientID, scope string) authtoken.Provider {
if scope == "" {
scope = aksScope
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/authtoken/providers/secret/k8s_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type secretAuthTokenProvider struct {
secretNamespace string
}

func New(secretName, namespace string) (authtoken.AuthTokenProvider, error) {
func New(secretName, namespace string) (authtoken.Provider, error) {
client, err := getClient()
if err != nil {
return nil, fmt.Errorf("an error occurred will creating client: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/authtoken/token_refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type RefreshDurationFuncType func(token AuthToken) time.Duration
type CreateTickerFuncType func(time.Duration) <-chan time.Time

type Refresher struct {
provider AuthTokenProvider
writer AuthTokenWriter
provider Provider
writer Writer
refreshCalculate RefreshDurationFuncType
createTicker CreateTickerFuncType
}

func NewAuthTokenRefresher(tokenProvider AuthTokenProvider,
writer AuthTokenWriter,
func NewAuthTokenRefresher(tokenProvider Provider,
writer Writer,
refreshCalculate RefreshDurationFuncType,
createTicker CreateTickerFuncType) *Refresher {
return &Refresher{
Expand Down
8 changes: 4 additions & 4 deletions pkg/authtoken/token_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ func (w Factory) Create() (io.WriteCloser, error) {
return wc, nil
}

type Writer struct {
type TokenWriter struct {
writerFactory func() (io.WriteCloser, error)
}

func NewWriter(factory func() (io.WriteCloser, error)) AuthTokenWriter {
return &Writer{
func NewWriter(factory func() (io.WriteCloser, error)) Writer {
return &TokenWriter{
writerFactory: factory,
}
}

func (w *Writer) WriteToken(token AuthToken) error {
func (w *TokenWriter) WriteToken(token AuthToken) error {
writer, err := w.writerFactory()
if err != nil {
return err
Expand Down

0 comments on commit 78d0797

Please sign in to comment.