// NewWebFrontEndImpl constructs a web service for Boulder
181028
func NewWebFrontEndImpl(
	scope metrics.Scope,
	clk clock.Clock,
	keyPolicy goodkey.KeyPolicy,
	certificateChains map[string][]byte,
	logger blog.Logger,
) (WebFrontEndImpl, error) {
	nonceService, err := nonce.NewNonceService(scope)
	if err != nil {
		return WebFrontEndImpl{}, err
	}

	return WebFrontEndImpl{
		log:               logger,
		clk:               clk,
		nonceService:      nonceService,
		keyPolicy:         keyPolicy,
		certificateChains: certificateChains,
		stats:             initStats(scope),
		scope:             scope,
	}, nil
}
1225574
func SwarmingBuildImpl(c context.Context, svc SwarmingService, taskID string) (*ui.MiloBuildLegacy, error) {
	// First, get the task result from swarming, and maybe the logs.
	fr, logDogStreamAddr, err := swarmingFetchMaybeLogs(c, svc, taskID)
	if err != nil {
		return nil, err
	}
	swarmingResult := fr.res

	// Legacy codepath - Annotations are encoded in the swarming log instead of LogDog.
	// TODO(hinoka): Remove this once skia moves logging to logdog/kitchen.
	if logDogStreamAddr == nil {
		taskURL := TaskPageURL(svc.GetHost(), taskID)
		return buildFromLogs(c, taskURL, fr)
	}

	// Create an empty build here first because we might want to add some
	// system-level messages.
	var build ui.MiloBuildLegacy

	// Load the build from the LogDog service.  For known classes of errors, add
	// steps in the build presentation to explain what may be going on.
	step, err := rawpresentation.ReadAnnotations(c, logDogStreamAddr)
	switch errors.Unwrap(err) {
	case coordinator.ErrNoSuchStream:
		// The stream was not found.  This could be due to one of two things:
		// 1. The step just started and we're just waiting for the logs
		// to propogage to logdog.
		// 2. The bootsrap on the client failed, and never sent data to logdog.
		// This would be evident because the swarming result would be a failure.
		if swarmingResult.State == TaskCompleted {
			err = failedToStart(c, &build, swarmingResult, svc.GetHost())
			return &build, err
		}
		logging.WithError(err).Errorf(c, "User cannot access stream.")
		build.Components = append(build.Components, infoComponent(model.Running,
			"Waiting...", "waiting for annotation stream"))

	case coordinator.ErrNoAccess:
		logging.WithError(err).Errorf(c, "User cannot access stream.")
		build.Components = append(build.Components, infoComponent(model.Failure,
			"No Access", "no access to annotation stream"))
	case nil:
		// continue

	default:
		logging.WithError(err).Errorf(c, "Failed to load LogDog annotation stream.")
		build.Components = append(build.Components, infoComponent(model.InfraFailure,
			"Error", "failed to load annotation stream: "+err.Error()))
	}

	// Skip these steps if the LogDog stream doesn't exist.
	// i.e. when the stream isn't ready yet, or errored out.
	if step != nil {
		// Milo Step Proto += Swarming Result Data
		if err := addTaskToMiloStep(c, svc.GetHost(), swarmingResult, step); err != nil {
			return nil, err
		}
		// Log links are linked directly to the logdog service.  This is used when
		// converting proto step data to resp build structs
		ub := rawpresentation.NewURLBuilder(logDogStreamAddr)
		rawpresentation.AddLogDogToBuild(c, ub, step, &build)
	}
	addFailureSummary(&build)

	// Milo Resp Build += Swarming Result Data
	// This is done for things in resp but not in step like the banner, buildset,
	// recipe link, bot info, title, etc.
	err = addTaskToBuild(c, svc.GetHost(), swarmingResult, &build)
	return &build, err
}
377923
func NewInverseBloomFilter(capacity uint) *InverseBloomFilter {
	return &InverseBloomFilter{
		array:    make([]*[]byte, capacity),
		hashPool: &sync.Pool{New: func() interface{} { return fnv.New32() }},
		capacity: capacity,
	}
}
1270857
func NewEndpointDiscoveryWrapper(ctx context.Client, channelID string, target fab.DiscoveryService, opts ...Opt) (*DiscoveryWrapper, error) {
	chpeers := ctx.EndpointConfig().ChannelPeers(channelID)
	if len(chpeers) == 0 {
		return nil, errors.Errorf("no channel peers for channel [%s]", channelID)
	}

	s := &DiscoveryWrapper{
		DiscoveryService: target,
		chPeers:          chpeers,
		ctx:              ctx,
	}

	for _, opt := range opts {
		opt(s)
	}

	if s.filter != nil {
		s.DiscoveryService = discovery.NewDiscoveryFilterService(target, s.filter)
	}

	return s, nil
}
288523
func newWebHookREST(buildConfigClient buildclienttyped.BuildV1Interface, secretsClient kubetypedclient.SecretsGetter, instantiator client.BuildConfigInstantiator, groupVersion schema.GroupVersion, plugins map[string]webhook.Plugin) *WebHook {
	return &WebHook{
		groupVersion:      groupVersion,
		buildConfigClient: buildConfigClient,
		secretsClient:     secretsClient,
		instantiator:      instantiator,
		plugins:           plugins,
	}
}
771353
func NewWebSession(name string, spec WebSessionSpecV2) WebSession {
	return &WebSessionV2{
		Kind:    KindWebSession,
		Version: V2,
		Metadata: Metadata{
			Name:      name,
			Namespace: defaults.Namespace,
		},
		Spec: spec,
	}
}
962890
func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) {
	b := &Browser{
		LostConnection: make(chan struct{}),

		newTabQueue: make(chan *Target),
		delTabQueue: make(chan target.SessionID, 1),

		// Fit some jobs without blocking, to reduce blocking in
		// Execute.
		cmdQueue: make(chan cmdJob, 32),

		logf: log.Printf,
	}
	// apply options
	for _, o := range opts {
		o(b)
	}
	// ensure errf is set
	if b.errf == nil {
		b.errf = func(s string, v ...interface{}) { b.logf("ERROR: "+s, v...) }
	}

	// dial
	var err error
	urlstr = forceIP(urlstr)
	b.conn, err = DialContext(ctx, urlstr, WithConnDebugf(b.dbgf))
	if err != nil {
		return nil, fmt.Errorf("could not dial %q: %v", urlstr, err)
	}

	go b.run(ctx)
	return b, nil
}
139114
func NewClientWrapper() client.Wrapper {
	return func(c client.Client) client.Client {
		return &ddWrapper{c}
	}
}
164368
func NewMultiHandler(signers map[string]signer.Signer, defaultLabel string) (http.Handler, error) {
	return &api.HTTPHandler{
		Handler: &MultiHandler{
			signers:      signers,
			defaultLabel: defaultLabel,
		},
		Methods: []string{"POST"},
	}, nil
}
1306253
func NewWebSessionsChangeFixedLengthPolicyType(Description string) *WebSessionsChangeFixedLengthPolicyType {
	s := new(WebSessionsChangeFixedLengthPolicyType)
	s.Description = Description
	return s
}
310988
func NewOnHostDatapointDimensions(metric string, value datapoint.Value, metricType datapoint.MetricType, dimensions map[string]string) *datapoint.Datapoint {
	return Wrap(datapoint.New(metric, dimensions, value, metricType, time.Now()))
}
1214618
func NewDomainInvitesSetInviteNewUserPrefToYesType(Description string) *DomainInvitesSetInviteNewUserPrefToYesType {
	s := new(DomainInvitesSetInviteNewUserPrefToYesType)
	s.Description = Description
	return s
}
1292118
func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uint64) *core.ChainIndexer {
	trieTable := rawdb.NewTable(db, BloomTrieTablePrefix)
	backend := &BloomTrieIndexerBackend{
		diskdb:     db,
		odr:        odr,
		trieTable:  trieTable,
		triedb:     trie.NewDatabaseWithCache(trieTable, 1), // Use a tiny cache only to keep memory down
		parentSize: parentSize,
		size:       size,
	}
	backend.bloomTrieRatio = size / parentSize
	backend.sectionHeads = make([]common.Hash, backend.bloomTrieRatio)
	return core.NewChainIndexer(db, rawdb.NewTable(db, "bltIndex-"), backend, size, 0, time.Millisecond*100, "bloomtrie")
}
516409
func NewValidationBarrier(numActiveReqs int,
	quitChan chan struct{}) *ValidationBarrier {

	v := &ValidationBarrier{
		chanAnnFinSignal:     make(map[lnwire.ShortChannelID]chan struct{}),
		chanEdgeDependencies: make(map[lnwire.ShortChannelID]chan struct{}),
		nodeAnnDependencies:  make(map[route.Vertex]chan struct{}),
		quit:                 quitChan,
	}

	// We'll first initialize a set of sempahores to limit our concurrency
	// when validating incoming requests in parallel.
	v.validationSemaphore = make(chan struct{}, numActiveReqs)
	for i := 0; i < numActiveReqs; i++ {
		v.validationSemaphore <- struct{}{}
	}

	return v
}
286297
func NewForConfigOrDie(c *rest.Config) *Clientset {
	var cs Clientset
	cs.fluxV1beta1 = fluxv1beta1.NewForConfigOrDie(c)
	cs.helmV1alpha2 = helmv1alpha2.NewForConfigOrDie(c)

	cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
	return &cs
}
1200596
func NewNonInteractiveDeferredLoadingClientConfig(loadingRules *ClientConfigLoadingRules, overrides *ConfigOverrides) ClientConfig {
	return DeferredLoadingClientConfig{loadingRules, overrides, nil}
}
13226
func (a *MetricsAPIInstaller) NewWebService() *restful.WebService {
	ws := new(restful.WebService)
	ws.Path(a.prefix)
	// a.prefix contains "prefix/group/version"
	ws.Doc("API at " + a.prefix)
	// Backwards compatibility, we accepted objects with empty content-type at V1.
	// If we stop using go-restful, we can default empty content-type to application/json on an
	// endpoint by endpoint basis
	ws.Consumes("*/*")
	mediaTypes, streamMediaTypes := negotiation.MediaTypesForSerializer(a.group.Serializer)
	ws.Produces(append(mediaTypes, streamMediaTypes...)...)
	ws.ApiVersion(a.group.GroupVersion.String())

	return ws
}