From d36811ce52ddad2048063f595316a45dc254cbf9 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Tue, 26 Dec 2017 19:09:14 +0800 Subject: [PATCH] Using the string trimmed the project name at the begining as the input of repository filter --- src/replication/core/controller.go | 6 +----- src/replication/source/repository_convertor.go | 2 -- src/replication/source/repository_filter.go | 3 +++ src/replication/source/repository_filter_test.go | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/replication/core/controller.go b/src/replication/core/controller.go index 7eda6a699..9065e6284 100644 --- a/src/replication/core/controller.go +++ b/src/replication/core/controller.go @@ -110,9 +110,7 @@ func (ctl *DefaultController) Init() error { if policies != nil && len(policies) > 0 { for _, policy := range policies { if err := ctl.triggerManager.SetupTrigger(&policy); err != nil { - //TODO: Log error - fmt.Printf("Error: %s", err) - //TODO:Update the status of policy + log.Errorf("failed to setup trigger for policy %v: %v", policy, err) } } } @@ -143,8 +141,6 @@ func (ctl *DefaultController) CreatePolicy(newPolicy models.ReplicationPolicy) ( //UpdatePolicy will update the policy with new content. //Parameter updatedPolicy must have the ID of the updated policy. func (ctl *DefaultController) UpdatePolicy(updatedPolicy models.ReplicationPolicy) error { - // TODO check pre-conditions - id := updatedPolicy.ID originPolicy, err := ctl.policyManager.GetPolicy(id) if err != nil { diff --git a/src/replication/source/repository_convertor.go b/src/replication/source/repository_convertor.go index db39d775d..c3a8ea0b8 100644 --- a/src/replication/source/repository_convertor.go +++ b/src/replication/source/repository_convertor.go @@ -34,8 +34,6 @@ func NewRepositoryConvertor(registry registry.Adaptor) *RepositoryConvertor { // Convert projects to repositories func (r *RepositoryConvertor) Convert(items []models.FilterItem) []models.FilterItem { - // TODO get repositories from database where the push/deletion operations are recorded - // if support replicate deletion result := []models.FilterItem{} for _, item := range items { // just put it to the result list if the item is not a project diff --git a/src/replication/source/repository_filter.go b/src/replication/source/repository_filter.go index 78258dfe2..7c4dc33fe 100644 --- a/src/replication/source/repository_filter.go +++ b/src/replication/source/repository_filter.go @@ -17,6 +17,7 @@ package source import ( "strings" + "github.com/vmware/harbor/src/common/utils" "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/replication" "github.com/vmware/harbor/src/replication/models" @@ -71,6 +72,8 @@ func (r *RepositoryFilter) DoFilter(items []models.FilterItem) []models.FilterIt log.Debugf("pattern is null, add %s to the repository filter result list", item.Value) result = append(result, item) } else { + // trim the project + _, repository = utils.ParseRepository(repository) matched, err := match(r.pattern, repository) if err != nil { log.Errorf("failed to match pattern %s to value %s: %v", r.pattern, repository, err) diff --git a/src/replication/source/repository_filter_test.go b/src/replication/source/repository_filter_test.go index 6ab515323..aab5d9462 100644 --- a/src/replication/source/repository_filter_test.go +++ b/src/replication/source/repository_filter_test.go @@ -54,7 +54,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { assert.Equal(t, 1, len(items)) // non-empty pattern - filter = NewRepositoryFilter("library/*", ®istry.HarborAdaptor{}) + filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ models.FilterItem{ Kind: replication.FilterItemKindTag, @@ -64,7 +64,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { assert.Equal(t, 1, len(items)) // non-empty pattern - filter = NewRepositoryFilter("library/*", ®istry.HarborAdaptor{}) + filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ models.FilterItem{ Kind: replication.FilterItemKindTag,