// AddImport tracks exports for a given import binding
501050
func (ce *ContainerEndpoints) AddImport(cancel <-chan struct{}, application string, bind zkservice.ImportBinding) {
	logger := plog.WithFields(log.Fields{
		"application":     application,
		"applicationglob": bind.Application,
		"purpose":         bind.Purpose,
	})
	logger.Debug("Tracking exports for endpoint")
	defer logger.Debug("Exited export tracking for endpoint")
	bind.Application = application

	for {
		select {
		case conn := <-zzk.Connect("/", zzk.GetLocalConnection):
			if conn != nil {

				logger.Debug("Received coordinator connection")

				ch := registry.TrackExports(cancel, conn, ce.opts.TenantID, application)
				for exports := range ch {
					ce.UpdateRemoteExports(bind, exports)
				}

				select {
				case <-cancel:
					return
				default:
				}
			}
		case <-cancel:
			return
		}
	}
}
1342421
func (p *parser) recordImport(f *ast.File, typ ast.Expr) error {
	if star, ok := typ.(*ast.StarExpr); ok {
		typ = star.X
	}

	sel, ok := typ.(*ast.SelectorExpr)
	if !ok {
		return nil
	}
	pkgID, ok := sel.X.(*ast.Ident)
	if !ok {
		return nil
	}

	if _, ok := p.extraImports[pkgID.Name]; ok {
		return nil
	}

	path := ""
	for _, i := range f.Imports {
		if i.Name.Name == pkgID.Name {
			path = strings.Trim(i.Path.Value, `"`)
			break
		}
	}
	if path == "" {
		return fmt.Errorf("could not resolve package %s", pkgID.Name)
	}
	if p.extraImports == nil {
		p.extraImports = make(map[string]string)
	}
	p.extraImports[pkgID.Name] = path
	return nil
}
557780
func (s *IGDService) AddPortMapping(protocol nat.Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error) {
	tpl := `<u:AddPortMapping xmlns:u="%s">
	<NewRemoteHost></NewRemoteHost>
	<NewExternalPort>%d</NewExternalPort>
	<NewProtocol>%s</NewProtocol>
	<NewInternalPort>%d</NewInternalPort>
	<NewInternalClient>%s</NewInternalClient>
	<NewEnabled>1</NewEnabled>
	<NewPortMappingDescription>%s</NewPortMappingDescription>
	<NewLeaseDuration>%d</NewLeaseDuration>
	</u:AddPortMapping>`
	body := fmt.Sprintf(tpl, s.URN, externalPort, protocol, internalPort, s.LocalIP, description, duration/time.Second)

	response, err := soapRequest(s.URL, s.URN, "AddPortMapping", body)
	if err != nil && duration > 0 {
		// Try to repair error code 725 - OnlyPermanentLeasesSupported
		envelope := &soapErrorResponse{}
		if unmarshalErr := xml.Unmarshal(response, envelope); unmarshalErr != nil {
			return externalPort, unmarshalErr
		}
		if envelope.ErrorCode == 725 {
			return s.AddPortMapping(protocol, internalPort, externalPort, description, 0)
		}
	}

	return externalPort, err
}
886685
func (g *Plugin) GenerateImports(file *generator.FileDescriptor) {
	if len(file.FileDescriptorProto.Service) == 0 {
		return
	}
	g.P("import (")
	g.P(contextPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, contextPkgPath)))
	g.P(yarpcPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, yarpcPkgPath)))
	g.P(")")
	g.P()
}
874849
func GetImportFunc(ctx context.Context) store.ImportCallback {
	imf, ok := ctx.Value(ctxKeyImportFunc).(store.ImportCallback)
	if !ok || imf == nil {
		return func(context.Context, string, []string) bool {
			return true
		}
	}
	return imf
}
1111035
func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) {
	u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
	req, err := s.client.NewRequest("DELETE", u, nil)
	if err != nil {
		return nil, err
	}

	// TODO: remove custom Accept header when this API fully launches
	req.Header.Set("Accept", mediaTypeImportPreview)

	return s.client.Do(ctx, req, nil)
}
1051000
func (ce *ContainerEndpoints) RunImportListener(cancel <-chan struct{}, tenantID string, binds ...zkservice.ImportBinding) {
	plog.Debug("Running import listener")
	defer plog.Debug("Exited import listener")

	// set up the import listener and add the import bindings
	listener := registry.NewImportListener(tenantID)
	for _, bind := range binds {
		rgx, err := regexp.Compile(fmt.Sprintf("^%s$", bind.Application))
		if err != nil {
			plog.WithField("regex", bind.Application).WithError(err).Warn("Could not compile regex; skipping")
			continue
		}
		ch := listener.AddTerm(rgx)
		go func(bind zkservice.ImportBinding) {
			for {
				select {
				case app := <-ch:
					go ce.AddImport(cancel, app, bind)
				case <-cancel:
					return
				}
			}
		}(bind)
	}

	// start the import listener
	for {
		select {
		case conn := <-zzk.Connect("/", zzk.GetLocalConnection):
			if conn != nil {

				plog.Debug("Received coordinator connection")
				listener.Run(cancel, conn)

				select {
				case <-cancel:
					return
				default:
				}
			}
		case <-cancel:
			return
		}
	}
}
1282697
func (w *Wrapper) inImportDir(file string) bool {
	for _, imp := range w.ImportDirs {
		if strings.HasPrefix(file, imp) {
			return true
		}
	}
	return false
}
520705
func (s *SourceImportAuthor) GetImportURL() string {
	if s == nil || s.ImportURL == nil {
		return ""
	}
	return *s.ImportURL
}
1044675
func (u Universe) AddImports(packagePath string, importPaths ...string) {
	p := u.Package(packagePath)
	for _, i := range importPaths {
		p.Imports[i] = u.Package(i)
	}
}
1197372
func (vrsConnection *VRSConnection) AddPortToAlubr0(intfName string, entityInfo EntityInfo) error {

	namedPortUUID := "port"
	namedIntfUUID := "intf"
	var err error

	// 1) Insert a row for Nuage port in OVSDB Interface table
	extIDMap := make(map[string]string)
	intfOp := libovsdb.Operation{}
	intf := make(map[string]interface{})
	intf["name"] = intfName
	extIDMap["vm-name"] = entityInfo.Name
	extIDMap["vm-uuid"] = entityInfo.UUID
	intf["external_ids"], err = libovsdb.NewOvsMap(extIDMap)
	if err != nil {
		return err
	}
	// interface table ops
	intfOp = libovsdb.Operation{
		Op:       "insert",
		Table:    interfaceTable,
		Row:      intf,
		UUIDName: namedIntfUUID,
	}

	// 2) Insert a row for Nuage port in OVSDB Port table
	portOp := libovsdb.Operation{}
	port := make(map[string]interface{})
	port["name"] = intfName
	port["interfaces"] = libovsdb.UUID{namedIntfUUID}
	port["external_ids"], err = libovsdb.NewOvsMap(extIDMap)
	if err != nil {
		return err
	}
	portOp = libovsdb.Operation{
		Op:       "insert",
		Table:    portTable,
		Row:      port,
		UUIDName: namedPortUUID,
	}

	// 3) Mutate the Ports column of the row in the Bridge table with new Nuage port
	mutateUUID := []libovsdb.UUID{libovsdb.UUID{namedPortUUID}}
	mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
	mutation := libovsdb.NewMutation("ports", "insert", mutateSet)
	condition := libovsdb.NewCondition("name", "==", bridgeName)
	mutateOp := libovsdb.Operation{
		Op:        "mutate",
		Table:     bridgeTable,
		Mutations: []interface{}{mutation},
		Where:     []interface{}{condition},
	}

	operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
	reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, operations...)
	if err != nil || len(reply) < len(operations) {
		return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0")
	}

	return nil
}
1066735
func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
	genDecl, ok := decl.(*ast.GenDecl)
	if !ok {
		return
	}

	if genDecl.Tok != token.IMPORT {
		return
	}

	for _, spec := range genDecl.Specs {
		importSpec := spec.(*ast.ImportSpec)
		var pkgAlias string
		if importSpec.Name != nil {
			pkgAlias = importSpec.Name.Name
			if pkgAlias == "_" {
				continue
			}
		}
		quotedPath := importSpec.Path.Value           // e.g. "\"sample/app/models\""
		fullPath := quotedPath[1 : len(quotedPath)-1] // Remove the quotes

		// If the package was not aliased (common case), we have to import it
		// to see what the package name is.
		// TODO: Can improve performance here a lot:
		// 1. Do not import everything over and over again.  Keep a cache.
		// 2. Exempt the standard library; their directories always match the package name.
		// 3. Can use build.FindOnly and then use parser.ParseDir with mode PackageClauseOnly
		if pkgAlias == "" {
			utils.Logger.Debug("Reading from build", "path", fullPath, "srcPath", srcDir, "gopath", build.Default.GOPATH)
			pkg, err := build.Import(fullPath, srcDir, 0)
			if err != nil {
				// We expect this to happen for apps using reverse routing (since we
				// have not yet generated the routes).  Don't log that.
				if !strings.HasSuffix(fullPath, "/app/routes") {
					utils.Logger.Error("Could not find import:", "path", fullPath, "srcPath", srcDir, "error", err)
				}
				continue
			} else {
				utils.Logger.Debug("Found package in dir", "dir", pkg.Dir, "name", pkg.ImportPath)
			}
			pkgAlias = pkg.Name
		}

		imports[pkgAlias] = fullPath
	}
}
1221157
func (g *Generator) writeImports(w io.Writer) error {
	if len(g.imports) == 0 {
		return nil
	}

	if _, err := fmt.Fprintf(w, "\nimport (\n"); err != nil {
		return err
	}

	for path, alias := range g.imports {
		if alias.Alias == nil || *alias.Alias != "" {
			if _, err := fmt.Fprintf(w, "%s %q\n", alias, path); err != nil {
				return err
			}
		}
	}

	if _, err := fmt.Fprintf(w, ")\n"); err != nil {
		return err
	}

	_, err := w.Write([]byte{})
	return err
}
609753
func (s *ListImportsOutput) SetImports(v []*string) *ListImportsOutput {
	s.Imports = v
	return s
}
1240758
func (s *CancelResizeOutput) SetImportTablesNotStarted(v []*string) *CancelResizeOutput {
	s.ImportTablesNotStarted = v
	return s
}
250700
func (csp *CSP) KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (k bccsp.Key, err error) {
	// Validate arguments
	if raw == nil {
		return nil, errors.New("Invalid raw. It must not be nil.")
	}
	if opts == nil {
		return nil, errors.New("Invalid opts. It must not be nil.")
	}

	keyImporter, found := csp.KeyImporters[reflect.TypeOf(opts)]
	if !found {
		return nil, errors.Errorf("Unsupported 'KeyImportOpts' provided [%v]", opts)
	}

	k, err = keyImporter.KeyImport(raw, opts)
	if err != nil {
		return nil, errors.Wrapf(err, "Failed importing key with opts [%v]", opts)
	}

	// If the key is not Ephemeral, store it.
	if !opts.Ephemeral() {
		// Store the key
		err = csp.ks.StoreKey(k)
		if err != nil {
			return nil, errors.Wrapf(err, "Failed storing imported key with opts [%v]", opts)
		}
	}

	return
}
977357
func NewImportCommand(stdin io.Reader, stdout, stderr io.Writer) *ImportCommand {
	return &ImportCommand{
		CmdIO:      pilosa.NewCmdIO(stdin, stdout, stderr),
		BufferSize: 10000000,
	}
}