Beispiel #1
0
func (hmf headerMatcherFactory) Create(config interface{}) (Matcher, error) {
	headermatcherconfig := matcherConfig{}
	if err := common.ReMarshal(config, &headermatcherconfig); err != nil {
		return headerMatcher{}, err
	}

	if len(headermatcherconfig.MatchAny) == 0 {
		return headerMatcher{}, errorMatcherConfig{
			name:    hmf.Type(),
			message: "missing key match_any",
		}
	}

	headers := []headerMatch{}
	for _, headerdetails := range headermatcherconfig.MatchAny {
		if headerdetails.Name == "" {
			return headerMatcher{}, errorMatcherConfig{
				name:    hmf.Type(),
				message: "name required for headers",
			}
		}

		headermatch, err := newHeaderMatch(headerdetails.Name, headerdetails.Match)
		if err != nil {
			return headerMatcher{}, err
		}
		headers = append(headers, headermatch)
	}
	return headerMatcher{headers: headers}, nil
}
Beispiel #2
0
// NewHeaderLimitKeys creates a slice of headerLimitKeys that keys on the named request header
func NewHeaderLimitKeys(config interface{}) ([]LimitKey, error) {
	conf := headerConfig{}
	err := common.ReMarshal(config, &conf)
	if err != nil {
		return nil, err
	}
	keys := []LimitKey{}
	sort.Strings(conf.Names) // order of config should not change bucketnames
	for _, header := range conf.Names {
		keys = append(keys, &headerLimitKey{name: header, salt: conf.Encrypt})
	}
	return keys, nil
}
Beispiel #3
0
func (pmf pathMatcherFactory) Create(config interface{}) (Matcher, error) {
	matcherConfig := pathMatcherConfig{}
	matcher := pathMatcher{}
	if err := common.ReMarshal(config, &matcherConfig); err != nil {
		return matcher, err
	}

	if len(matcherConfig.MatchAny) == 0 {
		return matcher, errorMatcherConfig{
			name:    pmf.Type(),
			message: "missing key match_any or no paths",
		}
	}

	for _, p := range matcherConfig.MatchAny {
		compiled, err := regexp.Compile(p)
		if err != nil {
			return matcher, err
		}
		matcher.Paths = append(matcher.Paths, compiled)
	}
	return matcher, nil
}