// FilterPlatforms is a handler wrapper which limits the descriptors returned
// based on matching the specified platform matcher.
162682
func FilterPlatforms(f HandlerFunc, m platforms.Matcher) HandlerFunc {
	return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		children, err := f(ctx, desc)
		if err != nil {
			return children, err
		}

		var descs []ocispec.Descriptor

		if m == nil {
			descs = children
		} else {
			for _, d := range children {
				if d.Platform == nil || m.Match(*d.Platform) {
					descs = append(descs, d)
				}
			}
		}

		return descs, nil
	}
}
548797
func (s *Run) SetPlatform(v string) *Run {
	s.Platform = &v
	return s
}
872324
func filterPodPresets(list []*settingsv1alpha1.PodPreset, pod *api.Pod) ([]*settingsv1alpha1.PodPreset, error) {
	var matchingPPs []*settingsv1alpha1.PodPreset

	for _, pp := range list {
		selector, err := metav1.LabelSelectorAsSelector(&pp.Spec.Selector)
		if err != nil {
			return nil, fmt.Errorf("label selector conversion failed: %v for selector: %v", pp.Spec.Selector, err)
		}

		// check if the pod labels match the selector
		if !selector.Matches(labels.Set(pod.Labels)) {
			continue
		}
		klog.V(4).Infof("PodPreset %s matches pod %s labels", pp.GetName(), pod.GetName())
		matchingPPs = append(matchingPPs, pp)
	}
	return matchingPPs, nil
}
316977
func LoadPlatforms(filename string) error {
	// if filename is empty, skip the metadata loading
	if filename == "" {
		return nil
	}

	relativePath := filepath.Dir(filename)
	// Attempt to load root certificate metadata
	log.Debug("Loading platform metadata: ", filename)
	bytes, err := ioutil.ReadFile(filename)
	if err != nil {
		return fmt.Errorf("platform metadata failed to load: %v", err)
	}
	var rawPlatforms []Platform
	if bytes != nil {
		err = json.Unmarshal(bytes, &rawPlatforms)
		if err != nil {
			return fmt.Errorf("platform metadata failed to parse: %v", err)
		}
	}

	for _, platform := range rawPlatforms {
		if platform.KeyStoreFile != "" {
			platform.KeyStoreFile = path.Join(relativePath, platform.KeyStoreFile)
		}
		ok := platform.ParseAndLoad()
		if !ok {
			// erase all loaded platforms
			Platforms = nil
			return fmt.Errorf("fail to finalize the parsing of platform metadata: %v", platform)
		}

		log.Infof("Platform metadata is loaded: %v %v", platform.Name, len(platform.KeyStore))
		Platforms = append(Platforms, platform)
	}

	return nil
}
359643
func (s *RegisterDeviceInput) SetPlatform(v string) *RegisterDeviceInput {
	s.Platform = &v
	return s
}
723500
func (s *App) SetPlatform(v string) *App {
	s.Platform = &v
	return s
}
1219823
func FilterEvents(filter EventFilter, userdata interface{}) {
	context := newEventFilterCallbackContext(filter, userdata)
	C.filterEvents(context.cptr())
}
938923
func (s *CreateAppInput) SetPlatform(v string) *CreateAppInput {
	s.Platform = &v
	return s
}
429192
func (s *Offering) SetPlatform(v string) *Offering {
	s.Platform = &v
	return s
}
848870
func WithPlatform(platform string) RemoteOpt {
	if platform == "" {
		platform = platforms.DefaultString()
	}
	return func(_ *Client, c *RemoteContext) error {
		for _, p := range c.Platforms {
			if p == platform {
				return nil
			}
		}

		c.Platforms = append(c.Platforms, platform)
		return nil
	}
}
1190990
func (actor Actor) GetPlatformString(runtimeGOOS string, runtimeGOARCH string) string {
	return generic.GeneratePlatform(runtime.GOOS, runtime.GOARCH)
}
461482
func importPlatforms(c context.Context, configSet config.Set) (map[string]int64, error) {
	platform := &configPB.Platforms{}
	metadata := &config.Meta{}
	if err := cfgclient.Get(c, cfgclient.AsService, configSet, platformsFilename, textproto.Message(platform), metadata); err != nil {
		return nil, errors.Annotate(err, "failed to load %s", platformsFilename).Err()
	}
	logging.Infof(c, "Found %s revision %q", platformsFilename, metadata.Revision)

	ctx := &validation.Context{Context: c}
	ctx.SetFile(platformsFilename)
	validatePlatforms(ctx, platform)
	if err := ctx.Finalize(); err != nil {
		return nil, errors.Annotate(err, "invalid config").Err()
	}

	ids, err := model.EnsurePlatforms(c, platform.Platform)
	if err != nil {
		return nil, errors.Annotate(err, "failed to ensure platforms").Err()
	}
	return ids, nil
}
1052810
func FilterVersionsToPlatform(versions Versions) Versions {
	var output []*Version

	for _, version := range versions {
		if version.Platform != runtime.GOOS {
			continue
		}
		if version.Architecture != runtime.GOARCH {
			continue
		}
		output = append(output, version)
	}

	return output
}
1241970
func ValidatePlatform(platform specs.Platform) error {
	if runtime.GOOS == "windows" {
		if !(platform.OS == runtime.GOOS || (LCOWSupported() && platform.OS == "linux")) {
			return errors.Errorf("unsupported os %s", platform.OS)
		}
	}
	return nil
}
1189946
func (s *AvailabilityZone) SetSupportedPlatforms(v []*SupportedPlatform) *AvailabilityZone {
	s.SupportedPlatforms = v
	return s
}
1122648
func filterMatchingPrefix(entries []string, prefixEntry string) []string {
	start := 0
	end := len(entries)
	for {
		if start == end {
			break
		}
		if hasPrefix(entries[start], prefixEntry) {
			break
		}
		start++
	}
	for {
		if start == end {
			break
		}
		if hasPrefix(entries[end-1], prefixEntry) {
			break
		}
		end--
	}
	sort.Strings(entries[start:end])
	return entries[start:end]
}
1068552
func (s *SegmentDemographics) SetPlatform(v *SetDimension) *SegmentDemographics {
	s.Platform = v
	return s
}