Merge pull request #7301 from ywk253100/190404_agent

Filter the events triggerred by replication
This commit is contained in:
Wenkai Yin 2019-04-04 16:50:23 +08:00 committed by GitHub
commit dc35be09c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -20,6 +20,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/goharbor/harbor/src/replication/ng/adapter"
"github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao"
clairdao "github.com/goharbor/harbor/src/common/dao/clair" clairdao "github.com/goharbor/harbor/src/common/dao/clair"
"github.com/goharbor/harbor/src/common/models" "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 { func checkEvent(event *models.Event) bool {
// pull and push manifest // push action
if strings.ToLower(strings.TrimSpace(event.Request.UserAgent)) != "harbor-registry-client" && (event.Action == "pull" || event.Action == "push") { 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 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 { func autoScanEnabled(project *models.Project) bool {

View File

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

View File

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