Skip to content

Commit

Permalink
put token in auth header if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
annabarnes1138 committed May 26, 2021
1 parent ec42d65 commit 75a468d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type GitHub interface {

type HttpClient interface {
Get(url string) (*http.Response, error)
GetWithToken(url string, token string) (*http.Response, error)
}

type Git interface {
Expand All @@ -77,6 +78,13 @@ func (c *DefaultHttpClient) Get(url string) (resp *http.Response, err error) {
return http.Get(url)
}

func (c *DefaultHttpClient) GetWithToken(url string, token string) (resp *http.Response, err error) {
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", fmt.Sprintf("token %s", token))
client := &http.Client{}
return client.Do(req)
}

type Releaser struct {
config *config.Options
github GitHub
Expand Down Expand Up @@ -109,9 +117,18 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {

var indexFile *repo.IndexFile

resp, err := r.httpClient.Get(fmt.Sprintf("%s/index.yaml", r.config.ChartsRepo))
if err != nil {
return false, err
var resp *http.Response
var err error
if r.config.Token != "" {
resp, err = r.httpClient.GetWithToken(fmt.Sprintf("%s/index.yaml", r.config.ChartsRepo), r.config.Token)
if err != nil {
return false, err
}
} else {
resp, err = r.httpClient.Get(fmt.Sprintf("%s/index.yaml", r.config.ChartsRepo))
if err != nil {
return false, err
}
}

defer resp.Body.Close()
Expand Down

0 comments on commit 75a468d

Please sign in to comment.