// InitClient aims to support multi endpoints
426237
func InitClient(storeName string, storeURLs []string) (API, error) {
	plugin := GetPlugin(storeName)
	if plugin == nil {
		log.Errorf("Invalid DB type %s", storeName)
		return nil, errors.New("unsupported DB type")
	}
	cl, err := plugin.NewClient(storeURLs)
	if err != nil {
		log.Errorf("Error creating client %s to url %v. Err: %v", storeName, storeURLs, err)
		return nil, err
	}
	return cl, nil
}
1194633
func NewClient(config *Config) *Client {
	client := &Client{}

	if config.BaseUrl != "" {
		client.BaseUrl, _ = url.Parse(config.BaseUrl)
	} else {
		client.BaseUrl, _ = url.Parse(defaultBaseURL)
	}

	if config.HttpClient != nil {
		client.client = config.HttpClient
	} else if config.AccessToken != "" {
		client.client = oauth2.NewClient(
			oauth2.NoContext,
			oauth2.StaticTokenSource(
				&oauth2.Token{
					AccessToken: config.AccessToken,
				},
			),
		)
	}

	if &config.UserAgent != nil {
		client.UserAgent = config.UserAgent
	} else {
		client.UserAgent = userAgent
	}

	client.Sites = &SitesService{client: client}
	client.Deploys = &DeploysService{client: client}

	return client
}
1096974
func NewClient(caller base.APICaller) *Client {
	facadeCaller := base.NewFacadeCaller(caller, instanceMutaterFacade)
	return NewClientFromFacade(facadeCaller)
}
1190988
func init() {
	ps := endpoints.ProdService{}

	r := router.New()

	// Setup Cloud Endpoints.
	svr := prpc.Server{
		UnaryServerInterceptor: grpcmon.NewUnaryServerInterceptor(nil),
	}
	servicesPb.RegisterServicesServer(&svr, services.New())
	registrationPb.RegisterRegistrationServer(&svr, registration.New())

	// Standard HTTP endpoints.
	base := standard.Base().Extend(ps.Base)
	svr.InstallHandlers(r, base)
	standard.InstallHandlers(r)

	http.Handle("/", r)
}
880243
func NewClient(endpoint *transport.Endpoint) (transport.Transport, error) {
	f, ok := Protocols[endpoint.Protocol]
	if !ok {
		return nil, fmt.Errorf("unsupported scheme %q", endpoint.Protocol)
	}

	if f == nil {
		return nil, fmt.Errorf("malformed client for scheme %q, client is defined as nil", endpoint.Protocol)
	}

	return f, nil
}
899532
func SetClient(client httptransport.HTTPClient) ClientOption {
	return func(c *Client) { c.client = client }
}
580736
func InitClient(lang string) (client *osdb.Client, err error) {
	if client, err = osdb.NewClient(); err != nil {
		return
	}
	if err = client.LogIn(os.Getenv("OSDB_LOGIN"), os.Getenv("OSDB_PASSWORD"), lang); err != nil {
		return
	}
	return
}
118491
func NewClient(c HTTPClient) *Client {
	return &Client{
		Provider: &xmlContentProvider{
			client: &countingHTTPApiClient{
				client:       c,
				requestCount: 0,
			},
		},
	}
}
887613
func NewClient(h string, p int) Client {
	return Client{
		Host: h,
		Port: p,
	}
}
580173
func NewClient(endpoint string) (*Client, error) {
	u, err := parseEndpoint(endpoint)
	if err != nil {
		return nil, err
	}

	return &Client{
		HTTPClient:  &http.Client{Timeout: time.Duration(5 * time.Second)},
		endpoint:    endpoint,
		endpointURL: u,
	}, nil
}
1138246
func InitKeyClient(keysUrl string) (*LocalKeyClient, error) {
	aliveCh := make(chan struct{})
	localKeyClient, err := keys.NewRemoteKeyClient(keysUrl, logging.NewNoopLogger())
	if err != nil {
		return nil, err
	}

	err = localKeyClient.HealthCheck()

	go func() {
		for err != nil {
			err = localKeyClient.HealthCheck()
		}
		aliveCh <- struct{}{}
	}()
	select {
	case <-time.After(keysTimeout):
		return nil, fmt.Errorf("keys instance did not become responsive after %s: %v", keysTimeout, err)
	case <-aliveCh:
		return &LocalKeyClient{localKeyClient}, nil
	}
}
1335363
func (c *Client) init() error {
	c.HTTPClient = cleanhttp.DefaultClient()
	tlsConfig := &tls.Config{}
	if os.Getenv(atlasTLSNoVerifyEnvVar) != "" {
		tlsConfig.InsecureSkipVerify = true
	}
	err := rootcerts.ConfigureTLS(tlsConfig, &rootcerts.Config{
		CAFile: os.Getenv(atlasCAFileEnvVar),
		CAPath: os.Getenv(atlasCAPathEnvVar),
	})
	if err != nil {
		return err
	}
	t := cleanhttp.DefaultTransport()
	t.TLSClientConfig = tlsConfig
	c.HTTPClient.Transport = t
	return nil
}
73824
func NewClient(config ClientConfig) (Client, error) {
	if config.Connection == nil {
		return nil, WithStack(InvalidArgumentError{Message: "Connection is not set"})
	}
	conn := config.Connection
	if config.Authentication != nil {
		var err error
		conn, err = conn.SetAuthentication(config.Authentication)
		if err != nil {
			return nil, WithStack(err)
		}
	}
	c := &client{
		conn: conn,
	}
	if config.SynchronizeEndpointsInterval > 0 {
		go c.autoSynchronizeEndpoints(config.SynchronizeEndpointsInterval)
	}
	return c, nil
}
832522
func NewClient() (*Client, error) {
	var u *url.URL
	var err error

	if os.Getenv("VCLOUDAIR_ENDPOINT") != "" {
		u, err = url.ParseRequestURI(os.Getenv("VCLOUDAIR_ENDPOINT"))
		if err != nil {
			return nil, fmt.Errorf("cannot parse endpoint coming from VCLOUDAIR_ENDPOINT")
		}
	} else {
		// Implicitly trust this URL parse.
		u, _ = url.ParseRequestURI("https://vca.vmware.com/api")
	}
	return &Client{
		VAEndpoint:    *u,
		Region:        os.Getenv("VCLOUDAIR_REGION"),
		VCDAuthHeader: "X-Vcloud-Authorization",
		http:          http.Client{Transport: &http.Transport{TLSHandshakeTimeout: 120 * time.Second}},
	}, nil
}
141755
func (ep *etcdPlugin) NewClient(endpoints []string) (API, error) {
	var err error
	var ec = new(EtcdClient)

	ep.mutex.Lock()
	defer ep.mutex.Unlock()

	// Setup default url
	if len(endpoints) == 0 {
		endpoints = []string{"http://127.0.0.1:2379"}
	}

	etcdConfig := client.Config{
		Endpoints: endpoints,
	}

	// Create a new client
	ec.client, err = client.New(etcdConfig)
	if err != nil {
		log.Fatalf("Error creating etcd client. Err: %v", err)
		return nil, err
	}

	// create keys api
	ec.kapi = client.NewKeysAPI(ec.client)

	// Initialize service DB
	ec.serviceDb = make(map[string]*etcdServiceState)

	// Make sure we can read from etcd
	_, err = ec.kapi.Get(context.Background(), "/", &client.GetOptions{Recursive: true, Sort: true})
	if err != nil {
		log.Errorf("Failed to connect to etcd. Err: %v", err)
		return nil, err
	}

	return ec, nil
}
856307
func newClient(c clientConfig) (client, error) {
	if c.app.tokenURL == "" {
		c.app.tokenURL = tokenURL
	}

	if c.app.unauthenticated() {
		return &baseClient{clientWithAgent(c.agent)}, nil
	}

	if err := c.app.validateAuth(); err != nil {
		return nil, err
	}

	return newAppClient(c)
}
410358
func NewClient() *Client {
	c := new(Client)
	c.SetSoftwareName(DefaultSoftwareName)
	c.logger = NewLogger()
	return c
}