// NewAuthClusterClient returns a new REST client.
// host: REST endpoint [http://<ip>:<port> OR unix://<path-to-unix-socket>]. default: [unix://var/lib/osd/cluster/osd.sock]
// version: Cluster API version
325156
func NewAuthClusterClient(host, version string, authstring string, accesstoken string) (*client.Client, error) {
	if host == "" {
		host = client.GetUnixServerPath(OsdSocket, cluster.APIBase)
	}

	if version == "" {
		// Set the default version
		version = cluster.APIVersion
	}

	return client.NewAuthClient(host, version, authstring, accesstoken, "")
}
504880
func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
	// Default TLS names when TLS enabled.
	newHosts := make([]*Host, 0, len(hosts))
	if policy.TlsConfig != nil && !policy.TlsConfig.InsecureSkipVerify {
		useClusterName := len(policy.ClusterName) > 0

		for _, host := range hosts {
			nh := *host
			if nh.TLSName == "" {
				if useClusterName {
					nh.TLSName = policy.ClusterName
				} else {
					nh.TLSName = host.Name
				}
			}
			newHosts = append(newHosts, &nh)
		}
		hosts = newHosts
	}

	newCluster := &Cluster{
		clientPolicy: *policy,
		infoPolicy:   InfoPolicy{Timeout: policy.Timeout},
		tendChannel:  make(chan struct{}),

		seeds:    NewSyncVal(hosts),
		aliases:  NewSyncVal(make(map[Host]*Node)),
		nodesMap: NewSyncVal(make(map[string]*Node)),
		nodes:    NewSyncVal([]*Node{}),
		stats:    map[string]*nodeStats{},

		password: NewSyncVal(nil),

		supportsFloat:       NewAtomicBool(false),
		supportsBatchIndex:  NewAtomicBool(false),
		supportsReplicasAll: NewAtomicBool(false),
		supportsGeo:         NewAtomicBool(false),
	}

	newCluster.partitionWriteMap.Store(make(partitionMap))

	// setup auth info for cluster
	if policy.RequiresAuthentication() {
		if policy.AuthMode == AuthModeExternal && policy.TlsConfig == nil {
			return nil, errors.New("External Authentication requires TLS configuration to be set, because it sends clear password on the wire.")
		}

		newCluster.user = policy.User
		hashedPass, err := hashPassword(policy.Password)
		if err != nil {
			return nil, err
		}
		newCluster.password = NewSyncVal(hashedPass)
	}

	// try to seed connections for first use
	err := newCluster.waitTillStabilized()

	// apply policy rules
	if policy.FailIfNotConnected && !newCluster.IsConnected() {
		if err != nil {
			return nil, err
		}
		return nil, fmt.Errorf("Failed to connect to host(s): %v. The network connection(s) to cluster nodes may have timed out, or the cluster may be in a state of flux.", hosts)
	}

	// start up cluster maintenance go routine
	newCluster.wgTend.Add(1)
	go newCluster.clusterBoss(&newCluster.clientPolicy)

	if err == nil {
		Logger.Debug("New cluster initialized and ready to be used...")
	} else {
		Logger.Error("New cluster was not initialized successfully, but the client will keep trying to connect to the database. Error: %s", err.Error())
	}

	return newCluster, err
}
1184659
func NewClient(accessKeyId, accessKeySecret string) *Client {
	client := &Client{}
	client.Init(END_POINT, VERSION, accessKeyId, accessKeySecret)
	return client
}
647725
func NewClient(region string, auth Auth, httpClient *http.Client) (*Client, error) {
	if httpClient == nil {
		httpClient = &http.Client{}
	}

	c := &Client{httpClient: httpClient}

	c.endpoint = fmt.Sprintf(identityBaseURL, region)

	identity, err := c.getIdentity(auth)
	if err != nil {
		return nil, fmt.Errorf("failed to login: %v", err)
	}

	c.token = identity.Access.Token.ID
	c.endpoint = fmt.Sprintf(dnsServiceBaseURL, region)

	return c, nil
}
1115274
func NewClient(cluster []string) *Client {
	return &Client{
		cluster:       cluster,
		pool:          NewPool(cluster),
		logging:       false,
		pingFrequency: 1000,
		closed:        make(chan struct{}),
	}
}
489075
func (c *Client) AddCluster(p *AddClusterParameter) (*Cluster, error) {
	obj, err := c.Request("addCluster", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Cluster), err
}
155969
func NewClient(hostname string, port int) (*Client, error) {
	return NewClientWithPolicyAndHost(NewClientPolicy(), NewHost(hostname, port))
}
559543
func NewClient(host string, port int) (client *Client, err error) {
	client = new(Client)
	client.Host = host
	client.Port = port
	client.Connection, err = net.Dial("tcp", fmt.Sprintf("%v:%v", client.Host, client.Port))
	return
}
112923
func NewClient(accessKeyId, accessKeySecret string) *Client {
	endpoint := os.Getenv("KMS_ENDPOINT")
	if endpoint == "" {
		endpoint = KMSDefaultEndpoint
	}
	return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}
