feat(glad): add ability to set custom repository uri (#136)
This commit is contained in:
parent
bc6508033e
commit
de6aced299
36
glad/glad.go
36
glad/glad.go
@ -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)
|
||||
}
|
||||
|
||||
|
6
main.go
6
main.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user