// DefaultMetadataExtractor is the default metadata extractor for Docker
970267
func DefaultMetadataExtractor(info *types.ContainerJSON) (*policy.PURuntime, error) {

	// trigger new build
	tags := policy.NewTagStore()
	// TODO: Remove OLDTAGS
	tags.AppendKeyValue("@sys:image", info.Config.Image)
	tags.AppendKeyValue("@sys:name", info.Name)
	tags.AppendKeyValue("@app:image", info.Config.Image)
	tags.AppendKeyValue("@app:extractor", "docker")
	tags.AppendKeyValue("@app:docker:name", info.Name)

	for k, v := range info.Config.Labels {
		if len(strings.TrimSpace(k)) == 0 {
			continue
		}
		value := v
		if len(v) == 0 {
			value = "<empty>"
		}
		if !strings.HasPrefix(k, UserLabelPrefix) {
			tags.AppendKeyValue(UserLabelPrefix+k, value)
		} else {
			tags.AppendKeyValue(k, value)
		}
	}

	ipa := policy.ExtendedMap{
		"bridge": info.NetworkSettings.IPAddress,
	}

	if info.HostConfig.NetworkMode == constants.DockerHostMode {
		return policy.NewPURuntime(info.Name, info.State.Pid, "", tags, ipa, common.LinuxProcessPU, hostModeOptions(info)), nil
	}

	return policy.NewPURuntime(info.Name, info.State.Pid, "", tags, ipa, common.ContainerPU, nil), nil
}
231681
func extractFromListMeta(v reflect.Value, a *genericAccessor) error {
	if err := runtime.FieldPtr(v, "ResourceVersion", &a.resourceVersion); err != nil {
		return err
	}
	if err := runtime.FieldPtr(v, "SelfLink", &a.selfLink); err != nil {
		return err
	}
	return nil
}
772864
func NewMetadataJSONReader(in io.Reader) (*Metadata, error) {
	var flat flatMetadata
	if err := json.NewDecoder(in).Decode(&flat); err != nil {
		return nil, errors.Trace(err)
	}

	meta := NewMetadata()
	meta.SetID(flat.ID)

	err := meta.SetFileInfo(flat.Size, flat.Checksum, flat.ChecksumFormat)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if !flat.Stored.IsZero() {
		meta.SetStored(&flat.Stored)
	}

	meta.Started = flat.Started
	if !flat.Finished.IsZero() {
		meta.Finished = &flat.Finished
	}
	meta.Notes = flat.Notes
	meta.Origin = Origin{
		Model:    flat.Environment,
		Machine:  flat.Machine,
		Hostname: flat.Hostname,
		Version:  flat.Version,
		Series:   flat.Series,
	}

	// TODO(wallyworld) - put these in a separate file.
	meta.CACert = flat.CACert
	meta.CAPrivateKey = flat.CAPrivateKey

	return meta, nil
}
1064951
func (impl *repoImpl) GetPrefixMetadata(c context.Context, r *api.PrefixRequest) (resp *api.PrefixMetadata, err error) {
	// It is fine to implement this in terms of GetInheritedPrefixMetadata, since
	// we need to fetch all inherited metadata anyway to check ACLs.
	inherited, err := impl.GetInheritedPrefixMetadata(c, r)
	if err != nil {
		return nil, err
	}
	// Have the metadata for the requested prefix? It should be the last if so.
	if m := inherited.PerPrefixMetadata; len(m) != 0 && m[len(m)-1].Prefix == r.Prefix {
		return m[len(m)-1], nil
	}
	// Note that GetInheritedPrefixMetadata checked that the caller has permission
	// to view the requested prefix (via some parent prefix ACL), so sincerely
	// reply with NotFound.
	return nil, noMetadataErr(r.Prefix)
}
1328114
func CodeGenRequestFieldExtractor(fullMethod string, req interface{}) map[string]interface{} {
	if ext, ok := req.(requestFieldsExtractor); ok {
		retMap := make(map[string]interface{})
		ext.ExtractRequestFields(retMap)
		if len(retMap) == 0 {
			return nil
		}
		return retMap
	}
	return nil
}
763088
func (i *ImageService) GetMetadata(imageID string, auth Authenticator) (*ImageMetadata, error) {
	path := fmt.Sprintf("images/%s/json", imageID)
	req, err := i.client.newRequest("GET", path, auth, nil)
	if err != nil {
		return nil, err
	}

	meta := &ImageMetadata{}
	_, err = i.client.do(req, meta)
	if err != nil {
		return nil, err
	}

	return meta, nil
}
713333
func MetadataFromTools(toolsList coretools.List, toolsDir string) []*ToolsMetadata {
	metadata := make([]*ToolsMetadata, len(toolsList))
	for i, t := range toolsList {
		path := fmt.Sprintf("%s/juju-%s-%s-%s.tgz", toolsDir, t.Version.Number, t.Version.Series, t.Version.Arch)
		metadata[i] = &ToolsMetadata{
			Release:  t.Version.Series,
			Version:  t.Version.Number.String(),
			Arch:     t.Version.Arch,
			Path:     path,
			FileType: "tar.gz",
			Size:     t.Size,
			SHA256:   t.SHA256,
		}
	}
	return metadata
}
681674
func SubOptionMonitorPodMetadataExtractor(extractor extractors.PodMetadataExtractor) PodMonitorOption {
	return func(cfg *podmonitor.Config) {
		cfg.MetadataExtractor = extractor
	}
}
623028
func getMetaDataEntry(metadataString string) (map[string]string, *probe.Error) {
	metaDataMap := make(map[string]string)
	for _, metaData := range strings.Split(metadataString, ",") {
		metaDataEntry := strings.Split(metaData, "=")
		if len(metaDataEntry) == 2 {
			metaDataMap[metaDataEntry[0]] = metaDataEntry[1]
		} else {
			return nil, probe.NewError(ErrInvalidMetadata)
		}
	}
	return metaDataMap, nil
}
1319327
func getMetadataInner(ctx context.Context, g *libkb.GlobalContext, folder *keybase1.Folder) ([]keybase1.GitRepoResult, error) {
	mctx := libkb.NewMetaContext(ctx, g)
	teamer := NewTeamer(g)

	apiArg := libkb.APIArg{
		Endpoint:    "kbfs/git/team/get",
		SessionType: libkb.APISessionTypeREQUIRED,
		Args:        libkb.HTTPArgs{}, // a limit parameter exists, default 100, and we don't currently set it
	}

	// The team_id parameter is optional. Add it in if the caller supplied it.
	if folder != nil {
		teamIDVis, err := teamer.LookupOrCreate(ctx, *folder)
		if err != nil {
			return nil, err
		}
		apiArg.Args["team_id"] = libkb.S{Val: string(teamIDVis.TeamID)}
	}
	var serverResponse ServerResponse
	err := mctx.G().GetAPI().GetDecode(mctx, apiArg, &serverResponse)
	if err != nil {
		return nil, err
	}

	// Unbox the repos in parallel
	repoCh := make(chan ServerResponseRepo)
	eg, ctx := errgroup.WithContext(ctx)
	eg.Go(func() error {
		defer close(repoCh)
		for _, responseRepo := range serverResponse.Repos {
			select {
			case repoCh <- responseRepo:
			case <-ctx.Done():
				return ctx.Err()
			}
		}
		return nil
	})

	// Initializing the results list to non-nil means that we end up seeing
	// "[]" instead of "null" in the final JSON output on the CLI, which is
	// preferable.
	resultList := []keybase1.GitRepoResult{}
	var resLock sync.Mutex
	var firstErr error
	var anySuccess bool
	numUnboxThreads := 2
	for i := 0; i < numUnboxThreads; i++ {
		eg.Go(func() error {
			for responseRepo := range repoCh {
				info, skip, err := getMetadataInnerSingle(ctx, g, folder, responseRepo)

				resLock.Lock()
				if err != nil {
					if firstErr == nil {
						firstErr = err
					}
					mctx.Debug("git.getMetadataInner error (team:%v, repo:%v): %v", responseRepo.TeamID, responseRepo.RepoID, err)
					resultList = append(resultList, keybase1.NewGitRepoResultWithErr(err.Error()))
				} else {
					if !skip {
						anySuccess = true
						resultList = append(resultList, keybase1.NewGitRepoResultWithOk(*info))
					}
				}
				resLock.Unlock()

			}
			return nil
		})
	}
	if err := eg.Wait(); err != nil {
		return resultList, err
	}
	sort.Sort(ByRepoMtime(resultList))

	// If there were no repos, return ok
	// If all repos failed, return the first error (something is probably wrong that's not repo-specific)
	// If no repos failed, return ok
	if len(resultList) == 0 {
		return resultList, nil
	}
	if !anySuccess {
		return resultList, firstErr
	}
	return resultList, nil
}
1066306
func (cl *CoLog) SetExtractor(ex Extractor) {
	cl.mu.Lock()
	defer cl.mu.Unlock()

	cl.extractor = ex
}
1264589
func (goPlatform *Platform) GetMetadataProvider(code []byte) platforms.MetadataProvider {
	return &ccmetadata.TargzMetadataProvider{Code: code}
}
305593
func EmptyPredicateMetadataProducer(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) PredicateMetadata {
	return nil
}
1112758
func defaultHandler(w http.ResponseWriter, r *http.Request) {
	if err := defaultEntryTemplate.Execute(w, nil); err != nil {
		reportError(w, r, err)
	}
}
357029
func FromMetadata(md metadata.MD) *orcapb.LoadReport {
	vs := md.Get(mdKey)
	if len(vs) == 0 {
		return nil
	}
	return fromBytes([]byte(vs[0]))
}
783895
func GetMetadataSources(env environs.BootstrapEnviron) ([]simplestreams.DataSource, error) {
	config := env.Config()

	// Add configured and environment-specific datasources.
	var sources []simplestreams.DataSource
	if userURL, ok := config.AgentMetadataURL(); ok {
		verify := utils.VerifySSLHostnames
		if !config.SSLHostnameVerification() {
			verify = utils.NoVerifySSLHostnames
		}
		sources = append(sources, simplestreams.NewURLSignedDataSource(conf.AgentMetadataURLKey, userURL, keys.JujuPublicKey, verify, simplestreams.SPECIFIC_CLOUD_DATA, false))
	}

	envDataSources, err := environmentDataSources(env)
	if err != nil {
		return nil, err
	}
	sources = append(sources, envDataSources...)

	// Add the default, public datasource.
	defaultURL, err := ToolsURL(DefaultBaseURL)
	if err != nil {
		return nil, err
	}
	if defaultURL != "" {
		sources = append(sources,
			simplestreams.NewURLSignedDataSource("default simplestreams", defaultURL, keys.JujuPublicKey, utils.VerifySSLHostnames, simplestreams.DEFAULT_CLOUD_DATA, true))
	}
	return sources, nil
}
1037704
func (c *Subcommand) DefaultMeta() lucicfg.Meta {
	if c.params == nil {
		panic("call Init first")
	}
	return lucicfg.Meta{
		ConfigServiceHost: c.params.ConfigServiceHost,
		ConfigDir:         "generated",
	}
}