mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 12:15:20 +01:00
feat: Initialize scanner registrations properly
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
This commit is contained in:
parent
a642667ffc
commit
5f110c800a
@ -209,7 +209,7 @@ func main() {
|
||||
}
|
||||
|
||||
if config.WithTrivy() {
|
||||
log.Info("Registering Trivy scanner adapter")
|
||||
log.Debug("Registering Trivy scanner")
|
||||
reg := &scanner.Registration{
|
||||
Name: "Trivy",
|
||||
Description: "The Trivy scanner adapter",
|
||||
@ -218,12 +218,18 @@ func main() {
|
||||
Immutable: true,
|
||||
}
|
||||
if err := scan.EnsureScanner(reg, true); err != nil {
|
||||
log.Fatalf("failed to initialize Trivy scanner: %v", err)
|
||||
log.Fatalf("failed to register Trivy scanner: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !config.WithTrivy() {
|
||||
log.Debug("Removing Trivy scanner")
|
||||
if err := scan.RemoveImmutableScanner(config.TrivyAdapterURL()); err != nil {
|
||||
log.Warningf("failed to remove Trivy scanner: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if config.WithClair() {
|
||||
log.Info("Registering Clair scanner adapter")
|
||||
clairDB, err := config.ClairDB()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to load clair database information: %v", err)
|
||||
@ -232,6 +238,7 @@ func main() {
|
||||
log.Fatalf("failed to initialize clair database: %v", err)
|
||||
}
|
||||
|
||||
log.Debug("Registering Clair scanner")
|
||||
reg := &scanner.Registration{
|
||||
Name: "Clair",
|
||||
Description: "The clair scanner adapter",
|
||||
@ -241,14 +248,16 @@ func main() {
|
||||
}
|
||||
|
||||
if err := scan.EnsureScanner(reg, true); err != nil {
|
||||
log.Fatalf("failed to initialize clair scanner: %v", err)
|
||||
log.Fatalf("failed to register Clair scanner: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !config.WithClair() {
|
||||
log.Debug("Removing Clair scanner")
|
||||
if err := scan.RemoveImmutableScanner(config.ClairAdapterEndpoint()); err != nil {
|
||||
log.Warningf("failed to remove Clair scanners: %v", err)
|
||||
}
|
||||
}
|
||||
//} else {
|
||||
// if err := scan.RemoveImmutableScanners(); err != nil {
|
||||
// log.Warningf("failed to remove immutable scanners: %v", err)
|
||||
// }
|
||||
//}
|
||||
|
||||
closing := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
|
@ -86,13 +86,16 @@ func EnsureScanner(registration *scanner.Registration, resolveConflicts ...bool)
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveImmutableScanners remove all immutable scanners in the system
|
||||
func RemoveImmutableScanners() error {
|
||||
q := &q.Query{
|
||||
Keywords: map[string]interface{}{"immutable": true},
|
||||
// RemoveImmutableScanner removes an immutable scanner with the specified endpoint URL.
|
||||
func RemoveImmutableScanner(registrationURL string) error {
|
||||
query := &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"immutable": true,
|
||||
"url": registrationURL,
|
||||
},
|
||||
}
|
||||
|
||||
registrations, err := scannerManager.List(q)
|
||||
registrations, err := scannerManager.List(query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user