// NewInternalAPIEngine makes an API engine for internally querying the keybase
// API server
558628
func NewInternalAPIEngine(g *GlobalContext) (*InternalAPIEngine, error) {
	cliConfig, err := genClientConfigForInternalAPI(g)
	if err != nil {
		return nil, err
	}

	i := &InternalAPIEngine{
		BaseAPIEngine{
			config:       cliConfig,
			clients:      make(map[int]*Client),
			Contextified: NewContextified(g),
		},
	}
	return i, nil
}
555168
func NewIANA(iaid [4]byte, t1 time.Duration, t2 time.Duration, options dhcp6.Options) *IANA {
	if options == nil {
		options = make(dhcp6.Options)
	}

	return &IANA{
		IAID:    iaid,
		T1:      t1,
		T2:      t2,
		Options: options,
	}
}
873308
func getNodeInternalIP(node *api.Node) string {
	for _, address := range node.Status.Addresses {
		if address.Type == api.NodeInternalIP {
			return address.Address
		}
	}

	return "<none>"
}
124559
func NewGroupChangeExternalIdType(Description string) *GroupChangeExternalIdType {
	s := new(GroupChangeExternalIdType)
	s.Description = Description
	return s
}
326746
func New(query string, distance int) (*Levenshtein, error) {
	lev := &dynamicLevenshtein{
		query:    query,
		distance: uint(distance),
	}
	dfabuilder := newDfaBuilder(lev)
	dfa, err := dfabuilder.build()
	if err != nil {
		return nil, err
	}
	return &Levenshtein{
		prog: lev,
		dfa:  dfa,
	}, nil
}
797856
func newCipherGeneric(key []byte) (Block, error) {
	n := len(key) + 28
	c := aesCipher{make([]uint32, n), make([]uint32, n)}
	expandKeyGo(key, c.enc, c.dec)
	return &c, nil
}
514584
func NewEngine(cfg *config.EngineConfig) *Engine {
	if cfg == nil {
		defaultCfg := config.DefaultEngineConfig()
		cfg = &defaultCfg
	}
	// TODO(jsing): Validate node, peer and cluster IP configuration.
	engine := &Engine{
		config:   cfg,
		fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize),
		ncc:      ncclient.NewNCC(cfg.NCCSocket),

		overrides:    make(map[string]seesaw.Override),
		overrideChan: make(chan seesaw.Override),

		vlans:    make(map[uint16]*seesaw.VLAN),
		vservers: make(map[string]*vserver),

		shutdown:    make(chan bool),
		shutdownARP: make(chan bool),
		shutdownIPC: make(chan bool),
		shutdownRPC: make(chan bool),

		vserverSnapshots: make(map[string]*seesaw.Vserver),
		vserverChan:      make(chan *seesaw.Vserver, 1000),
	}
	engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval)
	engine.haManager = newHAManager(engine, cfg.HAStateTimeout)
	engine.hcManager = newHealthcheckManager(engine)
	engine.syncClient = newSyncClient(engine)
	engine.syncServer = newSyncServer(engine)
	return engine
}
675846
func NewPGPKeyfinder(g *libkb.GlobalContext, arg *PGPKeyfinderArg) *PGPKeyfinder {
	return &PGPKeyfinder{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}
305782
func NewIndicesPutMappingService(client *Client) *IndicesPutMappingService {
	return &IndicesPutMappingService{
		client: client,
		index:  make([]string, 0),
	}
}
459997
func isInternal(p *types.Package) (bool, error) {
	for _, t := range p.Types {
		for _, member := range t.Members {
			if member.Name == "TypeMeta" {
				return !strings.Contains(member.Tags, "json"), nil
			}
		}
	}
	return false, fmt.Errorf("unable to find TypeMeta for any types in package %s", p.Path)
}
1240039
func NewInternalClient(host string, remoteClient *http.Client) (*InternalClient, error) {
	if host == "" {
		return nil, pilosa.ErrHostRequired
	}

	uri, err := pilosa.NewURIFromAddress(host)
	if err != nil {
		return nil, errors.Wrap(err, "getting URI")
	}

	client := NewInternalClientFromURI(uri, remoteClient)
	return client, nil
}
798815
func (i *BatchIndexer) addInternal(doc *Doc) (int, error) {
	b, err := json.Marshal(&indexDoc{Doc: doc})
	if err != nil {
		return i.cnt, err
	}
	i.buf.Write(b)
	i.buf.Write([]byte("\n"))
	b, err = json.Marshal(doc.Source)
	if err != nil {
		return i.cnt, nil
	}
	i.buf.Write(b)
	i.buf.Write([]byte("\n"))
	i.cnt++
	return i.cnt, nil
}
1101082
func NewInternalError(err error) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusInternalServerError,
		Reason: unversioned.StatusReasonInternalError,
		Details: &unversioned.StatusDetails{
			Causes: []unversioned.StatusCause{{Message: err.Error()}},
		},
		Message: fmt.Sprintf("Internal error occurred: %v", err),
	}}
}
806229
func NewImageLayerIndex(lw ImageListWatch) ImageLayerIndex {
	informer := cache.NewSharedIndexInformer(&cache.ListWatch{
		ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
			list, err := lw.List(metav1.ListOptions{
				ResourceVersion: options.ResourceVersion,
				Limit:           options.Limit,
				Continue:        options.Continue,
			})
			if err != nil {
				return nil, err
			}
			// reduce the full image list to a smaller subset.
			out := &metainternalversion.List{
				ListMeta: metav1.ListMeta{
					Continue:        list.Continue,
					ResourceVersion: list.ResourceVersion,
				},
				Items: make([]runtime.Object, len(list.Items)),
			}
			for i, image := range list.Items {
				out.Items[i] = imageLayersForImage(&image)
			}
			return out, nil
		},
		WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
			w, err := lw.Watch(metav1.ListOptions{
				ResourceVersion: options.ResourceVersion,
			})
			if err != nil {
				return nil, err
			}
			return watch.Filter(w, func(in watch.Event) (out watch.Event, keep bool) {
				if in.Object == nil {
					return in, true
				}
				// reduce each object to the minimal subset we need for the cache
				image, ok := in.Object.(*imagev1.Image)
				if !ok {
					return in, true
				}
				in.Object = imageLayersForImage(image)
				return in, true
			}), nil
		},
	}, &ImageLayers{}, 0, cache.Indexers{
		// layers allows fast access to the images with a given layer
		"layers": func(obj interface{}) ([]string, error) {
			entry, ok := obj.(*ImageLayers)
			if !ok {
				return nil, fmt.Errorf("unexpected cache object %T", obj)
			}
			keys := make([]string, 0, len(entry.Layers))
			for _, layer := range entry.Layers {
				keys = append(keys, layer.Name)
			}
			return keys, nil
		},
	})
	return imageLayerIndex{informer: informer}
}
605979
func NewEngine(cfg Config) EngineInternal {
	eng := &engineImpl{cfg: cfg}
	eng.init()
	return eng
}
11860
func NewIntFlag(fl cli.IntFlag) *IntFlag {
	return &IntFlag{IntFlag: fl, set: nil}
}
728413
func (g *BuildGenerator) InstantiateInternal(ctx context.Context, request *buildapi.BuildRequest) (*buildapi.Build, error) {
	versionedRequest := &buildv1.BuildRequest{}
	if err := legacyscheme.Scheme.Convert(request, versionedRequest, nil); err != nil {
		return nil, fmt.Errorf("failed to convert internal BuildRequest to external: %v", err)
	}
	build, err := g.Instantiate(ctx, versionedRequest)
	if err != nil {
		return nil, err
	}
	internalBuild := &buildapi.Build{}
	if err := legacyscheme.Scheme.Convert(build, internalBuild, nil); err != nil {
		return nil, fmt.Errorf("failed to convert external Build to internal: %v", err)
	}
	return internalBuild, nil
}