feat(github): add GITHUB_TOKEN for rate limiting (#281)

This commit is contained in:
Teppei Fukuda
2019-11-15 16:45:07 +02:00
committed by GitHub
parent c2fdfab3ed
commit 15af65b9c5
3 changed files with 21 additions and 1 deletions

View File

@@ -5,12 +5,14 @@ import (
"fmt"
"io"
"net/http"
"os"
"sort"
"strings"
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy/pkg/log"
"github.com/google/go-github/v28/github"
"golang.org/x/oauth2"
"golang.org/x/xerrors"
)
@@ -44,7 +46,15 @@ type Client struct {
}
func NewClient() Client {
gc := github.NewClient(nil)
var client *http.Client
githubToken := os.Getenv("GITHUB_TOKEN")
if githubToken != "" {
log.Logger.Info("Use your github token")
ctx := context.Background()
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: githubToken})
client = oauth2.NewClient(ctx, ts)
}
gc := github.NewClient(client)
repo := Repository{
repository: gc.Repositories,