mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-01-31 05:43:14 +08:00
fix(repo): return a nil interface for gitAuth if missing (#10097)
This commit is contained in:
@@ -154,30 +154,26 @@ func newURL(rawurl string) (*url.URL, error) {
|
||||
|
||||
// Helper function to check for a GitHub/GitLab token from env vars in order to
|
||||
// make authenticated requests to access private repos
|
||||
func gitAuth() *http.BasicAuth {
|
||||
var auth *http.BasicAuth
|
||||
|
||||
func gitAuth() http.AuthMethod {
|
||||
// The username can be anything for HTTPS Git operations
|
||||
gitUsername := "fanal-aquasecurity-scan"
|
||||
|
||||
// We first check if a GitHub token was provided
|
||||
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||
if githubToken != "" {
|
||||
auth = &http.BasicAuth{
|
||||
return &http.BasicAuth{
|
||||
Username: gitUsername,
|
||||
Password: githubToken,
|
||||
}
|
||||
return auth
|
||||
}
|
||||
|
||||
// Otherwise we check if a GitLab token was provided
|
||||
gitlabToken := os.Getenv("GITLAB_TOKEN")
|
||||
if gitlabToken != "" {
|
||||
auth = &http.BasicAuth{
|
||||
return &http.BasicAuth{
|
||||
Username: gitUsername,
|
||||
Password: gitlabToken,
|
||||
}
|
||||
return auth
|
||||
}
|
||||
|
||||
// If no token was provided, we simply return a nil,
|
||||
|
||||
Reference in New Issue
Block a user