33557
func NewClient(addr string, authConfig types.AuthConfig) *Client {
	conn := connect(addr, authConfig)
	return &Client{addr: addr, conn: conn}
}
133642
func NewClient(config *ssh.ClientConfig) transport.Transport {
	return common.NewClient(&runner{config: config})
}
123623
func NewClient() (*Client, error) {
	osdbServer := os.Getenv("OSDB_SERVER")
	if osdbServer == "" {
		osdbServer = DefaultOSDBServer
	}
	rpc, err := xmlrpc.NewClient(osdbServer, nil)
	if err != nil {
		return nil, err
	}

	c := &Client{
		UserAgent: DefaultUserAgent,
		Client:    rpc, // xmlrpc.Client
	}

	return c, nil
}
1342234
func CreateClusterClient(config ClusterConfig) (Client, error) {
	return goredis.NewClusterClient(&goredis.ClusterOptions{
		Addrs: config.Endpoints,

		// Enables read only queries on slave nodes.
		ReadOnly: config.EnableReadQueryOnSlave,

		MaxRedirects:   config.MaxRedirects,
		RouteByLatency: config.RouteByLatency,

		// Optional password. Must match the password specified in the requirepass server configuration option.
		Password: config.Password,

		// Dial timeout for establishing new connections. Default is 5 seconds.
		DialTimeout: config.DialTimeout,
		// Timeout for socket reads. If reached, commands will fail with a timeout instead of blocking. Default is 3 seconds.
		ReadTimeout: config.ReadTimeout,
		// Timeout for socket writes. If reached, commands will fail with a timeout instead of blocking. Default is ReadTimeout.
		WriteTimeout: config.WriteTimeout,

		// Maximum number of socket connections. Default is 10 connections per every CPU as reported by runtime.NumCPU.
		PoolSize: config.Pool.PoolSize,
		// Amount of time a client waits for connection if all connections are busy before returning an error. Default is ReadTimeout + 1 second.
		PoolTimeout: config.Pool.PoolTimeout,
		// Amount of time after which a client closes idle connections. Should be less than server's timeout. Default is 5 minutes.
		IdleTimeout: config.Pool.IdleTimeout,
		// Frequency of idle checks. Default is 1 minute. When negative value is set, then idle check is disabled.
		IdleCheckFrequency: config.Pool.IdleCheckFrequency,

		// Maximum number of retries before giving up. Default is to not retry failed commands.
		MaxRetries: 0,
		// Minimum backoff between each retry. Default is 8 milliseconds; -1 disables backoff.
		MinRetryBackoff: 0,
		// Maximum backoff between each retry. Default is 512 milliseconds; -1 disables backoff.
		MaxRetryBackoff: 0,

		// Hook that is called when new connection is established
		// OnConnect func(*Conn) error
	}), nil
}
68930
func (c *OauthClient) RESTClient() rest.Interface {
	if c == nil {
		return nil
	}
	return c.restClient
}
936886
func NewCluster(options *Options) (*Cluster, error) {
    cluster := &Cluster{
	nodes: make(map[string]*redisNode),
	connTimeout: options.ConnTimeout,
	readTimeout: options.ReadTimeout,
	writeTimeout: options.WriteTimeout,
	keepAlive: options.KeepAlive,
	aliveTime: options.AliveTime,
	updateList: make(chan updateMesg),
    }

    for i := range options.StartNodes {
	node := &redisNode{
	    address: options.StartNodes[i],
	    connTimeout: options.ConnTimeout,
	    readTimeout: options.ReadTimeout,
	    writeTimeout: options.WriteTimeout,
	    keepAlive: options.KeepAlive,
	    aliveTime: options.AliveTime,
	}

	err := cluster.update(node)
	if err != nil {
	    continue
	} else {
	    go cluster.handleUpdate()
	    return cluster, nil
	}
    }

    return nil, fmt.Errorf("NewCluster: no valid node in %v", options.StartNodes)
}
16355
func NewClient(host, version, userAgent string) (*Client, error) {
	baseURL, err := url.Parse(host)
	if err != nil {
		return nil, err
	}
	if baseURL.Path == "" {
		baseURL.Path = "/"
	}
	unix2HTTP(baseURL)
	hClient := getHTTPClient(host)
	if hClient == nil {
		return nil, fmt.Errorf("Unable to parse provided url: %v", host)
	}
	c := &Client{
		base:        baseURL,
		version:     version,
		httpClient:  hClient,
		authstring:  "",
		accesstoken: "",
		userAgent:   fmt.Sprintf("%v/%v", userAgent, version),
	}
	return c, nil
}
1082592
func NewClient(config *oauth2.Config) *Client {
	return &Client{
		Config:  config,
		backoff: backoff,
	}
}