mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
feat(github): add GITHUB_TOKEN for rate limiting (#281)
This commit is contained in:
@@ -1485,6 +1485,15 @@ $ brew install aquasecurity/trivy/trivy
|
||||
|
||||
## Others
|
||||
|
||||
### GitHub Rate limiting
|
||||
|
||||
Specify GITHUB_TOKEN for authentication
|
||||
https://developer.github.com/v3/#rate-limiting
|
||||
|
||||
```
|
||||
$ GITHUB_TOKEN=XXXXXXXXXX trivy alpine:3.10
|
||||
```
|
||||
|
||||
### Unknown error
|
||||
|
||||
Try again with `--reset` option:
|
||||
|
||||
1
go.mod
1
go.mod
@@ -20,6 +20,7 @@ require (
|
||||
go.uber.org/zap v1.9.1
|
||||
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5
|
||||
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
|
||||
golang.org/x/sys v0.0.0-20191020152052-9984515f0562 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user