// labelIsAllowed return true if a should be included in metric
// the caller should lock m.filterLock while calling this method
186304
func (m *Metrics) labelIsAllowed(label *Label) bool {
	labelName := (*label).Name
	if m.blockedLabels != nil {
		_, ok := m.blockedLabels[labelName]
		if ok {
			// If present, let's remove this label
			return false
		}
	}
	if m.allowedLabels != nil {
		_, ok := m.allowedLabels[labelName]
		return ok
	}
	// Allow by default
	return true
}
247356
func (dl *DefaultLogger) IsAllowed(loglevel LogLevel) bool {
	return logLevelPriorities[loglevel] >= logLevelPriorities[dl.GetLogLevel()]
}
391734
func ipNetToLabel(cidr *net.IPNet) labels.Label {
	ones, _ := cidr.Mask.Size()
	lblStr := maskedIPToLabelString(&cidr.IP, ones)
	return labels.ParseLabel(lblStr)
}
853868
func IsValidMetricName(n LabelValue) bool {
	if len(n) == 0 {
		return false
	}
	for i, b := range n {
		if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) {
			return false
		}
	}
	return true
}
1323359
func (s *Service) FindLabels(ctx context.Context, filter influxdb.LabelFilter, opt ...influxdb.FindOptions) ([]*influxdb.Label, error) {
	filterFunc := func(label *influxdb.Label) bool {
		return (filter.Name == "" || (filter.Name == label.Name))
	}

	labels, err := s.filterLabels(ctx, filterFunc)
	if err != nil {
		return nil, err
	}

	return labels, nil
}
477194
func (e *Endpoint) hasLabelsRLocked(l pkgLabels.Labels) bool {
	allEpLabels := e.OpLabels.AllLabels()

	for _, v := range l {
		found := false
		for _, j := range allEpLabels {
			if j.Equals(&v) {
				found = true
				break
			}
		}
		if !found {
			return false
		}
	}

	return true
}
1280159
func (a *ACLs) IsAllowed(c context.Context, host, project string) (bool, error) {
	// Convert Gerrit to Git hosts.
	if strings.HasSuffix(host, "-review.googlesource.com") {
		host = strings.TrimSuffix(host, "-review.googlesource.com") + ".googlesource.com"
	}
	hacls, configured := a.hosts[host]
	if !configured {
		return false, nil
	}
	if pacls, projKnown := hacls.projects[project]; projKnown {
		return a.belongsTo(c, hacls.readers, pacls.readers)
	}
	return a.belongsTo(c, hacls.readers)
}
736134
func (r *REST) isAllowed(user user.Info, sar *authorizationapi.SubjectAccessReview) error {
	var localSARAttributes kauthorizer.AttributesRecord
	// if they are running a personalSAR, create synthentic check for selfSAR
	if authorizer.IsPersonalAccessReviewFromSAR(sar) {
		localSARAttributes = kauthorizer.AttributesRecord{
			User:            user,
			Verb:            "create",
			Namespace:       sar.Action.Namespace,
			APIGroup:        "authorization.k8s.io",
			Resource:        "selfsubjectaccessreviews",
			ResourceRequest: true,
		}
	} else {
		localSARAttributes = kauthorizer.AttributesRecord{
			User:            user,
			Verb:            "create",
			Namespace:       sar.Action.Namespace,
			Resource:        "localsubjectaccessreviews",
			ResourceRequest: true,
		}
	}

	authorized, reason, err := r.authorizer.Authorize(localSARAttributes)

	if err != nil {
		return kapierrors.NewForbidden(authorization.Resource(localSARAttributes.GetResource()), localSARAttributes.GetName(), err)
	}
	if authorized != kauthorizer.DecisionAllow {
		forbiddenError := kapierrors.NewForbidden(authorization.Resource(localSARAttributes.GetResource()), localSARAttributes.GetName(), errors.New("") /*discarded*/)
		forbiddenError.ErrStatus.Message = reason
		return forbiddenError
	}

	return nil
}
806390
func (c *Client) DeleteLabel(ctx context.Context, l platform.Label) error {
	return c.db.Update(func(tx *bolt.Tx) error {
		return c.deleteLabel(ctx, tx, platform.LabelFilter{Name: l.Name, ResourceID: l.ResourceID})
	})
}
298759
func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
	if r.err != nil {
		return r
	}
	if s == nil {
		return r
	}
	if s.Empty() {
		return r
	}
	return r.setParam(unversioned.LabelSelectorQueryParam(r.groupVersion.String()), s.String())
}
419530
func (i *ImportRestriction) isAllowed(packageToCheck string) bool {
	// if its not under our root, then its a built-in.  Everything else is under
	// github.com/openshift/origin or github.com/openshift/origin/vendor
	if !strings.HasPrefix(packageToCheck, rootPackage) {
		return true
	}
	if i.isIncludedInRestrictedPackages(packageToCheck) {
		return true
	}

	for _, forbiddenPackageRoot := range i.ForbiddenImportPackageRoots {
		if strings.HasPrefix(forbiddenPackageRoot, "vendor") {
			forbiddenPackageRoot = rootPackage + "/" + forbiddenPackageRoot
		}
		if strings.HasPrefix(packageToCheck, forbiddenPackageRoot) {
			return false
		}
	}
	for _, allowedPackage := range i.AllowedImportPackages {
		if strings.HasPrefix(allowedPackage, "vendor") {
			allowedPackage = rootPackage + "/" + allowedPackage
		}
		if packageToCheck == allowedPackage {
			return true
		}
	}
	for _, allowedPackageRoot := range i.AllowedImportPackageRoots {
		if strings.HasPrefix(allowedPackageRoot, "vendor") {
			allowedPackageRoot = rootPackage + "/" + allowedPackageRoot
		}
		if strings.HasPrefix(packageToCheck, allowedPackageRoot) {
			return true
		}
	}

	return false
}
56533
func (h *hawkularSink) recent(live *metrics.MetricDefinition, model *metrics.MetricDefinition) bool {
	recent := true
	for k := range model.Tags {
		if v, found := live.Tags[k]; !found {
			// There's a label that wasn't in our stored definition
			live.Tags[k] = v
			recent = false
		}
	}

	return recent
}
602015
func NameIsDNS1035Label(name string, prefix bool) []string {
	if prefix {
		name = maskTrailingDash(name)
	}
	return validation.IsDNS1035Label(name)
}
1227396
func (sink *influxdbSink) checkSanitizedMetricLabels(labels map[string]string) error {
	// label names have the same restrictions as metric names, here
	for k, v := range labels {
		if !metricAllowedChars.MatchString(k) {
			return fmt.Errorf("Invalid label name %q", k)
		}

		// for metric values, we're somewhat more permissive.  We allow any
		// Printable unicode character, except quotation marks, which are used
		// to delimit things.
		if strings.ContainsRune(v, '"') || strings.ContainsRune(v, '\'') {
			return fmt.Errorf("Invalid label value %q", v)
		}

		for _, runeVal := range v {
			if !unicode.IsPrint(runeVal) {
				return fmt.Errorf("Invalid label value %q", v)
			}
		}
	}

	return nil
}
1247669
func ParseLabelArray(labels ...string) LabelArray {
	array := make(LabelArray, len(labels))
	for i := range labels {
		array[i] = ParseLabel(labels[i])
	}
	return array.Sort()
}
647901
func (l *Ladon) IsAllowed(r *Request) (err error) {
	policies, err := l.Manager.FindRequestCandidates(r)
	if err != nil {
		return err
	}

	// Although the manager is responsible of matching the policies, it might decide to just scan for
	// subjects, it might return all policies, or it might have a different pattern matching than Golang.
	// Thus, we need to make sure that we actually matched the right policies.
	return l.DoPoliciesAllow(r, policies)
}
998963
func (mw *Stats) MeasureSinceWithLabels(key string, start time.Time, labels []Label) {
	labels = append(labels, Label{"host", mw.Hostname})
	elapsed := time.Since(start)

	mw.mu.Lock()
	defer mw.mu.Unlock()

	mw.MetricsCounts[key]++
	mw.MetricsTimers[key] = mw.MetricsTimers[key].Add(elapsed)
}