• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang etcd.NewTLSClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coreos/go-etcd/etcd.NewTLSClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTLSClient函数的具体用法?Golang NewTLSClient怎么用?Golang NewTLSClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewTLSClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewEtcd

func NewEtcd(prefixKey string, config *EtcdConfig) (*Etcd, error) {
	var (
		client *etcd.Client
		err    error
	)

	if config.CertFile != "" && config.KeyFile != "" {
		if client, err = etcd.NewTLSClient(config.Machines, config.CertFile, config.KeyFile, config.CaFile); err != nil {
			Logger.Error("Failed to connect to Etcd. Error: %+v.", err)
			return nil, err
		}
	} else {
		client = etcd.NewClient(config.Machines)
	}

	// Set the default value if not provided.
	if config.EtcdConsistency == "" {
		config.EtcdConsistency = etcd.STRONG_CONSISTENCY
	}

	if err = client.SetConsistency(config.EtcdConsistency); err != nil {
		Logger.Error("Failed to set Etcd consitency. Error: %+v.", err)
		return nil, err
	}

	return &Etcd{client: client, prefixKey: prefixKey}, nil
}
开发者ID:yonglehou,项目名称:maestro,代码行数:27,代码来源:etcd.go


示例2: NewEtcdClient

// NewEtcdClient returns an *etcd.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewEtcdClient(machines []string, cert, key string, caCert string) (*Client, error) {
	var c *goetcd.Client
	var err error
	if cert != "" && key != "" {
		c, err = goetcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return &Client{c}, err
		}
	} else {
		c = goetcd.NewClient(machines)
	}
	// Configure the DialTimeout, since 1 second is often too short
	c.SetDialTimeout(time.Duration(3) * time.Second)

	maxConnectAttempts := 10
	for attempt := 1; attempt <= maxConnectAttempts; attempt++ {
		success := c.SetCluster(machines)
		if success {
			break
			return &Client{c}, nil
		}

		if attempt == maxConnectAttempts {
			break
			return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
		}
		log.Info(fmt.Sprintf("[Attempt: %d] Attempting access to etcd after 5 second sleep", attempt))
		time.Sleep(5 * time.Second)
	}

	return &Client{c}, nil
}
开发者ID:Lineberty,项目名称:confd,代码行数:34,代码来源:client.go


示例3: New

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, f.Scheme+"://"+uri.Host)
	} else {
		urls = append(urls, f.Scheme+"://127.0.0.1:4001")
	}

	if f.Scheme == "https" {
		cert := os.Getenv("ETCD_CERTFILE")
		key := os.Getenv("ETCD_KEYFILE")
		caCert := os.Getenv("ETCD_CAFILE")
		client, err := etcd2.NewTLSClient(urls, cert, key, caCert)
		if err != nil {
			log.Fatal("etcd: error creating tls client", err)
		}
		return &EtcdAdapter{client2: client, path: uri.Path}
	}

	res, err := http.Get(urls[0] + "/version")
	if err != nil {
		log.Fatal("etcd: error retrieving version", err)
	}

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	if match, _ := regexp.Match("0\\.4\\.*", body); match == true {
		log.Println("etcd: using v0 client")
		return &EtcdAdapter{client: etcd.NewClient(urls), path: uri.Path}
	}

	return &EtcdAdapter{client2: etcd2.NewClient(urls), path: uri.Path}
}
开发者ID:genki,项目名称:registrator,代码行数:34,代码来源:etcd.go


示例4: newEtcdClient

func newEtcdClient(c *EtcdConfig) (*etcd.Client, error) {
	if c.Keyfile != "" || c.Certfile != "" || c.CAFile != "" {
		return etcd.NewTLSClient(c.Endpoints, c.Certfile, c.Keyfile, c.CAFile)
	} else {
		return etcd.NewClient(c.Endpoints), nil
	}
}
开发者ID:rajkotecha,项目名称:origin,代码行数:7,代码来源:registry.go


示例5: Client

