Exemplo n.º 1
0
func unsetFrontend(etcd *store.Etcd, identifier string) error {
	if err := etcd.DeleteDir(fmt.Sprintf("%s/frontends/%s", vulcandKeyBase, identifier), true); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 2
0
// {"Type": "http", "BackendId": "$identifier", "Route": "Host(`$identifier.$base_domain`) && PathRegexp(`/`)", "Settings": {"TrustForwardHeader": true}}
func setFrontend(etcd *store.Etcd, projectName, identifier, baseDomain string) error {
	key := fmt.Sprintf("%s/frontends/%s/frontend", vulcandKeyBase, identifier)
	frontend := Frontend{
		Type:      "http",
		BackendId: projectName,
		Route:     fmt.Sprintf("Host(`%s.%s`) && PathRegexp(`/`)", strings.ToLower(identifier), strings.ToLower(baseDomain)),
		Settings: FrontendSettings{
			TrustForwardHeader: true,
		},
	}

	b, err := json.Marshal(frontend)

	if err != nil {
		return errors.Wrap(err, "Failed to generate vulcand frontend JSON.")
	}

	// json.Marshal generates HTML-escaped JSON string
	b = bytes.Replace(b, []byte("\\u0026"), []byte("&"), -1)
	json := string(b)

	if err := etcd.Set(key, json); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 3
0
func unsetServer(etcd *store.Etcd, projectName string) error {
	key := fmt.Sprintf("%s/backends/%s/servers", vulcandKeyBase, projectName)

	if err := etcd.DeleteDir(key, true); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 4
0
func unsetBackend(etcd *store.Etcd, projectName string) error {
	key := fmt.Sprintf("%s/backends/%s/backend", vulcandKeyBase, projectName)

	if err := etcd.Delete(key); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 5
0
// {"Type": "http"}
func setBackend(etcd *store.Etcd, projectName string) error {
	key := fmt.Sprintf("%s/backends/%s/backend", vulcandKeyBase, projectName)

	if err := etcd.Set(key, httpBackendJSON); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 6
0
// {"URL": "http://$web_container_host_ip:$web_container_port"}
func setServer(etcd *store.Etcd, projectName string, container *model.Container, baseDomain string) error {
	key := fmt.Sprintf("%s/backends/%s/servers/%s", vulcandKeyBase, projectName, container.ContainerId)
	server := Server{
		URL: fmt.Sprintf("http://%s:%s", container.HostIP(), container.HostPort()),
	}

	b, err := json.Marshal(server)

	if err != nil {
		return errors.Wrap(err, "Failed to generate vulcand server JSON.")
	}

	json := string(b)

	if err := etcd.Set(key, json); err != nil {
		return err
	}

	return nil
}