Skip to content

Commit

Permalink
chore: reword bearer
Browse files Browse the repository at this point in the history
Signed-off-by: Kasper J. Hermansen <[email protected]>
  • Loading branch information
kjuulh committed Jun 13, 2024
1 parent 9c619db commit 974e250
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/extensions/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extensions

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -34,20 +35,25 @@ func newGitHubReleaseDownloader(downloadLink *registryExtensionDownloadLink) Dow

func (d *gitHubReleaseDownloader) Download(ctx context.Context, dest string) error {
client := http.DefaultClient

client.Timeout = time.Second * 60

req, err := http.NewRequestWithContext(ctx, http.MethodGet, d.link.Url, nil)
if err != nil {
return err
}

var bearer string
if accessToken := os.Getenv("SHUTTLE_EXTENSIONS_GITHUB_ACCESS_TOKEN"); accessToken != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
bearer = accessToken
} else if accessToken := os.Getenv("GITHUB_ACCESS_TOKEN"); accessToken != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
bearer = accessToken
}

if bearer == "" {
return errors.New("failed to find a valid authorization token for github. Please make sure you're logged into github-cli (gh), or have followed the setup documentation")
}

req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", bearer))
resp, err := client.Do(req)
if err != nil {
return err
Expand Down

0 comments on commit 974e250

Please sign in to comment.