mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-19 08:45:27 +01:00
Only replicate "public" metadata when creating project in Harbor
This commit filters the metadata when creating project in replication to avoid replicate unnecessary properties, such as retention policy Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
b364ad89ae
commit
96a1ad89fa
@ -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