func Client() *etcd.Client {
	clientSingletonO.Do(func() {
		host := "http://localhost:4001"
		if len(os.Getenv("ETCD_HOST")) != 0 {
			host = os.Getenv("ETCD_HOST")
		}

		cacert := os.Getenv("ETCD_CACERT")
		tlskey := os.Getenv("ETCD_TLS_KEY")
		tlscert := os.Getenv("ETCD_TLS_CERT")
		if len(cacert) != 0 && len(tlskey) != 0 && len(tlscert) != 0 {
			if !strings.Contains(host, "https://") {
				host = strings.Replace(host, "http", "https", 1)
			}
			c, err := etcd.NewTLSClient([]string{host}, tlscert, tlskey, cacert)
			if err != nil {
				panic(err)
			}
			clientSingleton = c
		} else {
			clientSingleton = etcd.NewClient([]string{host})
		}
	})
	return clientSingleton
}
开发者ID:xwangkai,项目名称:etcd-discovery,代码行数:25,代码来源:init.go


示例6: New

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, f.Scheme+"://"+uri.Host)
	} else {
		urls = append(urls, f.Scheme+"://127.0.0.1:4001")
	}

	if len(uri.Path) < 2 {
		log.Fatal("skydns2: dns domain required e.g.: skydns2://<host>/<domain>")
	}

	if f.Scheme == "https" {
		cert := os.Getenv("ETCD_CERTFILE")
		key := os.Getenv("ETCD_KEYFILE")
		caCert := os.Getenv("ETCD_CAFILE")
		client, err := etcd.NewTLSClient(urls, cert, key, caCert)
		if err != nil {
			log.Fatal("etcd: error creating tls client", err)
		}
		return &Skydns2Adapter{client: client, path: domainPath(uri.Path[1:])}
	}

	return &Skydns2Adapter{client: etcd.NewClient(urls), path: domainPath(uri.Path[1:])}
}
开发者ID:genki,项目名称:registrator,代码行数:25,代码来源:skydns2.go


示例7: newEtcdLockClient

func newEtcdLockClient(e *EtcdLock) (utils.Registry, error) {
	var c utils.Registry
	// if all are set, try to use tls
	if *e.CertFile != "" && *e.KeyFile != "" && *e.CAFile != "" {
		return etcd.NewTLSClient(*e.Members, *e.CertFile, *e.KeyFile, *e.CAFile)
	}
	c = etcd.NewClient(*e.Members)

	return c, nil
}
开发者ID:roboll,项目名称:elector,代码行数:10,代码来源:etcd.go


示例8: NewClient

func NewClient(machines []string, cert, key, ca string) (client *Client, err error) {
	client = &Client{}
	if cert != "" && key != "" && ca != "" {
		if client.Client, err = etcd.NewTLSClient(machines, cert, key, ca); err != nil {
			return
		}
	} else {
		client.Client = etcd.NewClient(machines)
	}
	return
}
开发者ID:alemic,项目名称:gleam,代码行数:11,代码来源:client.go


示例9: NewEtcdClient

func NewEtcdClient() (client *etcd.Client) {
	if etcdClient != nil {
		return etcdClient
	}

	tlsEnabled := os.Getenv("ETCDCTL_TLS")
	tls := len(tlsEnabled) > 0

	certFile := os.Getenv("ETCDCTL_CERT_FILE")
	keyFile := os.Getenv("ETCDCTL_KEY_FILE")
	caFile := os.Getenv("ETCDCTL_TRUSTED_CA_FILE")

	var err error
	peersStr := os.Getenv("ETCDCTL_PEERS")
	if len(peersStr) > 0 {
		log.Println("Connecting to etcd peers : " + peersStr)
		peers := strings.Split(peersStr, ",")
		if tls {
			etcdClient, err = etcd.NewTLSClient(peers, certFile, keyFile, caFile)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			etcdClient = etcd.NewClient(peers)
		}
	} else {
		if tls {
			etcdClient, err = etcd.NewTLSClient(nil, certFile, keyFile, caFile)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			etcdClient = etcd.NewClient(nil)
		}
	}

	return etcdClient
}
开发者ID:keithballdotnet,项目名称:couchbase-array,代码行数:38,代码来源:couchbase.go


示例10: NewClient

//新建注册中心客户端
func (c *Conn) NewClient() (result *registry, err error) {
	var client *etcd.Client
	if c.Tls == true {
		//https conn
		client, err = etcd.NewTLSClient(c.Hosts, c.Cert, c.Key, c.CaCert)
	} else {
		//http conn
		client = etcd.NewClient(c.Hosts)
		if client == nil {
			err = fmt.Errorf("client init faild")
		}
	}
	return &registry{pool: client}, err
}
开发者ID:chuangyou,项目名称:qsf,代码行数:15,代码来源:registry.go


