Using the string trimmed the project name at the begining as the input of repository filter

This commit is contained in:
Wenkai Yin 2017-12-26 19:09:14 +08:00
parent 95339d5488
commit d36811ce52
4 changed files with 6 additions and 9 deletions

View File

@ -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 {

View File

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

View File

@ -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)

View File

@ -54,7 +54,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) {
assert.Equal(t, 1, len(items))
// non-empty pattern
filter = NewRepositoryFilter("library/*", &registry.HarborAdaptor{})
filter = NewRepositoryFilter("*", &registry.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/*", &registry.HarborAdaptor{})
filter = NewRepositoryFilter("*", &registry.HarborAdaptor{})
items = filter.DoFilter([]models.FilterItem{
models.FilterItem{
Kind: replication.FilterItemKindTag,