feat(glad): add ability to set custom repository uri (#136)

This commit is contained in:
Alan (Maciej) Paruszewski 2022-04-21 11:39:18 +02:00 committed by GitHub
parent bc6508033e
commit de6aced299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 12 deletions

View File

@ -16,8 +16,9 @@ import (
)
const (
repoURL = "https://gitlab.com/gitlab-org/advisories-community.git"
gladDir = "glad" // GitLab Advisory Database
repoURL = "https://gitlab.com/gitlab-org/advisories-community.git"
repoBranch = "main"
gladDir = "glad" // GitLab Advisory Database
)
var (
@ -26,16 +27,20 @@ var (
)
type Updater struct {
vulnListDir string
cacheDir string
appFs afero.Fs
alternativeRepoBranch string
alternativeRepoURL string
vulnListDir string
cacheDir string
appFs afero.Fs
}
func NewUpdater() Updater {
func NewUpdater(alternativeRepoURL string, alternativeRepoBranch string) Updater {
return Updater{
vulnListDir: utils.VulnListDir(),
cacheDir: utils.CacheDir(),
appFs: afero.NewOsFs(),
alternativeRepoBranch: alternativeRepoBranch,
alternativeRepoURL: alternativeRepoURL,
vulnListDir: utils.VulnListDir(),
cacheDir: utils.CacheDir(),
appFs: afero.NewOsFs(),
}
}
@ -44,7 +49,18 @@ func (u Updater) Update() error {
gc := git.Config{}
dir := filepath.Join(u.cacheDir, gladDir)
if _, err := gc.CloneOrPull(repoURL, dir, "main", false); err != nil {
defaultOrAlternativeRepoURL := repoURL
defaultOrAlternativeRepoBranch := repoBranch
if len(u.alternativeRepoURL) > 0 {
defaultOrAlternativeRepoURL = u.alternativeRepoURL
}
if len(u.alternativeRepoBranch) > 0 {
defaultOrAlternativeRepoBranch = u.alternativeRepoBranch
}
if _, err := gc.CloneOrPull(defaultOrAlternativeRepoURL, dir, defaultOrAlternativeRepoBranch, false); err != nil {
return xerrors.Errorf("failed to clone or pull: %w", err)
}

View File

@ -47,7 +47,9 @@ const (
var (
target = flag.String("target", "", "update target (nvd, alpine, alpine-unfixed, redhat, redhat-oval, "+
"debian, debian-oval, ubuntu, amazon, oracle-oval, suse-cvrf, photon, arch-linux, ghsa, glad, cwe, osv, go-vulndb, mariner)")
years = flag.String("years", "", "update years (only redhat)")
years = flag.String("years", "", "update years (only redhat)")
targetUri = flag.String("target-uri", "", "alternative repository URI (only glad)")
targetBranch = flag.String("target-branch", "", "alternative repository branch (only glad)")
)
func main() {
@ -174,7 +176,7 @@ func run() error {
}
commitMsg = "GitHub Security Advisory"
case "glad":
gu := glad.NewUpdater()
gu := glad.NewUpdater(*targetUri, *targetBranch)
if err := gu.Update(); err != nil {
return xerrors.Errorf("GitLab Advisory Database update error: %w", err)
}