mirror of https://github.com/daffainfo/nuclei.git
parent
83681fb308
commit
1d0fbc0b62
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
fileutil "github.com/projectdiscovery/utils/file"
|
||||
folderutil "github.com/projectdiscovery/utils/folder"
|
||||
"golang.org/x/oauth2"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
)
|
||||
|
@ -85,10 +86,22 @@ func NewGitHubProviders(options *types.Options) ([]*customTemplateGitHubRepo, er
|
|||
githubToken: options.GitHubToken,
|
||||
}
|
||||
providers = append(providers, customTemplateRepo)
|
||||
|
||||
customTemplateRepo.restructureRepoDir()
|
||||
}
|
||||
return providers, nil
|
||||
}
|
||||
|
||||
func (customTemplateRepo *customTemplateGitHubRepo) restructureRepoDir() {
|
||||
customGitHubTemplatesDirectory := config.DefaultConfig.CustomGitHubTemplatesDirectory
|
||||
oldRepoClonePath := filepath.Join(customGitHubTemplatesDirectory, customTemplateRepo.reponame+"-"+customTemplateRepo.owner)
|
||||
newRepoClonePath := customTemplateRepo.getLocalRepoClonePath(customGitHubTemplatesDirectory)
|
||||
|
||||
if fileutil.FolderExists(oldRepoClonePath) && !fileutil.FolderExists(newRepoClonePath) {
|
||||
_ = folderutil.SyncDirectory(oldRepoClonePath, newRepoClonePath)
|
||||
}
|
||||
}
|
||||
|
||||
// getOwnerAndRepo returns the owner, repo, err from the given string
|
||||
// e.g., it takes input projectdiscovery/nuclei-templates and
|
||||
// returns owner => projectdiscovery, repo => nuclei-templates
|
||||
|
@ -154,9 +167,9 @@ func (ctr *customTemplateGitHubRepo) pullChanges(repoPath, githubToken string) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// All Custom github repos are cloned in the format of 'reponame-owner' for uniqueness
|
||||
// All Custom github repos are cloned in the format of 'owner/reponame' for uniqueness
|
||||
func (ctr *customTemplateGitHubRepo) getLocalRepoClonePath(downloadPath string) string {
|
||||
return filepath.Join(downloadPath, ctr.reponame+"-"+ctr.owner)
|
||||
return filepath.Join(downloadPath, ctr.owner, ctr.reponame)
|
||||
}
|
||||
|
||||
// returns the auth object with username and github token as password
|
||||
|
|
|
@ -30,6 +30,6 @@ func TestDownloadCustomTemplatesFromGitHub(t *testing.T) {
|
|||
|
||||
ctm.Download(context.Background())
|
||||
|
||||
require.DirExists(t, filepath.Join(templatesDirectory, "github", "nuclei-templates-projectdiscovery"), "cloned directory does not exists")
|
||||
require.DirExists(t, filepath.Join(templatesDirectory, "github", "nuclei-templates-ehsandeep"), "cloned directory does not exists")
|
||||
require.DirExists(t, filepath.Join(templatesDirectory, "github", "projectdiscovery", "nuclei-templates"), "cloned directory does not exists")
|
||||
require.DirExists(t, filepath.Join(templatesDirectory, "github", "ehsandeep", "nuclei-templates"), "cloned directory does not exists")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue