Skip to content

Commit

Permalink
add Logger field to the XXXOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Aug 15, 2023
1 parent 3a03083 commit 1267082
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/credentials/provider/ecsmetadata_provider.go
Expand Up @@ -39,6 +39,7 @@ type ECSMetadataProviderOptions struct {

ExpiryWindow time.Duration
RefreshPeriod time.Duration
Logger Logger
}

func NewECSMetadataProvider(opts ECSMetadataProviderOptions) *ECSMetadataProvider {
Expand All @@ -57,6 +58,7 @@ func NewECSMetadataProvider(opts ECSMetadataProviderOptions) *ECSMetadataProvide
e.u = NewUpdater(e.getCredentials, UpdaterOptions{
ExpiryWindow: opts.ExpiryWindow,
RefreshPeriod: opts.RefreshPeriod,
Logger: opts.Logger,
})
e.u.Start(context.TODO())

Expand Down Expand Up @@ -211,6 +213,9 @@ func (o *ECSMetadataProviderOptions) applyDefaults() {
if o.ExpiryWindow == 0 {
o.ExpiryWindow = defaultExpiryWindow
}
if o.Logger == nil {
o.Logger = defaultLog
}
}

func (e metadataError) Error() string {
Expand Down
5 changes: 5 additions & 0 deletions pkg/credentials/provider/encryptedfile_provider.go
Expand Up @@ -19,6 +19,7 @@ type EncryptedFileProviderOptions struct {
FilePath string
RefreshPeriod time.Duration
ExpiryWindow time.Duration
Logger Logger
}

func NewEncryptedFileProvider(opts EncryptedFileProviderOptions) *EncryptedFileProvider {
Expand All @@ -28,6 +29,7 @@ func NewEncryptedFileProvider(opts EncryptedFileProviderOptions) *EncryptedFileP
e.f = NewFileProvider(opts.FilePath, parseEncryptedToken, FileProviderOptions{
RefreshPeriod: opts.RefreshPeriod,
ExpiryWindow: opts.ExpiryWindow,
Logger: opts.Logger,
})

return e
Expand All @@ -44,6 +46,9 @@ func (o *EncryptedFileProviderOptions) applyDefaults() {
if o.FilePath == "" {
o.FilePath = defaultEncryptedFilePath
}
if o.Logger == nil {
o.Logger = defaultLog
}
}

func parseEncryptedToken(data []byte) (*Credentials, error) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/credentials/provider/file_provider.go
Expand Up @@ -17,16 +17,20 @@ type FileProvider struct {
type FileProviderOptions struct {
RefreshPeriod time.Duration
ExpiryWindow time.Duration
Logger Logger
}

func NewFileProvider(filepath string, decoder func(data []byte) (*Credentials, error), opts FileProviderOptions) *FileProvider {
opts.applyDefaults()

e := &FileProvider{
filepath: filepath,
decoder: decoder,
}
e.u = NewUpdater(e.getCredentials, UpdaterOptions{
ExpiryWindow: opts.ExpiryWindow,
RefreshPeriod: opts.RefreshPeriod,
Logger: opts.Logger,
})
e.u.Start(context.TODO())

Expand All @@ -52,3 +56,12 @@ func (f *FileProvider) getCredentials(ctx context.Context) (*Credentials, error)
}
return cred, nil
}

func (f *FileProviderOptions) applyDefaults() {
if f.ExpiryWindow == 0 {
f.ExpiryWindow = defaultExpiryWindow
}
if f.Logger == nil {
f.Logger = defaultLog
}
}
5 changes: 5 additions & 0 deletions pkg/credentials/provider/oidc_provider.go
Expand Up @@ -49,6 +49,7 @@ type OIDCProviderOptions struct {

ExpiryWindow time.Duration
RefreshPeriod time.Duration
Logger Logger
}

func NewOIDCProvider(opts OIDCProviderOptions) *OIDCProvider {
Expand All @@ -70,6 +71,7 @@ func NewOIDCProvider(opts OIDCProviderOptions) *OIDCProvider {
e.u = NewUpdater(e.getCredentials, UpdaterOptions{
ExpiryWindow: opts.ExpiryWindow,
RefreshPeriod: opts.RefreshPeriod,
Logger: opts.Logger,
})
e.u.Start(context.TODO())

Expand Down Expand Up @@ -209,4 +211,7 @@ func (o *OIDCProviderOptions) applyDefaults() {
if o.EnvOIDCTokenFile == "" {
o.EnvOIDCTokenFile = defaultEnvOIDCTokenFile
}
if o.Logger == nil {
o.Logger = defaultLog
}
}
2 changes: 2 additions & 0 deletions pkg/credentials/provider/updater.go
Expand Up @@ -28,6 +28,7 @@ type Updater struct {
type UpdaterOptions struct {
ExpiryWindow time.Duration
RefreshPeriod time.Duration
Logger Logger
}

func NewUpdater(getter getCredentialsFunc, opts UpdaterOptions) *Updater {
Expand All @@ -38,6 +39,7 @@ func NewUpdater(getter getCredentialsFunc, opts UpdaterOptions) *Updater {
getCredentials: getter,
cred: nil,
lockForCred: sync.RWMutex{},
Logger: opts.Logger,
}
return u
}
Expand Down

0 comments on commit 1267082

Please sign in to comment.