示例11: newClient

func newClient() (client *etcd.Client) {
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		if client, err = etcd.NewTLSClient(machines, tlspem, tlskey, ""); err != nil {
			log.Fatal(err)
		}
	} else {
		client = etcd.NewClient(machines)
	}
	client.SyncCluster()
	return client
}
开发者ID:njhartwell,项目名称:skydns2,代码行数:15,代码来源:main.go


示例12: newClient

func newClient(machines []string, tlsCert, tlsKey, tlsCACert string) (client *etcd.Client) {
	// set default if not specified in env
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		// TODO(miek): machines is local, the rest is global, ugly.
		if client, err = etcd.NewTLSClient(machines, tlsCert, tlsKey, tlsCACert); err != nil {
			// TODO(miek): would be nice if this wasn't a fatal error
			log.Fatalf("skydns: failure to connect: %s", err)
		}
		return client
	}
	return etcd.NewClient(machines)
}
开发者ID:schatt,项目名称:skydns,代码行数:16,代码来源:main.go


示例13: NewEtcdClient

// NewEtcdClient returns an *etcd.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewEtcdClient(machines []string, cert, key string, caCert string) (*Client, error) {
	var c *etcd.Client
	if cert != "" && key != "" {
		c, err := etcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return &Client{c}, err
		}
	} else {
		c = etcd.NewClient(machines)
	}
	success := c.SetCluster(machines)
	if !success {
		return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
	}
	return &Client{c}, nil
}
开发者ID:carriercomm,项目名称:haproxy-confd,代码行数:18,代码来源:client.go


示例14: reconnect

func (n *ng) reconnect() error {
	n.Close()
	var client *etcd.Client
	if n.options.EtcdCertFile == "" && n.options.EtcdKeyFile == "" {
		client = etcd.NewClient(n.nodes)
	} else {
		var err error
		if client, err = etcd.NewTLSClient(n.nodes, n.options.EtcdCertFile, n.options.EtcdKeyFile, n.options.EtcdCaFile); err != nil {
			return err
		}
	}
	if err := client.SetConsistency(n.options.EtcdConsistency); err != nil {
		return err
	}
	n.client = client
	return nil
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:17,代码来源:etcd.go


示例15: NewClient

// NewClient returns an *etcd.Client with a connection to the named machines.
// It will return an error if a connection to the cluster cannot be made.
// The parameter machines needs to be a full URL with schemas.
// e.g. "http://localhost:4001" will work, but "localhost:4001" will not.
func NewClient(machines []string, cert, key, caCert string) (Client, error) {
	var c *etcd.Client
	var err error

	if cert != "" && key != "" {
		c, err = etcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return nil, err
		}
	} else {
		c = etcd.NewClient(machines)
	}
	success := c.SetCluster(machines)
	if !success {
		return nil, fmt.Errorf("cannot connect to the etcd cluster: %s", strings.Join(machines, ","))
	}
	return &client{c}, nil
}
开发者ID:nimmen,项目名称:kit,代码行数:22,代码来源:client.go


示例16: NewClient

func NewClient(machines []string) (client *etcd.Client) {
	// set default if not specified in env
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		if client, err = etcd.NewTLSClient(machines, tlspem, tlskey, cacert); err != nil {
			// TODO(miek): would be nice if this wan't a fatal error
			log.Fatalf("failure to connect: %s\n", err)
		}
		client.SyncCluster()
	} else {
		client = etcd.NewClient(machines)
		client.SyncCluster()
	}
	return client
}
开发者ID:korya,项目名称:skydns,代码行数:18,代码来源:client.go


示例17: NewEtcdClient

// NewEtcdClient returns an *etcd.Client with a connection to named machines.
// It returns an error if a connection to the cluster cannot be made.
func NewEtcdClient(machines []string, cert, key string, caCert string) (*Client, error) {
	var c *etcd.Client
	if cert != "" && key != "" {
		c, err := etcd.NewTLSClient(machines, cert, key, caCert)
		if err != nil {
			return &Client{c}, err
		}
	} else {
		c = etcd.NewClient(machines)
	}
	// Configure the DialTimeout, since 1 second is often too short
	c.SetDialTimeout(time.Duration(3) * time.Second)
	success := c.SetCluster(machines)
	if !success {
		return &Client{c}, errors.New("cannot connect to etcd cluster: " + strings.Join(machines, ","))
	}
	return &Client{c}, nil
}
开发者ID:radartools,项目名称:confd,代码行数:20,代码来源:client.go


