diff --git a/v3/pkg/util/inexlist/dcfilter/dcfilter.go b/v3/pkg/util/inexlist/dcfilter/dcfilter.go index 24a931b18..22f7843ae 100644 --- a/v3/pkg/util/inexlist/dcfilter/dcfilter.go +++ b/v3/pkg/util/inexlist/dcfilter/dcfilter.go @@ -37,6 +37,29 @@ func Apply(dcMap map[string][]string, filters []string) ([]string, error) { return filtered, nil } +// Filter that lets you filter datacenters. +type Filter struct { + filters []string + inex inexlist.InExList +} + +func NewFilter(filters []string) (*Filter, error) { + // Decorate filters and create inexlist + inex, err := inexlist.ParseInExList(decorate(filters)) + if err != nil { + return nil, errors.Wrapf(err, "parse dc filter %v", filters) + } + return &Filter{ + filters: filters, + inex: inex, + }, nil +} + +// Check returns true iff dc matches filter. +func (f *Filter) Check(dc string) bool { + return len(f.inex.Filter([]string{dc})) > 0 +} + func decorate(filters []string) []string { if len(filters) == 0 { filters = append(filters, "*")