From 4f981eefd2cf493eae7c65e42404038258b753b1 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Fri, 18 Oct 2019 17:40:19 +0800 Subject: [PATCH] Populate public metadata into the event Fixes #9455. Populate the public metadata into the event when doing the replication based on event Signed-off-by: Wenkai Yin --- src/core/api/chart_repository.go | 14 +++++++++++--- src/core/service/notifications/registry/handler.go | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/api/chart_repository.go b/src/core/api/chart_repository.go index 29c47be1a..c8663cc85 100644 --- a/src/core/api/chart_repository.go +++ b/src/core/api/chart_repository.go @@ -10,15 +10,15 @@ import ( "mime/multipart" "net/http" "net/url" + "strconv" "strings" - "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/core/label" - "github.com/goharbor/harbor/src/chartserver" + "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/rbac" hlog "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/core/config" + "github.com/goharbor/harbor/src/core/label" rep_event "github.com/goharbor/harbor/src/replication/event" "github.com/goharbor/harbor/src/replication/model" ) @@ -429,6 +429,11 @@ func (cra *ChartRepositoryAPI) addEventContext(files []formFile, request *http.R return err } + public, err := cra.ProjectMgr.IsPublic(cra.namespace) + if err != nil { + hlog.Errorf("failed to check the public of project %s: %v", cra.namespace, err) + public = false + } e := &rep_event.Event{ Type: rep_event.EventTypeChartUpload, Resource: &model.Resource{ @@ -436,6 +441,9 @@ func (cra *ChartRepositoryAPI) addEventContext(files []formFile, request *http.R Metadata: &model.ResourceMetadata{ Repository: &model.Repository{ Name: fmt.Sprintf("%s/%s", cra.namespace, chartDetails.Metadata.Name), + Metadata: map[string]interface{}{ + "public": strconv.FormatBool(public), + }, }, Vtags: []string{chartDetails.Metadata.Version}, }, diff --git a/src/core/service/notifications/registry/handler.go b/src/core/service/notifications/registry/handler.go index d3530f979..331a4973e 100644 --- a/src/core/service/notifications/registry/handler.go +++ b/src/core/service/notifications/registry/handler.go @@ -17,6 +17,7 @@ package registry import ( "encoding/json" "regexp" + "strconv" "strings" "time" @@ -116,7 +117,6 @@ func (n *NotificationHandler) Post() { return } - // TODO: handle image delete event and chart event go func() { e := &rep_event.Event{ Type: rep_event.EventTypeImagePush, @@ -125,7 +125,9 @@ func (n *NotificationHandler) Post() { Metadata: &model.ResourceMetadata{ Repository: &model.Repository{ Name: repository, - // TODO filling the metadata + Metadata: map[string]interface{}{ + "public": strconv.FormatBool(pro.IsPublic()), + }, }, Vtags: []string{tag}, },