mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +01:00
Merge pull request #7301 from ywk253100/190404_agent
Filter the events triggerred by replication
This commit is contained in:
commit
dc35be09c4
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user