mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-12 05:58:23 +02:00
Merge remote-tracking branch 'upstream/master' into 170620_pm
Conflicts: src/ui/service/notification.go
This commit is contained in:
commit
78366ad23a
@ -16,6 +16,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -25,6 +26,8 @@ import (
|
|||||||
"github.com/vmware/harbor/src/common/utils"
|
"github.com/vmware/harbor/src/common/utils"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
"github.com/vmware/harbor/src/ui/api"
|
"github.com/vmware/harbor/src/ui/api"
|
||||||
|
"github.com/vmware/harbor/src/ui/config"
|
||||||
|
"github.com/vmware/harbor/src/ui/projectmanager/pms"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NotificationHandler handles request on /service/notifications/, which listens to registry's events.
|
// NotificationHandler handles request on /service/notifications/, which listens to registry's events.
|
||||||
@ -96,7 +99,13 @@ func (n *NotificationHandler) Post() {
|
|||||||
log.Errorf("Error happens when adding repository: %v", err)
|
log.Errorf("Error happens when adding repository: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go api.TriggerReplicationByRepository(pro.ProjectID, repository, []string{tag}, models.RepOpTransfer)
|
go api.TriggerReplicationByRepository(pro.ProjectID, repository, []string{tag}, models.RepOpTransfer)
|
||||||
|
if autoScanEnabled(project) {
|
||||||
|
if err := api.TriggerImageScan(repository, tag); err != nil {
|
||||||
|
log.Warningf("Failed to scan image, repository: %s, tag: %s, error: %v", repository, tag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if action == "pull" {
|
if action == "pull" {
|
||||||
go func() {
|
go func() {
|
||||||
@ -145,6 +154,27 @@ func filterEvents(notification *models.Notification) ([]*models.Event, error) {
|
|||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func autoScanEnabled(projectName string) bool {
|
||||||
|
if !config.WithClair() {
|
||||||
|
log.Debugf("Auto Scan disabled because Harbor is not deployed with Clair")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if config.WithAdmiral() {
|
||||||
|
//TODO get a project manager based on service account.
|
||||||
|
var pm *pms.ProjectManager = pms.NewProjectManager("", "")
|
||||||
|
p, err := pm.Get(projectName)
|
||||||
|
if err != nil {
|
||||||
|
log.Warningf("failed to get project, error: %v", err)
|
||||||
|
return false
|
||||||
|
} else if p == nil {
|
||||||
|
log.Warningf("project with name: %s not found.", projectName)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return p.AutomaticallyScanImagesOnPush
|
||||||
|
}
|
||||||
|
return os.Getenv("ENABLE_HARBOR_SCAN_ON_PUSH") == "1"
|
||||||
|
}
|
||||||
|
|
||||||
// Render returns nil as it won't render any template.
|
// Render returns nil as it won't render any template.
|
||||||
func (n *NotificationHandler) Render() error {
|
func (n *NotificationHandler) Render() error {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user