mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 12:46:03 +01:00
Merge pull request #3882 from ywk253100/171226_fix
Using the string trimmed the project name at the begining as the input of repository filter
This commit is contained in:
commit
da65d46e76
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user