mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-01-31 13:53: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
|
// Helper function to check for a GitHub/GitLab token from env vars in order to
|
||||||
// make authenticated requests to access private repos
|
// make authenticated requests to access private repos
|
||||||
func gitAuth() *http.BasicAuth {
|
func gitAuth() http.AuthMethod {
|
||||||
var auth *http.BasicAuth
|
|
||||||
|
|
||||||
// The username can be anything for HTTPS Git operations
|
// The username can be anything for HTTPS Git operations
|
||||||
gitUsername := "fanal-aquasecurity-scan"
|
gitUsername := "fanal-aquasecurity-scan"
|
||||||
|
|
||||||
// We first check if a GitHub token was provided
|
// We first check if a GitHub token was provided
|
||||||
githubToken := os.Getenv("GITHUB_TOKEN")
|
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||||
if githubToken != "" {
|
if githubToken != "" {
|
||||||
auth = &http.BasicAuth{
|
return &http.BasicAuth{
|
||||||
Username: gitUsername,
|
Username: gitUsername,
|
||||||
Password: githubToken,
|
Password: githubToken,
|
||||||
}
|
}
|
||||||
return auth
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise we check if a GitLab token was provided
|
// Otherwise we check if a GitLab token was provided
|
||||||
gitlabToken := os.Getenv("GITLAB_TOKEN")
|
gitlabToken := os.Getenv("GITLAB_TOKEN")
|
||||||
if gitlabToken != "" {
|
if gitlabToken != "" {
|
||||||
auth = &http.BasicAuth{
|
return &http.BasicAuth{
|
||||||
Username: gitUsername,
|
Username: gitUsername,
|
||||||
Password: gitlabToken,
|
Password: gitlabToken,
|
||||||
}
|
}
|
||||||
return auth
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no token was provided, we simply return a nil,
|
// If no token was provided, we simply return a nil,
|
||||||
|
|||||||
Reference in New Issue
Block a user