From 6311ff4ab288384ed070edd05047caebcd4f426f Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 6 Jan 2015 17:04:10 -0700 Subject: [PATCH] Set labels on container create Signed-off-by: Darren Shepherd --- parsers/filters/parse.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/parsers/filters/parse.go b/parsers/filters/parse.go index 8b045a3..9c056bb 100644 --- a/parsers/filters/parse.go +++ b/parsers/filters/parse.go @@ -65,6 +65,38 @@ func FromParam(p string) (Args, error) { return args, nil } +func (filters Args) MatchKVList(field string, sources map[string]string) bool { + fieldValues := filters[field] + + //do not filter if there is no filter set or cannot determine filter + if len(fieldValues) == 0 { + return true + } + + if sources == nil || len(sources) == 0 { + return false + } + +outer: + for _, name2match := range fieldValues { + testKV := strings.SplitN(name2match, "=", 2) + + for k, v := range sources { + if len(testKV) == 1 { + if k == testKV[0] { + continue outer + } + } else if k == testKV[0] && v == testKV[1] { + continue outer + } + } + + return false + } + + return true +} + func (filters Args) Match(field, source string) bool { fieldValues := filters[field]