mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-24 03:45:28 +00:00
Implements github request with token fallback
This commit is contained in:
parent
f94372acf3
commit
6e5e7f23e5
@ -224,21 +224,38 @@ func (r *Runner) checkNucleiIgnoreFileUpdates(configDir string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// getLatestReleaseFromGithub returns the latest release from GitHub
|
||||
func (r *Runner) getLatestReleaseFromGithub(latestTag string) (*github.RepositoryRelease, error) {
|
||||
func getGHClientIncognito() *github.Client {
|
||||
var tc *http.Client
|
||||
return github.NewClient(tc)
|
||||
}
|
||||
|
||||
func getGHClientWithToken() *github.Client {
|
||||
if token, ok := os.LookupEnv("GITHUB_TOKEN"); ok {
|
||||
ctx := context.Background()
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: token},
|
||||
)
|
||||
tc = oauth2.NewClient(ctx, ts)
|
||||
oauthClient := oauth2.NewClient(ctx, ts)
|
||||
return github.NewClient(oauthClient)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
gitHubClient := github.NewClient(tc)
|
||||
|
||||
// getLatestReleaseFromGithub returns the latest release from GitHub
|
||||
func (r *Runner) getLatestReleaseFromGithub(latestTag string) (*github.RepositoryRelease, error) {
|
||||
var (
|
||||
gitHubClient *github.Client
|
||||
retried bool
|
||||
)
|
||||
gitHubClient = getGHClientIncognito()
|
||||
getRelease:
|
||||
release, _, err := gitHubClient.Repositories.GetReleaseByTag(context.Background(), userName, repoName, "v"+latestTag)
|
||||
if err != nil {
|
||||
// retry with authentication
|
||||
if gitHubClient = getGHClientWithToken(); gitHubClient != nil && !retried {
|
||||
retried = true
|
||||
goto getRelease
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if release == nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user