mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Merge pull request #11107 from ywk253100/filter_replication_pull
Filter the pulling manifest request from replication service
This commit is contained in:
commit
eb2af6095e
@ -56,6 +56,11 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// const definition
|
||||
const (
|
||||
UserAgent = "harbor-registry-client"
|
||||
)
|
||||
|
||||
// Client defines the methods that a registry client should implements
|
||||
type Client interface {
|
||||
// Ping the base API endpoint "/v2/"
|
||||
@ -504,6 +509,7 @@ func (c *client) do(req *http.Request) (*http.Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
req.Header.Set(http.CanonicalHeaderKey("User-Agent"), UserAgent)
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/internal"
|
||||
ierror "github.com/goharbor/harbor/src/internal/error"
|
||||
"github.com/goharbor/harbor/src/pkg/notification"
|
||||
"github.com/goharbor/harbor/src/pkg/registry"
|
||||
serror "github.com/goharbor/harbor/src/server/error"
|
||||
"github.com/goharbor/harbor/src/server/router"
|
||||
"github.com/opencontainers/go-digest"
|
||||
@ -48,20 +49,20 @@ func getManifest(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
recorder := internal.NewResponseRecorder(w)
|
||||
proxy.ServeHTTP(recorder, req)
|
||||
// fire event
|
||||
if recorder.Success() {
|
||||
// TODO don't fire event for the pulling from replication
|
||||
e := &metadata.PullArtifactEventMetadata{
|
||||
Ctx: req.Context(),
|
||||
Artifact: &artifact.Artifact,
|
||||
}
|
||||
// TODO provide a util function to determine whether the reference is tag or not
|
||||
// the reference is tag
|
||||
if _, err = digest.Parse(reference); err != nil {
|
||||
e.Tag = reference
|
||||
}
|
||||
notification.AddEvent(req.Context(), e)
|
||||
// fire event, ignore the HEAD request and pulling request from replication service
|
||||
if !recorder.Success() || req.Method == http.MethodHead ||
|
||||
req.UserAgent() == registry.UserAgent {
|
||||
return
|
||||
}
|
||||
e := &metadata.PullArtifactEventMetadata{
|
||||
Ctx: req.Context(),
|
||||
Artifact: &artifact.Artifact,
|
||||
}
|
||||
// the reference is tag
|
||||
if _, err = digest.Parse(reference); err != nil {
|
||||
e.Tag = reference
|
||||
}
|
||||
notification.AddEvent(req.Context(), e)
|
||||
}
|
||||
|
||||
// just delete the artifact from database
|
||||
|
Loading…
Reference in New Issue
Block a user