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 <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2019-10-18 17:40:19 +08:00
parent dde372bc80
commit 4f981eefd2
2 changed files with 15 additions and 5 deletions

View File

@ -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},
},

View File

@ -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},
},