Skip to content

Commit

Permalink
Apply user options after defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
kfcampbell committed Nov 29, 2023
1 parent 5d9e5ca commit c352388
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions github/authentication/token_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ func NewTokenProvider(apiToken string, options ...TokenProviderOption) (*TokenPr
func (t *TokenProvider) AuthenticateRequest(context context.Context, request *abs.RequestInformation, additionalAuthenticationContext map[string]interface{}) error {
reqWrapper := &Request{RequestInformation: request}

for _, option := range t.options {
option(t, reqWrapper)
}

if request.Headers == nil {
request.Headers = abs.NewRequestHeaders()
if reqWrapper.Headers == nil {
reqWrapper.Headers = abs.NewRequestHeaders()
}

// TODO(kfcampbell): cut this if chain over to new TokenProviderOption pattern
Expand All @@ -65,5 +61,10 @@ func (t *TokenProvider) AuthenticateRequest(context context.Context, request *ab
request.Headers.Add(APIVersionKey, APIVersionValue)
}

// apply user options after defaults
for _, option := range t.options {
option(t, reqWrapper)
}

return nil
}

0 comments on commit c352388

Please sign in to comment.