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"
"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,16 +181,17 @@ 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") {
return true
}
// push manifest by job-service
if strings.ToLower(strings.TrimSpace(event.Request.UserAgent)) == "harbor-registry-client" && event.Action == "push" {
// push action
if 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 true
}
func autoScanEnabled(project *models.Project) bool {
if !config.WithClair() {

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 {