// NewClientWithConfig instantiates a new client able to interact with the
// Algolia Analytics API.
181998
func NewClientWithConfig(config Configuration) *Client {
	var hosts []*transport.StatefulHost

	if config.Hosts == nil {
		hosts = defaultHosts(config.Region)
	} else {
		for _, h := range config.Hosts {
			hosts = append(hosts, transport.NewStatefulHost(h, call.IsReadWrite))
		}
	}

	searchConfig := search.Configuration{
		AppID:          config.AppID,
		APIKey:         config.APIKey,
		Requester:      config.Requester,
		ReadTimeout:    config.ReadTimeout,
		WriteTimeout:   config.WriteTimeout,
		Headers:        config.Headers,
		ExtraUserAgent: config.ExtraUserAgent,
	}

	return &Client{
		appID:        config.AppID,
		searchClient: search.NewClientWithConfig(searchConfig),
		transport: transport.New(
			hosts,
			config.Requester,
			config.AppID,
			config.APIKey,
			config.ReadTimeout,
			config.WriteTimeout,
			config.Headers,
			config.ExtraUserAgent,
		),
	}
}
886354
func NewClient(auth Auth) *Client {
	return &Client{auth: auth, client: http.DefaultClient}
}
1023677
func NewNonInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides, configAccess ConfigAccess) ClientConfig {
	return &DirectClientConfig{config, contextName, overrides, nil, configAccess, promptedCredentials{}}
}
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
}
1345598
func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
	if clientID == "" || secret == "" || APIBase == "" {
		return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
	}

	return &Client{
		Client:   &http.Client{},
		ClientID: clientID,
		Secret:   secret,
		APIBase:  APIBase,
	}, nil
}
476592
func NewClientFromConfig(cfg *config.Config) (*Client, error) {
	options, err := configToOptions(cfg)
	if err != nil {
		return nil, err
	}
	return DialContext(context.Background(), options...)
}
157889
func NewClientWithHTTPClient(key string, secret string, region *Region, client *http.Client) *Client {
	return &Client{
		keys:          &aws4.Keys{AccessKey: key, SecretKey: secret},
		httpClient:    client,
		pollingClient: client,
		Region:        region,
	}
}
994032
func NewClient(options ClientOptions) (client *Client, err error) {
	if !options.Environment.Valid() {
		return nil, errors.New("Invalid environment specified: " + string(options.Environment))
	}

	if options.HTTPClient == nil {
		options.HTTPClient = &http.Client{}
	}

	return &Client{
		clientID:    options.ClientID,
		secret:      options.Secret,
		publicKey:   options.PublicKey,
		environment: options.Environment,
		httpClient:  options.HTTPClient,
	}, nil
}
47100
func NewClient(rw io.ReadWriter, config ClientConfig) *Client {
	c := &Client{
		Conn:    NewConn(rw),
		config:  config,
		errChan: make(chan error, 1),
		caps:    make(map[string]cap),
	}

	// Replace the writer writeCallback with one of our own
	c.Conn.Writer.writeCallback = c.writeCallback

	return c
}
1062598
func NewClient(addr string, tlsConfig *tlsconfig.Options) (*Client, error) {
	clientTransport, err := newTransport(addr, tlsConfig)
	if err != nil {
		return nil, err
	}
	return newClientWithTransport(clientTransport, 0), nil
}
569154
func NewClient(cfg *Config) (*Client, error) {
	pk, err := PrivateKeyFromString([]byte(cfg.Key))
	if err != nil {
		return nil, err
	}

	baseUrl, _ := url.Parse(cfg.BaseURL)

	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
		TLSClientConfig:     &tls.Config{InsecureSkipVerify: cfg.SkipSSL},
		TLSHandshakeTimeout: 10 * time.Second,
	}

	c := &Client{
		Auth: &AuthConfig{
			PrivateKey: pk,
			ClientName: cfg.Name,
		},
		client: &http.Client{
			Transport: tr,
			Timeout:   cfg.Timeout * time.Second,
		},
		BaseURL: baseUrl,
	}
	c.ACLs = &ACLService{client: c}
	c.Clients = &ApiClientService{client: c}
	c.Cookbooks = &CookbookService{client: c}
	c.DataBags = &DataBagService{client: c}
	c.Environments = &EnvironmentService{client: c}
	c.Nodes = &NodeService{client: c}
	c.Principals = &PrincipalService{client: c}
	c.Roles = &RoleService{client: c}
	c.Sandboxes = &SandboxService{client: c}
	c.Search = &SearchService{client: c}
	return c, nil
}
192485
func NewClient(config *Config) (*Client, error) {
	// bootstrap the config
	defConfig := DefaultConfig()

	if len(config.BOSHAddress) == 0 {
		config.BOSHAddress = defConfig.BOSHAddress
	}

	if len(config.Username) == 0 {
		config.Username = defConfig.Username
	}

	if len(config.Password) == 0 {
		config.Password = defConfig.Password
	}

	//Save the configured HTTP Client timeout for later
	var timeout time.Duration
	if config.HttpClient != nil {
		timeout = config.HttpClient.Timeout
	}

	endpoint := &Endpoint{}
	config.HttpClient = &http.Client{
		Timeout: timeout,
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: config.SkipSslValidation,
			},
		},
	}

	authType, err := getAuthType(config.BOSHAddress, config.HttpClient)
	if err != nil {
		return nil, fmt.Errorf("Could not get auth type: %v", err)
	}
	if authType != "uaa" {
		config.HttpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
			if len(via) > 10 {
				return fmt.Errorf("stopped after 10 redirects")
			}
			req.URL.Host = strings.TrimPrefix(config.BOSHAddress, req.URL.Scheme+"://")
			req.SetBasicAuth(config.Username, config.Password)
			req.Header.Add("User-Agent", "gogo-bosh")
			req.Header.Del("Referer")
			return nil
		}
	} else {
		ctx := getContext(*config)

		endpoint, err := getUAAEndpoint(config.BOSHAddress, oauth2.NewClient(ctx, nil))

		if err != nil {
			return nil, fmt.Errorf("Could not get api /info: %v", err)
		}

		config.Endpoint = endpoint

		if config.ClientID == "" { //No ClientID? Do UAA User auth
			authConfig, token, err := getToken(ctx, *config)

			if err != nil {
				return nil, fmt.Errorf("Error getting token: %v", err)
			}

			config.TokenSource = authConfig.TokenSource(ctx, token)
			config.HttpClient = oauth2.NewClient(ctx, config.TokenSource)
		} else { //Got a ClientID? Do UAA Client Auth (two-legged auth)
			authConfig := &clientcredentials.Config{
				ClientID:     config.ClientID,
				ClientSecret: config.ClientSecret,
				TokenURL:     endpoint.URL + "/oauth/token",
			}
			config.TokenSource = authConfig.TokenSource(ctx)
			config.HttpClient = authConfig.Client(ctx)
		}

		config.HttpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
			if len(via) > 10 {
				return fmt.Errorf("stopped after 10 redirects")
			}
			req.URL.Host = strings.TrimPrefix(config.BOSHAddress, req.URL.Scheme+"://")
			req.Header.Add("User-Agent", "gogo-bosh")
			req.Header.Del("Referer")
			return nil
		}
	}

	//Restore the timeout from the provided HTTP Client
	config.HttpClient.Timeout = timeout

	client := &Client{
		config:   *config,
		Endpoint: *endpoint,
	}

	return client, nil
}
78476
func (p *provider) NewConfig() (*osincli.ClientConfig, error) {
	scopes := []string{githubOAuthScope}
	// if we're limiting to specific organizations or teams, we also need to read their org membership
	if len(p.allowedOrganizations) > 0 || len(p.allowedTeams) > 0 {
		scopes = append(scopes, githubOrgScope)
	}

	config := &osincli.ClientConfig{
		ClientId:                 p.clientID,
		ClientSecret:             p.clientSecret,
		ErrorsInStatusCode:       true,
		SendClientSecretInParams: true,
		AuthorizeUrl:             p.githubAuthorizeURL,
		TokenUrl:                 p.githubTokenURL,
		Scope:                    strings.Join(scopes, " "),
	}
	return config, nil
}
1236701
func new_client(configPath *C.char) C.result {
	clientsRWL.Lock()
	defer clientsRWL.Unlock()

	result := C.result{}

	client_id, err := newClientID()
	if err != nil {
		result.err = C.CString(err.Error())
		return result
	}

	c, err := newWithConfig(C.GoString(configPath))
	if err != nil {
		result.err = C.CString(err.Error())
		return result
	}

	clients[*client_id] = c
	result.val = unsafe.Pointer(client_id)
	return result
}
707031
func NewClientWithConfig(config Configuration) *Client {
	var (
		hosts        []*transport.StatefulHost
		maxBatchSize int
	)

	if len(config.Hosts) == 0 {
		hosts = defaultHosts(config.AppID)
	} else {
		for _, h := range config.Hosts {
			hosts = append(hosts, transport.NewStatefulHost(h, call.IsReadWrite))
		}
	}

	if config.MaxBatchSize == 0 {
		maxBatchSize = DefaultMaxBatchSize
	} else {
		maxBatchSize = config.MaxBatchSize
	}

	return &Client{
		appID:        config.AppID,
		maxBatchSize: maxBatchSize,
		transport: transport.New(
			hosts,
			config.Requester,
			config.AppID,
			config.APIKey,
			config.ReadTimeout,
			config.WriteTimeout,
			config.Headers,
			config.ExtraUserAgent,
		),
	}
}
1169076
func NewClient(httpClient *http.Client, endpoint, apiVersion string, tlsConfig *tls.Config) (*Client, error) {
	if endpoint == "" {
		return nil, errors.New("endpoint missing for httpClient configuration")
	}
	if apiVersion == "" {
		apiVersion = DefaultAPIVersion
	}

	if tlsConfig != nil {
		tlsConfig.Renegotiation = tls.RenegotiateFreelyAsClient
		tlsConfig.BuildNameToCertificate()
		httpClient.Transport = &http.Transport{TLSClientConfig: tlsConfig}
	}

	return &Client{
		endpoint:   endpoint,
		apiVersion: apiVersion,
		httpClient: httpClient,
	}, nil
}
228276
func NewClient(config Config) *Client {
	userAgent := fmt.Sprintf("%s/%s (%s; %s %s)",
		config.AppName,
		config.AppVersion,
		runtime.Version(),
		runtime.GOARCH,
		runtime.GOOS,
	)

	client := Client{
		userAgent:  userAgent,
		router:     rata.NewRequestGenerator(config.RoutingEndpoint, internal.APIRoutes),
		connection: NewConnection(config.ConnectionConfig),
	}

	for _, wrapper := range config.Wrappers {
		client.connection = wrapper.Wrap(client.connection)
	}

	return &client
}