// New creates a new SDK server
516484
func New(config *ServerConfig) (*Server, error) {

	if config == nil {
		return nil, fmt.Errorf("Must provide configuration")
	}

	// If no security set, initialize the object as empty
	if config.Security == nil {
		config.Security = &SecurityConfig{}
	}

	// Check if the socket is provided to enable the REST gateway to communicate
	// to the unix domain socket
	if len(config.Socket) == 0 {
		return nil, fmt.Errorf("Must provide unix domain socket for SDK")
	}
	if len(config.RestPort) == 0 {
		return nil, fmt.Errorf("Must provide REST Gateway port for the SDK")
	}

	// Set default log locations
	var (
		accessLog, auditLog *os.File
		err                 error
	)
	if config.AuditOutput == nil {
		auditLog, err = openLog(defaultAuditLog)
		if err != nil {
			return nil, err
		}
		config.AuditOutput = auditLog
	}
	if config.AccessOutput == nil {
		accessLog, err := openLog(defaultAccessLog)
		if err != nil {
			return nil, err
		}
		config.AccessOutput = accessLog
	}

	// Create a gRPC server on the network
	netServer, err := newSdkGrpcServer(config)
	if err != nil {
		return nil, err
	}

	// Create a gRPC server on a unix domain socket
	udsConfig := *config
	udsConfig.Net = "unix"
	udsConfig.Address = config.Socket
	udsServer, err := newSdkGrpcServer(&udsConfig)
	if err != nil {
		return nil, err
	}

	// Create REST Gateway and connect it to the unix domain socket server
	restGateway, err := newSdkRestGateway(config, udsServer)
	if err != nil {
		return nil, err
	}

	return &Server{
		config:      *config,
		netServer:   netServer,
		udsServer:   udsServer,
		restGateway: restGateway,
		auditLog:    auditLog,
		accessLog:   accessLog,
	}, nil
}
1114464
func New(c *Options) (s *Server) {
	c.ensure()
	s = &Server{
		cfg:    c,
		Logger: log.Get(PkgName),
		Binder: new(binder),
		router: router.New(router.Options{}),
		routes: make(map[string]router.Route),
	}
	s.stdLogger = slog.New(s.Logger, "web > ", 0)
	s.ctxPool = newContextPool(s)
	return s
}
873019
func New(token string, url string) *API {
	api := new(API)
	api.Endpoint = url
	api.Client = newRestClient(token)
	return api
}
331604
func New(host, authtoken string) (*TCP, error) {
	client := &TCP{
		host:     host,
		messages: make(chan mist.Message),
		token:    authtoken,
	}

	return client, client.connect()
}
388700
func New(crioSocketPath string) (CrioClient, error) {
	tr := new(http.Transport)
	configureUnixTransport(tr, "unix", crioSocketPath)
	c := &http.Client{
		Transport: tr,
	}
	return &crioClientImpl{
		client:         c,
		crioSocketPath: crioSocketPath,
	}, nil
}
18115
func New(config *Config) (*Kubernetes, error) {
	var err error

	if config == nil {
		config = &Config{}
	}

	if config.ClusterConfig == nil {
		config.ClusterConfig, err = rest.InClusterConfig()
	}

	if err != nil {
		return nil, err
	}

	clientset, err := kubernetes.NewForConfig(config.ClusterConfig)
	if err != nil {
		return nil, err
	}

	return &Kubernetes{Clientset: clientset, Config: config}, nil
}
358074
func New(serverURL, userID string) (*Client, error) {
	if userID == "" {
		return nil, errors.New("omaha: empty user identifier")
	}

	c := &Client{
		apiClient:     newHTTPClient(),
		clientVersion: defaultClientVersion,
		userID:        userID,
		sessionID:     uuid.NewV4().String(),
		apps:          make(map[string]*AppClient),
	}

	if err := c.SetServerURL(serverURL); err != nil {
		return nil, err
	}

	return c, nil
}
537422
func New(c ServerConfig) (*Server, error) {
	// Check and make sure we everything we need to build a forwarding node.
	err := c.CheckDefaults()
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// Build a pipe connection to hook up the client and the server. we save both
	// here and will pass them along to the context when we create it so they
	// can be closed by the context.
	serverConn, clientConn := utils.DualPipeNetConn(c.SrcAddr, c.DstAddr)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	s := &Server{
		log: logrus.WithFields(logrus.Fields{
			trace.Component: teleport.ComponentForwardingNode,
			trace.ComponentFields: map[string]string{
				"src-addr": c.SrcAddr.String(),
				"dst-addr": c.DstAddr.String(),
			},
		}),
		id:              uuid.New(),
		targetConn:      c.TargetConn,
		serverConn:      utils.NewTrackingConn(serverConn),
		clientConn:      clientConn,
		userAgent:       c.UserAgent,
		hostCertificate: c.HostCertificate,
		authClient:      c.AuthClient,
		auditLog:        c.AuthClient,
		authService:     c.AuthClient,
		sessionServer:   c.AuthClient,
		dataDir:         c.DataDir,
		clock:           c.Clock,
	}

	// Set the ciphers, KEX, and MACs that the in-memory server will send to the
	// client in its SSH_MSG_KEXINIT.
	s.ciphers = c.Ciphers
	s.kexAlgorithms = c.KEXAlgorithms
	s.macAlgorithms = c.MACAlgorithms

	s.sessionRegistry, err = srv.NewSessionRegistry(s)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// Common auth handlers.
	s.authHandlers = &srv.AuthHandlers{
		Entry: logrus.WithFields(logrus.Fields{
			trace.Component:       teleport.ComponentForwardingNode,
			trace.ComponentFields: logrus.Fields{},
		}),
		Server:      s,
		Component:   teleport.ComponentForwardingNode,
		AuditLog:    c.AuthClient,
		AccessPoint: c.AuthClient,
	}

	// Common term handlers.
	s.termHandlers = &srv.TermHandlers{
		SessionRegistry: s.sessionRegistry,
	}

	// Create a close context that is used internally to signal when the server
	// is closing and for any blocking goroutines to unblock.
	s.closeContext, s.closeCancel = context.WithCancel(context.Background())

	return s, nil
}
772295
func New(token, environment, codeVersion, serverHost, serverRoot string) *Handler {
	return NewFromClient(rollbar.New(token, environment, codeVersion, serverHost, serverRoot))
}
1082538
func New(scheme, host string, port uint16) (*Client, error) {
	client := &Client{
		Scheme: scheme,
		Host:   host,
		Port:   port,
	}

	return client, nil
}
1342901
func New(e *empire.Empire) *Server {
	r := &Server{
		Empire: e,
		mux:    mux.NewRouter(),
	}

	// Apps
	r.handle("GET", "/apps", r.GetApps)                  // hk apps
	r.handle("GET", "/apps/{app}", r.GetAppInfo)         // hk info
	r.handle("DELETE", "/apps/{app}", r.DeleteApp)       // hk destroy
	r.handle("PATCH", "/apps/{app}", r.PatchApp)         // hk destroy
	r.handle("POST", "/apps/{app}/deploys", r.DeployApp) // Deploy an image to an app
	r.handle("POST", "/apps", r.PostApps)                // hk create
	r.handle("POST", "/organizations/apps", r.PostApps)  // hk create

	// Domains
	r.handle("GET", "/apps/{app}/domains", r.GetDomains)                 // hk domains
	r.handle("POST", "/apps/{app}/domains", r.PostDomains)               // hk domain-add
	r.handle("DELETE", "/apps/{app}/domains/{hostname}", r.DeleteDomain) // hk domain-remove

	// Deploys
	r.handle("POST", "/deploys", r.PostDeploys) // Deploy an app

	// Releases
	r.handle("GET", "/apps/{app}/releases", r.GetReleases)          // hk releases
	r.handle("GET", "/apps/{app}/releases/{version}", r.GetRelease) // hk release-info
	r.handle("POST", "/apps/{app}/releases", r.PostReleases)        // hk rollback

	// Configs
	r.handle("GET", "/apps/{app}/config-vars", r.GetConfigs)                    // hk env, hk get
	r.handle("GET", "/apps/{app}/config-vars/{version}", r.GetConfigsByRelease) // hk env v1, hk get v1
	r.handle("PATCH", "/apps/{app}/config-vars", r.PatchConfigs)                // hk set, hk unset

	// Processes
	r.handle("GET", "/apps/{app}/dynos", r.GetProcesses)                     // hk dynos
	r.handle("POST", "/apps/{app}/dynos", r.PostProcess)                     // hk run
	r.handle("DELETE", "/apps/{app}/dynos", r.DeleteProcesses)               // hk restart
	r.handle("DELETE", "/apps/{app}/dynos/{ptype}.{pid}", r.DeleteProcesses) // hk restart web.1
	r.handle("DELETE", "/apps/{app}/dynos/{pid}", r.DeleteProcesses)         // hk restart web

	// Formations
	r.handle("GET", "/apps/{app}/formation", r.GetFormation)     // hk scale -l
	r.handle("PATCH", "/apps/{app}/formation", r.PatchFormation) // hk scale

	// OAuth
	r.handle("POST", "/oauth/authorizations", r.PostAuthorizations).
		// Authentication for this endpoint is handled directly in the
		// handler.
		AuthWith(auth.StrategyUsernamePassword)

	// Certs
	r.handle("POST", "/apps/{app}/certs", r.PostCerts)

	// SSL
	sslRemoved := errHandler(ErrSSLRemoved)
	r.handle("GET", "/apps/{app}/ssl-endpoints", sslRemoved)           // hk ssl
	r.handle("POST", "/apps/{app}/ssl-endpoints", sslRemoved)          // hk ssl-cert-add
	r.handle("PATCH", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved)  // hk ssl-cert-add, hk ssl-cert-rollback
	r.handle("DELETE", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved) // hk ssl-destroy

	// Logs
	r.handle("POST", "/apps/{app}/log-sessions", r.PostLogs) // hk log

	return r
}
831823
func New(endpoints []string, ca, cert, key string) (*Client, error) {
	client := Client{Endpoints: endpoints}

	if ca != "" || cert != "" || key != "" {
		tlsInfo := transport.TLSInfo{
			CertFile:      cert,
			KeyFile:       key,
			TrustedCAFile: ca,
		}
		tlsConfig, err := tlsInfo.ClientConfig()
		if err != nil {
			return nil, err
		}
		client.TLS = tlsConfig
	}

	return &client, nil
}
72070
func New(conf *config.AppConfig) *server {

	if conf.Insecure {
		acl.SetSkipAuth()
	}

	// create new storage handler
	if err := storage.New(conf.Storage); err != nil {
		log.Fatalf("Could not create storage handler => %s", err.Error())
	}

	// create new locker handler
	if err := locker.New(conf.Locker); err != nil {
		log.Fatalf("Could not create locker handler => %s", err.Error())
	}

	// load ca clients
	client.New(conf.Clients)
	providers.New(conf.Payment)

	lis, err := net.Listen("tcp", conf.Address)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	log.Infof("Listening on %s", conf.Address)
	return &server{
		listener:   lis,
		grpcServer: newGRPCServer(conf),
	}
}
1057033
func New(host, port, username string, sams ...ssh.AuthMethod) (*Client, error) {
	config := &ssh.ClientConfig{
		User: username,
		Auth: sams,
	}
	client, err := ssh.Dial("tcp", BuildSSHURL(host, port), config)
	if err != nil {
		return nil, err
	}
	tmpSftpClient, err := sftp.NewClient(client)
	if err != nil {
		return nil, err
	}
	return (*Client)(unsafe.Pointer(tmpSftpClient)), err
}
229833
func New(addr string) *Client {
	return &Client{Address: addr, Client: &http.Client{}}
}
742978
func New(config *Config) (*Service, error) {
	holster.SetDefault(&config.Clock, &holster.SystemClock{})
	holster.SetDefault(&config.Random, &random.CSPRNG{})

	return NewWithProviders(
		config,
		config.Clock,
		config.Random,
	)
}
491856
func New(serviceNames ...string) (DiscoveryServer, error) {
	desc, err := combineDescriptors(serviceNames)
	if err != nil {
		return nil, err
	}
	desc = proto.Clone(desc).(*descriptor.FileDescriptorSet)

	cpy := make([]string, len(serviceNames))
	copy(cpy, serviceNames)
	return &service{cpy, desc}, nil
}