mirror of
https://github.com/goharbor/harbor.git
synced 2024-08-28 14:59:37 +02:00
Merge pull request #3473 from steven-zou/master
Define filter interfaces for replication service
This commit is contained in:
commit
3565f60f5b
10
src/replication/consts.go
Normal file
10
src/replication/consts.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package replication
|
||||
|
||||
const (
|
||||
//Kind of filter item is 'project'
|
||||
filterItemKindProject = "project"
|
||||
//Kind of filter item is 'repository'
|
||||
filterItemKindRepository = "repository"
|
||||
//Kind of filter item is 'tag'
|
||||
filterItemKindTag = "tag"
|
||||
)
|
7
src/replication/models/filter_config.go
Normal file
7
src/replication/models/filter_config.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package models
|
||||
|
||||
//FilterConfig is data model to provide configurations to the filters.
|
||||
type FilterConfig struct {
|
||||
//The pattern for fuzzy matching
|
||||
pattern string
|
||||
}
|
19
src/replication/models/filter_item.go
Normal file
19
src/replication/models/filter_item.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package models
|
||||
|
||||
//FilterItem is the general data model represents the filtering resources which are used as input and output for the filters.
|
||||
type FilterItem struct {
|
||||
|
||||
//The kind of the filtering resources. Support 'project','repository' and 'tag' etc.
|
||||
kind string
|
||||
|
||||
//The key value of resource which can be used to filter out the resource matched with specified pattern.
|
||||
//E.g:
|
||||
//kind == 'project', value will be project name;
|
||||
//kind == 'repository', value will be repository name
|
||||
//kind == 'tag', value will be tag name.
|
||||
value string
|
||||
|
||||
//Extension placeholder.
|
||||
//To append more additional information if required by the filter.
|
||||
metadata map[string]interface{}
|
||||
}
|
16
src/replication/source/convertor.go
Normal file
16
src/replication/source/convertor.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package source
|
||||
|
||||
import (
|
||||
"github.com/vmware/harbor/src/replication/models"
|
||||
)
|
||||
|
||||
//Convertor is designed to covert the format of output from upstream filter to the input format
|
||||
//required by the downstream filter if needed.
|
||||
//Each convertor covers only one specified conversion process between the two filters.
|
||||
//E.g:
|
||||
//If project filter connects to repository filter, then one convertor should be defined for this connection;
|
||||
//If project filter connects to tag filter, then another one should be defined. The above one can not be reused.
|
||||
type Convertor interface {
|
||||
//Accept the items from upstream filter as input and then covert them to the required format and returned.
|
||||
Convert(itemsOfUpstream []models.FilterItem) (itemsOfDownstream []models.FilterItem)
|
||||
}
|
21
src/replication/source/filter.go
Normal file
21
src/replication/source/filter.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package source
|
||||
|
||||
import (
|
||||
"github.com/vmware/harbor/src/replication/models"
|
||||
)
|
||||
|
||||
//Filter define the operations of selecting the matched resources from the candidates
|
||||
//according to the specified pattern.
|
||||
type Filter interface {
|
||||
//Initialize the filter with specified configurations like pattern definition
|
||||
Init(config models.FilterConfig)
|
||||
|
||||
//Set Convertor if necessary
|
||||
SetConvertor(convertor Convertor)
|
||||
|
||||
//Return the convertor if existing or nil if never set
|
||||
GetConvertor() Convertor
|
||||
|
||||
//Filter the items
|
||||
DoFilter(filterItems []models.FilterItem) []models.FilterItem
|
||||
}
|
21
src/replication/source/filter_chain.go
Normal file
21
src/replication/source/filter_chain.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package source
|
||||
|
||||
import (
|
||||
"github.com/vmware/harbor/src/replication/models"
|
||||
)
|
||||
|
||||
//FilterChain is the interface to define the operations of coordinating multiple filters
|
||||
//to work together as a whole pipeline.
|
||||
//E.g:
|
||||
//(original resources)---->[project filter]---->[repository filter]---->[tag filter]---->[......]---->(filter resources)
|
||||
type FilterChain interface {
|
||||
//Build the filter chain with the filters provided;
|
||||
//if failed, an error will be returned.
|
||||
Build(filter []Filter) error
|
||||
|
||||
//Return all the filters in the chain.
|
||||
Filters() []Filter
|
||||
|
||||
//Filter the items and returned the filtered items via the appended filters in the chain.
|
||||
DoFilter(filterItems []models.FilterItem) []models.FilterItem
|
||||
}
|
Loading…
Reference in New Issue
Block a user