示例18: newEtcdBackend

// newEtcdBackend constructs a etcd backend using a given machine address.
func newEtcdBackend(conf map[string]string) (Backend, error) {
	// Get the etcd path form the configuration.
	path, ok := conf["path"]
	if !ok {
		path = "/vault"
	}

	// Ensure path is prefixed.
	if !strings.HasPrefix(path, "/") {
		path = "/" + path
	}

	// Set a default machines list and check for an overriding address value.
	machines := "http://128.0.0.1:2379"
	if address, ok := conf["address"]; ok {
		machines = address
	}
	machinesParsed := strings.Split(machines, EtcdMachineDelimiter)

	// Create a new client from the supplied address and attempt to sync with the
	// cluster.
	var client *etcd.Client
	cert, has_cert := conf["tls_cert_file"]
	key, has_key := conf["tls_key_file"]
	ca, has_ca := conf["tls_ca_file"]
	if has_cert || has_key || has_ca {
		var err error
		client, err = etcd.NewTLSClient(machinesParsed, cert, key, ca)
		if err != nil {
			return nil, err
		}
	} else {
		client = etcd.NewClient(machinesParsed)
	}
	if !client.SyncCluster() {
		return nil, EtcdSyncClusterError
	}

	// Setup the backend.
	return &EtcdBackend{
		path:   path,
		client: client,
	}, nil
}
开发者ID:gdb,项目名称:vault,代码行数:45,代码来源:etcd.go


示例19: New

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)

	if len(uri.Path) < 2 {
		log.Fatal("skydns2: dns domain required e.g.: skydns2://<host>/<domain>")
	}

	tlskey := os.Getenv("ETCD_TLSKEY")
	tlspem := os.Getenv("ETCD_TLSPEM")
	cacert := os.Getenv("ETCD_CACERT")

	var client *etcd.Client

	// Assuming https
	if cacert != "" {
		urls = append(urls, "https://"+uri.Host)

		// Assuming Client authentication if tlskey and tlspem is set
		if tlskey != "" && tlspem != "" {
			var err error
			if client, err = etcd.NewTLSClient(urls, tlspem, tlskey, cacert); err != nil {
				log.Fatalf("skydns2: failure to connect: %s", err)
			}
		} else {
			client = etcd.NewClient(urls)
			ca, err := ioutil.ReadFile(cacert)
			if err != nil {
				log.Fatal(err)
			}
			caCertPool := x509.NewCertPool()
			caCertPool.AppendCertsFromPEM(ca)
			tr := &http.Transport{
				TLSClientConfig:    &tls.Config{RootCAs: caCertPool},
				DisableCompression: true,
			}
			client.SetTransport(tr)
		}
	} else {
		urls = append(urls, "http://"+uri.Host)
		client = etcd.NewClient(urls)
	}

	return &Skydns2Adapter{client: client, path: domainPath(uri.Path[1:])}
}
开发者ID:csatf,项目名称:registrator,代码行数:44,代码来源:skydns2.go


示例20: newClient

func newClient() (client *etcd.Client) {
	if len(machines) == 1 && machines[0] == "" {
		machines[0] = "http://127.0.0.1:4001"
		// override if we have a commandline flag as well
		if machine != "" {
			strings.Split(machine, ",")
		}
	}
	if strings.HasPrefix(machines[0], "https://") {
		var err error
		if client, err = etcd.NewTLSClient(machines, tlspem, tlskey, ""); err != nil {
			log.Fatal(err)
		}
	} else {
		client = etcd.NewClient(machines)
	}
	client.SyncCluster()
	return client
}
开发者ID:nhulac,项目名称:skydns,代码行数:19,代码来源:main.go



注:本文中的github.com/coreos/go-etcd/etcd.NewTLSClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang etcd.SetLogger函数代码示例发布时间:2022-05-23
下一篇:
Golang etcd.NewClientFromFile函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap