Esempio n. 1
0
//GetDefinition retrieves a specific backend definition
func (BackendDef) GetDefinition(kvs kvstore.KVStore, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	backendName := resourceIDFromURI(req.RequestURI)

	backendConfig, err := config.ReadBackendConfig(backendName, kvs)
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		return nil, err
	}

	if backendConfig == nil {
		resp.WriteHeader(http.StatusNotFound)
		return nil, errBackendNotFound
	}

	return backendConfig, err

}
Esempio n. 2
0
func buildBackend(kvs kvstore.KVStore, name string) (*backend, error) {
	var b backend

	log.Info("Building backend " + name)
	backendConfig, err := config.ReadBackendConfig(name, kvs)
	if err != nil {
		return nil, err
	}

	if backendConfig == nil {
		return nil, errors.New("Backend defnition for '" + name + "' not found")
	}

	b.Name = name
	var servers []config.ServerConfig

	for _, serverName := range backendConfig.ServerNames {
		server, err := buildServer(serverName, kvs)
		if err != nil {
			return nil, err
		}
		servers = append(servers, *server)

	}

	loadBalancer, err := instantiateLoadBalancer(backendConfig.LoadBalancerPolicy, name, backendConfig.CACertPath, servers)
	if err != nil {
		return nil, err
	}

	b.LoadBalancer = loadBalancer

	b.TLSOnly = backendConfig.TLSOnly

	b.CACert, err = createCertPool(backendConfig)
	if err != nil {
		return nil, err
	}

	return &b, nil
}