// New returns a new policy enforcer that implements both the data paths.
506772
func New(
	mutualAuthorization bool,
	fqConfig *fqconfig.FilterQueue,
	collector collector.EventCollector,
	service packetprocessor.PacketProcessor,
	secrets secrets.Secrets,
	serverID string,
	validity time.Duration,
	mode constants.ModeType,
	procMountPoint string,
	externalIPCacheTimeout time.Duration,
	packetLogs bool,
	cfg *runtime.Configuration,
) (Enforcer, error) {

	tokenAccessor, err := tokenaccessor.New(serverID, validity, secrets)
	if err != nil {
		zap.L().Fatal("Cannot create a token engine")
	}

	puFromContextID := cache.NewCache("puFromContextID")

	transport := nfqdatapath.New(
		mutualAuthorization,
		fqConfig,
		collector,
		serverID,
		validity,
		service,
		secrets,
		mode,
		procMountPoint,
		externalIPCacheTimeout,
		packetLogs,
		tokenAccessor,
		puFromContextID,
		cfg,
	)

	tcpProxy, err := applicationproxy.NewAppProxy(tokenAccessor, collector, puFromContextID, nil, secrets)
	if err != nil {
		return nil, err
	}

	return &enforcer{
		proxy:     tcpProxy,
		transport: transport,
		secrets:   secretsproxy.NewSecretsProxy(),
	}, nil
}
544061
func New(conn *grpc.ClientConn, tracer stdopentracing.Tracer, logger log.Logger, opts ...Option) Service {
	clientOpts := &options{
		limiterRate:     100,
		limiterCapacity: 100,
	}
	for _, opt := range opts {
		opt(clientOpts)
	}
	limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(clientOpts.limiterRate, clientOpts.limiterCapacity))
	circuitbreaker := circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{Name: "SessionManagement"}))
	var createSessionEndpoint endpoint.Endpoint
	{
		createSessionEndpoint = grpctransport.NewClient(
			conn,
			"SessionManagement",
			"CreateSession",
			noop,
			noop,
			pb.CreateSessionReply{},
			grpctransport.ClientBefore(kitty.ToGRPCRequest(tracer, logger)),
		).Endpoint()
		createSessionEndpoint = opentracing.TraceClient(tracer, "Create session")(createSessionEndpoint)
		createSessionEndpoint = kitty.EndpointTracingMiddleware(createSessionEndpoint)
		createSessionEndpoint = limiter(createSessionEndpoint)
		createSessionEndpoint = circuitbreaker(createSessionEndpoint)
	}
	var findSessionByTokenEndpoint endpoint.Endpoint
	{
		findSessionByTokenEndpoint = grpctransport.NewClient(
			conn,
			"SessionManagement",
			"FindSessionByToken",
			noop,
			noop,
			pb.FindSessionByTokenReply{},
			grpctransport.ClientBefore(kitty.ToGRPCRequest(tracer, logger)),
		).Endpoint()
		findSessionByTokenEndpoint = opentracing.TraceClient(tracer, "Find session by token")(findSessionByTokenEndpoint)
		findSessionByTokenEndpoint = kitty.EndpointTracingMiddleware(findSessionByTokenEndpoint)
		findSessionByTokenEndpoint = limiter(findSessionByTokenEndpoint)
		findSessionByTokenEndpoint = circuitbreaker(findSessionByTokenEndpoint)
	}
	var deleteSessionByTokenEndpoint endpoint.Endpoint
	{
		deleteSessionByTokenEndpoint = grpctransport.NewClient(
			conn,
			"SessionManagement",
			"DeleteSessionByToken",
			noop,
			noop,
			pb.DeleteSessionByTokenReply{},
			grpctransport.ClientBefore(kitty.ToGRPCRequest(tracer, logger)),
		).Endpoint()
		deleteSessionByTokenEndpoint = opentracing.TraceClient(tracer, "Delete session by token")(deleteSessionByTokenEndpoint)
		deleteSessionByTokenEndpoint = kitty.EndpointTracingMiddleware(deleteSessionByTokenEndpoint)
		deleteSessionByTokenEndpoint = limiter(deleteSessionByTokenEndpoint)
		deleteSessionByTokenEndpoint = circuitbreaker(deleteSessionByTokenEndpoint)
	}
	var deleteSessionsByOwnerTokenEndpoint endpoint.Endpoint
	{
		deleteSessionsByOwnerTokenEndpoint = grpctransport.NewClient(
			conn,
			"SessionManagement",
			"DeleteSessionsByOwnerToken",
			noop,
			noop,
			pb.DeleteSessionsByOwnerTokenReply{},
			grpctransport.ClientBefore(kitty.ToGRPCRequest(tracer, logger)),
		).Endpoint()
		deleteSessionsByOwnerTokenEndpoint = opentracing.TraceClient(tracer, "Delete sessions by owner token")(deleteSessionsByOwnerTokenEndpoint)
		deleteSessionsByOwnerTokenEndpoint = kitty.EndpointTracingMiddleware(deleteSessionsByOwnerTokenEndpoint)
		deleteSessionsByOwnerTokenEndpoint = limiter(deleteSessionsByOwnerTokenEndpoint)
		deleteSessionsByOwnerTokenEndpoint = circuitbreaker(deleteSessionsByOwnerTokenEndpoint)
	}

	return Endpoints{
		CreateSessionEndpoint:              createSessionEndpoint,
		FindSessionByTokenEndpoint:         findSessionByTokenEndpoint,
		DeleteSessionByTokenEndpoint:       deleteSessionByTokenEndpoint,
		DeleteSessionsByOwnerTokenEndpoint: deleteSessionsByOwnerTokenEndpoint,
	}
}
209532
func New(store Store, rate *Rate) *Limiter {
	return &Limiter{
		Store: store,
		Rate:  rate,
	}
}
140630
func New(transport peer.Transport, opts ...newrr.ListOption) *newrr.List {
	return newrr.New(transport, opts...)
}
1078290
func New(dir string, fw ChoriaProvider) (aa *AAgent, err error) {
	notifier, err := notifier.New(fw)
	if err != nil {
		return nil, errors.Wrapf(err, "could not create notifier")
	}

	return &AAgent{
		fw:       fw,
		logger:   fw.Logger("aagent"),
		source:   dir,
		machines: []*managedMachine{},
		notifier: notifier,
	}, nil
}
374830
func New(req *csr.CertificateRequest) (cert, csrPEM, key []byte, err error) {
	policy := CAPolicy()
	if req.CA != nil {
		if req.CA.Expiry != "" {
			policy.Default.ExpiryString = req.CA.Expiry
			policy.Default.Expiry, err = time.ParseDuration(req.CA.Expiry)
			if err != nil {
				return
			}
		}

		if req.CA.Backdate != "" {
			policy.Default.Backdate, err = time.ParseDuration(req.CA.Backdate)
			if err != nil {
				return
			}
		}

		policy.Default.CAConstraint.MaxPathLen = req.CA.PathLength
		if req.CA.PathLength != 0 && req.CA.PathLenZero {
			log.Infof("ignore invalid 'pathlenzero' value")
		} else {
			policy.Default.CAConstraint.MaxPathLenZero = req.CA.PathLenZero
		}
	}

	g := &csr.Generator{Validator: validator}
	csrPEM, key, err = g.ProcessRequest(req)
	if err != nil {
		log.Errorf("failed to process request: %v", err)
		key = nil
		return
	}

	priv, err := helpers.ParsePrivateKeyPEM(key)
	if err != nil {
		log.Errorf("failed to parse private key: %v", err)
		return
	}

	s, err := local.NewSigner(priv, nil, signer.DefaultSigAlgo(priv), policy)
	if err != nil {
		log.Errorf("failed to create signer: %v", err)
		return
	}

	signReq := signer.SignRequest{Hosts: req.Hosts, Request: string(csrPEM)}
	cert, err = s.Sign(signReq)

	return

}
380558
func New(dataDir string) (*Migrator, error) {
	// Check that the directory exists
	if _, err := os.Stat(dataDir); err != nil {
		return nil, err
	}

	// Create the struct
	m := &Migrator{
		ProgressCh: make(chan *ProgressUpdate, 128),
		dataDir:    dataDir,

		raftPath:      filepath.Join(dataDir, raftDir),
		mdbPath:       filepath.Join(dataDir, raftDir, mdbDir),
		mdbBackupPath: filepath.Join(dataDir, raftDir, mdbBackupDir),
		boltPath:      filepath.Join(dataDir, raftDir, boltFile),
		boltTempPath:  filepath.Join(dataDir, raftDir, boltTempFile),
	}

	return m, nil
}
550812
func (api *SimpleMonitorAPI) New(target string) *sacloud.SimpleMonitor {
	return sacloud.CreateNewSimpleMonitor(target)
}
841001
func New(files Files) (vfs.FileSystem, error) {
	fs := make(MapFS)

	for path, file := range files {
		if err := fs.addFile(path, file); err != nil {
			return nil, err
		}
	}

	return fs, nil
}
25624
func (config Config) New() (authorizer.Authorizer, authorizer.RuleResolver, error) {
	if len(config.AuthorizationModes) == 0 {
		return nil, nil, fmt.Errorf("at least one authorization mode must be passed")
	}

	var (
		authorizers   []authorizer.Authorizer
		ruleResolvers []authorizer.RuleResolver
	)

	for _, authorizationMode := range config.AuthorizationModes {
		// Keep cases in sync with constant list in k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes/modes.go.
		switch authorizationMode {
		case modes.ModeNode:
			graph := node.NewGraph()
			node.AddGraphEventHandlers(
				graph,
				config.VersionedInformerFactory.Core().V1().Nodes(),
				config.VersionedInformerFactory.Core().V1().Pods(),
				config.VersionedInformerFactory.Core().V1().PersistentVolumes(),
				config.VersionedInformerFactory.Storage().V1().VolumeAttachments(),
			)
			nodeAuthorizer := node.NewAuthorizer(graph, nodeidentifier.NewDefaultNodeIdentifier(), bootstrappolicy.NodeRules())
			authorizers = append(authorizers, nodeAuthorizer)

		case modes.ModeAlwaysAllow:
			alwaysAllowAuthorizer := authorizerfactory.NewAlwaysAllowAuthorizer()
			authorizers = append(authorizers, alwaysAllowAuthorizer)
			ruleResolvers = append(ruleResolvers, alwaysAllowAuthorizer)
		case modes.ModeAlwaysDeny:
			alwaysDenyAuthorizer := authorizerfactory.NewAlwaysDenyAuthorizer()
			authorizers = append(authorizers, alwaysDenyAuthorizer)
			ruleResolvers = append(ruleResolvers, alwaysDenyAuthorizer)
		case modes.ModeABAC:
			abacAuthorizer, err := abac.NewFromFile(config.PolicyFile)
			if err != nil {
				return nil, nil, err
			}
			authorizers = append(authorizers, abacAuthorizer)
			ruleResolvers = append(ruleResolvers, abacAuthorizer)
		case modes.ModeWebhook:
			webhookAuthorizer, err := webhook.New(config.WebhookConfigFile,
				config.WebhookCacheAuthorizedTTL,
				config.WebhookCacheUnauthorizedTTL)
			if err != nil {
				return nil, nil, err
			}
			authorizers = append(authorizers, webhookAuthorizer)
			ruleResolvers = append(ruleResolvers, webhookAuthorizer)
		case modes.ModeRBAC:
			rbacAuthorizer := rbac.New(
				&rbac.RoleGetter{Lister: config.VersionedInformerFactory.Rbac().V1().Roles().Lister()},
				&rbac.RoleBindingLister{Lister: config.VersionedInformerFactory.Rbac().V1().RoleBindings().Lister()},
				&rbac.ClusterRoleGetter{Lister: config.VersionedInformerFactory.Rbac().V1().ClusterRoles().Lister()},
				&rbac.ClusterRoleBindingLister{Lister: config.VersionedInformerFactory.Rbac().V1().ClusterRoleBindings().Lister()},
			)
			authorizers = append(authorizers, rbacAuthorizer)
			ruleResolvers = append(ruleResolvers, rbacAuthorizer)
		default:
			return nil, nil, fmt.Errorf("unknown authorization mode %s specified", authorizationMode)
		}
	}

	return union.New(authorizers...), union.NewRuleResolvers(ruleResolvers...), nil
}
278165
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg plugingetter.PluginGetter) (*DrvRegistry, error) {
	r := &DrvRegistry{
		drivers:      make(driverTable),
		ipamDrivers:  make(ipamTable),
		dfn:          dfn,
		ifn:          ifn,
		pluginGetter: pg,
	}

	return r, nil
}
1264250
func New(driver Driver, migrations []Migration, infoChan chan MigrationInfo) Darwin {
	return Darwin{
		driver:     driver,
		migrations: migrations,
		infoChan:   infoChan,
	}
}
228735
func New(sccp sysccprovider.SystemChaincodeProvider, ACLProvider aclmgmt.ACLProvider, platformRegistry *platforms.Registry) *LifeCycleSysCC {
	return &LifeCycleSysCC{
		Support:          &supportImpl{},
		PolicyChecker:    policyprovider.GetPolicyChecker(),
		SCCProvider:      sccp,
		ACLProvider:      ACLProvider,
		PlatformRegistry: platformRegistry,
	}
}
998306
func New(ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, aclProvider aclmgmt.ACLProvider) *PeerConfiger {
	return &PeerConfiger{
		policyChecker: policy.NewPolicyChecker(
			peer.NewChannelPolicyManagerGetter(),
			mgmt.GetLocalMSP(),
			mgmt.NewLocalMSPPrincipalGetter(),
		),
		configMgr:   peer.NewConfigSupport(),
		ccp:         ccp,
		sccp:        sccp,
		aclProvider: aclProvider,
	}
}
559641
func New(ctx context.Context, p *env.RemoteParameters, c chan *policy.RuntimeError, r rpcwrapper.RPCClient) ProcessManager {

	m := &RemoteMonitor{
		remoteEnforcerTempBuildPath: remoteEnforcerTempBuildPath,
		remoteEnforcerBuildName:     remoteEnforcerBuildName,
		netNSPath:                   netNSPath,
		activeProcesses:             cache.NewCache(processMonitorCacheName),
		childExitStatus:             make(chan exitStatus, 100),
		logToConsole:                p.LogToConsole,
		logWithID:                   p.LogWithID,
		logLevel:                    p.LogLevel,
		logFormat:                   p.LogFormat,
		compressedTags:              p.CompressedTags,
		runtimeErrorChannel:         c,
		rpc:                         r,
	}

	go m.collectChildExitStatus(ctx)

	return m
}
1269391
func New(c *Config) (*Middleware, error) {
	if c == nil {
		return nil, ErrMissingConfig
	}
	if c.Secret == "" {
		return nil, ErrMissingSecret
	}
	if c.Auth == nil {
		return nil, ErrMissingAuthFunc
	}
	if c.Claims == nil {
		return nil, ErrMissingClaimsFunc
	}
	if c.IdentityField == "" {
		c.IdentityField = "email"
	}
	if c.VerifyField == "" {
		c.VerifyField = "password"
	}
	m := &Middleware{
		secret:        c.Secret,
		auth:          c.Auth,
		claims:        c.Claims,
		identityField: c.IdentityField,
		verifyField:   c.VerifyField,
	}
	return m, nil
}
660159
func New(rawData ...interface{}) *Notifier {
	config := Config.clone()
	for i, datum := range rawData {
		if c, ok := datum.(Configuration); ok {
			config.update(&c)
			rawData[i] = nil
		}
	}

	return &Notifier{
		Config:  config,
		RawData: rawData,
	}
}