Example #1
0
func getDomainDiscoveryFlagValue(c *cli.Context) ([]string, error) {
	domainstr, insecure := getDiscoveryDomain(c)

	// If we still don't have domain discovery, return nothing
	if domainstr == "" {
		return []string{}, nil
	}

	discoverer := client.NewSRVDiscover()
	eps, err := discoverer.Discover(domainstr)
	if err != nil {
		return nil, err
	}
	if insecure {
		return eps, err
	}
	// strip insecure connections
	ret := []string{}
	for _, ep := range eps {
		if strings.HasPrefix("http://", ep) {
			fmt.Fprintf(os.Stderr, "ignoring discovered insecure endpoint %q\n", ep)
			continue
		}
		ret = append(ret, ep)
	}
	return ret, err
}
Example #2
0
func startGateway(cmd *cobra.Command, args []string) {
	endpoints := gatewayEndpoints
	if gatewayDNSCluster != "" {
		eps, err := client.NewSRVDiscover().Discover(gatewayDNSCluster)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
		plog.Infof("discovered the cluster %s from %s", eps, gatewayDNSCluster)
	}

	l, err := net.Listen("tcp", gatewayListenAddr)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	tp := tcpproxy.TCPProxy{
		Listener:        l,
		Endpoints:       endpoints,
		MonitorInterval: getewayRetryDelay,
	}

	tp.Run()
}
Example #3
0
func startGateway(cmd *cobra.Command, args []string) {
	endpoints := gatewayEndpoints
	if gatewayDNSCluster != "" {
		eps, err := client.NewSRVDiscover().Discover(gatewayDNSCluster)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
		plog.Infof("discovered the cluster %s from %s", eps, gatewayDNSCluster)
		// confirm TLS connections are good
		if !gatewayInsecureDiscovery {
			tlsInfo := transport.TLSInfo{
				TrustedCAFile: gatewayCA,
				ServerName:    gatewayDNSCluster,
			}
			plog.Infof("validating discovered endpoints %v", eps)
			endpoints, err = transport.ValidateSecureEndpoints(tlsInfo, eps)
			if err != nil {
				plog.Warningf("%v", err)
			}
			plog.Infof("using discovered endpoints %v", endpoints)
		}
	}

	if len(endpoints) == 0 {
		plog.Fatalf("no endpoints found")
	}

	l, err := net.Listen("tcp", gatewayListenAddr)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	tp := tcpproxy.TCPProxy{
		Listener:        l,
		Endpoints:       endpoints,
		MonitorInterval: getewayRetryDelay,
	}

	tp.Run()
}
Example #4
0
func getDomainDiscoveryFlagValue(c *cli.Context) ([]string, error) {
	domainstr := c.GlobalString("discovery-srv")

	// Use an environment variable if nothing was supplied on the
	// command line
	if domainstr == "" {
		domainstr = os.Getenv("ETCDCTL_DISCOVERY_SRV")
	}

	// If we still don't have domain discovery, return nothing
	if domainstr == "" {
		return []string{}, nil
	}

	discoverer := client.NewSRVDiscover()
	eps, err := discoverer.Discover(domainstr)
	if err != nil {
		return nil, err
	}

	return eps, err
}