Filter the events triggerred by replication

Filter the events triggerred by replication pull

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2019-04-04 15:42:26 +08:00
parent 3ed8d87406
commit 1c735a7464
3 changed files with 12 additions and 10 deletions

View File

@ -20,6 +20,8 @@ import (
"strings"
"time"
"github.com/goharbor/harbor/src/replication/ng/adapter"
"github.com/goharbor/harbor/src/common/dao"
clairdao "github.com/goharbor/harbor/src/common/dao/clair"
"github.com/goharbor/harbor/src/common/models"
@ -179,15 +181,16 @@ func filterEvents(notification *models.Notification) ([]*models.Event, error) {
}
func checkEvent(event *models.Event) bool {
// pull and push manifest
if strings.ToLower(strings.TrimSpace(event.Request.UserAgent)) != "harbor-registry-client" && (event.Action == "pull" || event.Action == "push") {
// push action
if event.Action == "push" {
return true
}
// push manifest by job-service
if strings.ToLower(strings.TrimSpace(event.Request.UserAgent)) == "harbor-registry-client" && event.Action == "push" {
return true
// if it is pull action, check the user-agent
userAgent := strings.ToLower(strings.TrimSpace(event.Request.UserAgent))
if userAgent == "harbor-registry-client" || userAgent == strings.ToLower(adapter.UserAgentReplication) {
return false
}
return false
return true
}
func autoScanEnabled(project *models.Project) bool {

View File

@ -51,7 +51,7 @@ func newAdapter(registry *model.Registry) *adapter {
transport := util.GetHTTPTransport(registry.Insecure)
modifiers := []modifier.Modifier{
&auth.UserAgentModifier{
UserAgent: adp.UserAgentReplicator,
UserAgent: adp.UserAgentReplication,
},
}
if registry.Credential != nil {

View File

@ -35,8 +35,7 @@ import (
// const definition
const (
// TODO: add filter for the agent in registry webhook handler
UserAgentReplicator = "harbor-replicator"
UserAgentReplication = "harbor-replication-service"
)
// ImageRegistry defines the capabilities that an image registry should have
@ -65,7 +64,7 @@ func NewDefaultImageRegistry(registry *model.Registry) *DefaultImageRegistry {
transport := util.GetHTTPTransport(registry.Insecure)
modifiers := []modifier.Modifier{
&auth.UserAgentModifier{
UserAgent: UserAgentReplicator,
UserAgent: UserAgentReplication,
},
}
if registry.Credential != nil {