コード例 #1
0
ファイル: vulcand.go プロジェクト: albertrdixon/romulus
func (v *vulcan) NewMiddlewares(rsc *kubernetes.Resource) ([]loadbalancer.Middleware, error) {
	mids := make([]loadbalancer.Middleware, 0, 1)
	for key, def := range DefaultMiddleware {
		if val, ok := rsc.GetAnnotation(key); ok && len(val) > 0 {
			switch key {
			case RedirectSSLID:
				if b, er := strconv.ParseBool(val); er != nil || !b {
					continue
				}
			case TraceID:
				re := regexp.MustCompile(`\s+`)
				list, er := json.Marshal(strings.Split(re.ReplaceAllString(val, ""), ","))
				if er != nil || string(list) == "" {
					logger.Warnf("Unable to json-ify trace headers: %v", er)
					list = []byte("[]")
				}
				def = fmt.Sprintf(def, string(list), string(list))
			case AuthID:
				bits := strings.SplitN(val, ":", 2)
				switch len(bits) {
				case 1:
					def = fmt.Sprintf(def, bits[0], "")
				case 2:
					def = fmt.Sprintf(def, bits[0], bits[1])
				default:
					logger.Errorf("Failed to parse provided basic auth, using default (admin:admin)")
					def = fmt.Sprintf(def, "admin", "admin")
				}
			case MaintenanceID:
				def = fmt.Sprintf(def, val)
			}

			m, er := engine.MiddlewareFromJSON([]byte(def), v.Registry.GetSpec, key)
			if er != nil {
				logger.Warnf("Failed to parse Middleware %s: %v", key, er)
				logger.Debugf("%q", def)
				continue
			}
			mids = append(mids, newMiddleware(m))
		}
	}

	rg := regexp.MustCompile(CustomMiddlewareKeyPattern)
	matches, _ := rsc.GetAnnotations(CustomMiddlewareKeyPattern)
	for key, val := range matches {
		if match := rg.FindStringSubmatch(key); match != nil {
			id := match[1]
			m, er := engine.MiddlewareFromJSON([]byte(val), v.Registry.GetSpec, id)
			if er != nil {
				logger.Warnf("Failed to parse Middleware %s: %v", id, er)
				continue
			}
			mids = append(mids, newMiddleware(m))
		}
	}

	return mids, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: albertrdixon/romulus
func (c *Client) GetMiddleware(mk engine.MiddlewareKey) (*engine.Middleware, error) {
	data, err := c.Get(c.endpoint("frontends", mk.FrontendKey.Id, "middlewares", mk.Id), url.Values{})
	if err != nil {
		return nil, err
	}
	return engine.MiddlewareFromJSON(data, c.Registry.GetSpec)
}
コード例 #3
0
ファイル: etcd.go プロジェクト: albertrdixon/romulus
func (n *ng) GetMiddleware(key engine.MiddlewareKey) (*engine.Middleware, error) {
	mKey := n.path("frontends", key.FrontendKey.Id, "middlewares", key.Id)
	bytes, err := n.getVal(mKey)
	if err != nil {
		return nil, err
	}
	return engine.MiddlewareFromJSON([]byte(bytes), n.registry.GetSpec, key.Id)
}
コード例 #4
0
ファイル: api.go プロジェクト: albertrdixon/romulus
func parseMiddlewarePack(v []byte, r *plugin.Registry) (*engine.Middleware, time.Duration, error) {
	var mp middlewareReadPack
	if err := json.Unmarshal(v, &mp); err != nil {
		return nil, 0, err
	}
	if len(mp.Middleware) == 0 {
		return nil, 0, &scroll.MissingFieldError{Field: "Middleware"}
	}
	f, err := engine.MiddlewareFromJSON(mp.Middleware, r.GetSpec)
	if err != nil {
		return nil, 0, err
	}
	var ttl time.Duration
	if mp.TTL != "" {
		ttl, err = time.ParseDuration(mp.TTL)
		if err != nil {
			return nil, 0, err
		}
	}
	return f, ttl, nil
}