mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-19 15:17:43 +01:00
Merge pull request #8609 from ywk253100/190808_replicate_meta
Only replicate "public" metadata when creating project in Harbor
This commit is contained in:
commit
67a60df033
@ -156,7 +156,7 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
||||
paths := strings.Split(resource.Metadata.Repository.Name, "/")
|
||||
projectName := paths[0]
|
||||
// handle the public properties
|
||||
metadata := resource.Metadata.Repository.Metadata
|
||||
metadata := abstractPublicMetadata(resource.Metadata.Repository.Metadata)
|
||||
pro, exist := projects[projectName]
|
||||
if exist {
|
||||
metadata = mergeMetadata(pro.Metadata, metadata)
|
||||
@ -187,6 +187,19 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func abstractPublicMetadata(metadata map[string]interface{}) map[string]interface{} {
|
||||
if metadata == nil {
|
||||
return nil
|
||||
}
|
||||
public, exist := metadata["public"]
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"public": public,
|
||||
}
|
||||
}
|
||||
|
||||
// currently, mergeMetadata only handles the public metadata
|
||||
func mergeMetadata(metadata1, metadata2 map[string]interface{}) map[string]interface{} {
|
||||
public := parsePublic(metadata1) && parsePublic(metadata2)
|
||||
|
@ -210,3 +210,26 @@ func TestMergeMetadata(t *testing.T) {
|
||||
assert.Equal(t, strconv.FormatBool(c.public), m["public"].(string))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAbstractPublicMetadata(t *testing.T) {
|
||||
// nil input metadata
|
||||
meta := abstractPublicMetadata(nil)
|
||||
assert.Nil(t, meta)
|
||||
|
||||
// contains no public metadata
|
||||
metadata := map[string]interface{}{
|
||||
"other": "test",
|
||||
}
|
||||
meta = abstractPublicMetadata(metadata)
|
||||
assert.Nil(t, meta)
|
||||
|
||||
// contains public metadata
|
||||
metadata = map[string]interface{}{
|
||||
"other": "test",
|
||||
"public": "true",
|
||||
}
|
||||
meta = abstractPublicMetadata(metadata)
|
||||
require.NotNil(t, meta)
|
||||
require.Equal(t, 1, len(meta))
|
||||
require.Equal(t, "true", meta["public"].(string))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user