mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-18 16:25:16 +01:00
Merge pull request #9478 from ywk253100/191018_test
Populate public metadata into the event
This commit is contained in:
commit
bd28ba43c0
@ -10,7 +10,10 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/chartserver"
|
"github.com/goharbor/harbor/src/chartserver"
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
@ -18,14 +21,10 @@ import (
|
|||||||
hlog "github.com/goharbor/harbor/src/common/utils/log"
|
hlog "github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/config"
|
"github.com/goharbor/harbor/src/core/config"
|
||||||
"github.com/goharbor/harbor/src/core/label"
|
"github.com/goharbor/harbor/src/core/label"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/core/middlewares"
|
"github.com/goharbor/harbor/src/core/middlewares"
|
||||||
n_event "github.com/goharbor/harbor/src/core/notifier/event"
|
n_event "github.com/goharbor/harbor/src/core/notifier/event"
|
||||||
rep_event "github.com/goharbor/harbor/src/replication/event"
|
rep_event "github.com/goharbor/harbor/src/replication/event"
|
||||||
"github.com/goharbor/harbor/src/replication/model"
|
"github.com/goharbor/harbor/src/replication/model"
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -489,6 +488,12 @@ func (cra *ChartRepositoryAPI) addEventContext(files []formFile, request *http.R
|
|||||||
extInfo["operator"] = cra.SecurityCtx.GetUsername()
|
extInfo["operator"] = cra.SecurityCtx.GetUsername()
|
||||||
extInfo["projectName"] = cra.namespace
|
extInfo["projectName"] = cra.namespace
|
||||||
extInfo["chartName"] = chartDetails.Metadata.Name
|
extInfo["chartName"] = chartDetails.Metadata.Name
|
||||||
|
|
||||||
|
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{
|
e := &rep_event.Event{
|
||||||
Type: rep_event.EventTypeChartUpload,
|
Type: rep_event.EventTypeChartUpload,
|
||||||
Resource: &model.Resource{
|
Resource: &model.Resource{
|
||||||
@ -496,6 +501,9 @@ func (cra *ChartRepositoryAPI) addEventContext(files []formFile, request *http.R
|
|||||||
Metadata: &model.ResourceMetadata{
|
Metadata: &model.ResourceMetadata{
|
||||||
Repository: &model.Repository{
|
Repository: &model.Repository{
|
||||||
Name: fmt.Sprintf("%s/%s", cra.namespace, chartDetails.Metadata.Name),
|
Name: fmt.Sprintf("%s/%s", cra.namespace, chartDetails.Metadata.Name),
|
||||||
|
Metadata: map[string]interface{}{
|
||||||
|
"public": strconv.FormatBool(public),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Vtags: []string{chartDetails.Metadata.Version},
|
Vtags: []string{chartDetails.Metadata.Version},
|
||||||
},
|
},
|
||||||
|
@ -17,6 +17,7 @@ package registry
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -140,7 +141,6 @@ func (n *NotificationHandler) Post() {
|
|||||||
log.Errorf("failed to build image push event metadata: %v", err)
|
log.Errorf("failed to build image push event metadata: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle image delete event and chart event
|
|
||||||
go func() {
|
go func() {
|
||||||
e := &rep_event.Event{
|
e := &rep_event.Event{
|
||||||
Type: rep_event.EventTypeImagePush,
|
Type: rep_event.EventTypeImagePush,
|
||||||
@ -149,7 +149,9 @@ func (n *NotificationHandler) Post() {
|
|||||||
Metadata: &model.ResourceMetadata{
|
Metadata: &model.ResourceMetadata{
|
||||||
Repository: &model.Repository{
|
Repository: &model.Repository{
|
||||||
Name: repository,
|
Name: repository,
|
||||||
// TODO filling the metadata
|
Metadata: map[string]interface{}{
|
||||||
|
"public": strconv.FormatBool(pro.IsPublic()),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Vtags: []string{tag},
|
Vtags: []string{tag},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user