// claim claims model ownership on behalf of a controller, and returns
// true if the attempt succeeded.
971458
func claim(config FlagConfig) (bool, error) {
	err := config.Facade.Claim(config.Duration)
	cause := errors.Cause(err)
	switch cause {
	case nil:
		return true, nil
	case lease.ErrClaimDenied:
		return false, nil
	}
	return false, errors.Trace(err)
}
776468
func (b *PositionsService) Claim(positionId int, amount string) (Position, error) {

	request := map[string]interface{}{
		"position_id": positionId,
		"amount":      amount,
	}

	req, err := b.client.newAuthenticatedRequest("POST", "position/claim", request)

	if err != nil {
		return Position{}, err
	}

	var position = &Position{}

	_, err = b.client.do(req, position)

	if err != nil {
		return Position{}, err
	}

	return *position, nil
}
1261683
func mergeClaims(a jose.Claims, b jose.Claims) (jose.Claims, error) {
	for k, v := range b {
		_, ok := a[k]
		if !ok {
			a[k] = v
		}
	}

	return a, nil
}
508746
func (ctrl *PersistentVolumeController) deleteClaim(claim *v1.PersistentVolumeClaim) {
	_ = ctrl.claims.Delete(claim)
	klog.V(4).Infof("claim %q deleted", claimToClaimKey(claim))

	volumeName := claim.Spec.VolumeName
	if volumeName == "" {
		klog.V(5).Infof("deleteClaim[%q]: volume not bound", claimToClaimKey(claim))
		return
	}
	// sync the volume when its claim is deleted.  Explicitly sync'ing the
	// volume here in response to claim deletion prevents the volume from
	// waiting until the next sync period for its Release.
	klog.V(5).Infof("deleteClaim[%q]: scheduling sync of volume %s", claimToClaimKey(claim), volumeName)
	ctrl.volumeQueue.Add(volumeName)
}
287536
func NewClaim(orgID, ownerID, previous, pubKeyID *identity.ID, claimType ClaimType) *Claim {
	return &Claim{
		OrgID:       orgID,
		OwnerID:     ownerID,
		Previous:    previous,
		PublicKeyID: pubKeyID,
		ClaimType:   claimType,
		Created:     time.Now().UTC(),
	}
}
952803
func (s *MappingRule) SetClaim(v string) *MappingRule {
	s.Claim = &v
	return s
}
821276
func (p *OpenPrinter) ClaimPDF() ([]byte, error) {
	data, err := httpGET(&p.auth, p.register.InvitePageURL)
	if err != nil {
		return nil, fmt.Errorf("ClaimPDF: %v", err)
	}
	return data, nil
}
901805
func (c *APICache) MatchClaims(rules [][]string, claims []string) bool {

	claimsMap := map[string]struct{}{}
	for _, claim := range claims {
		claimsMap[claim] = struct{}{}
	}

	var matched int
	for _, clause := range rules {
		matched = len(clause)
		for _, claim := range clause {
			if _, ok := claimsMap[claim]; ok {
				matched--
			}
			if matched == 0 {
				return true
			}
		}
	}
	return false
}
1061095
func (c *client) ClaimLeadership(appId, unitId string, duration time.Duration) error {

	results, err := c.bulkClaimLeadership(c.prepareClaimLeadership(appId, unitId, duration))
	if err != nil {
		return err
	}

	// TODO(fwereade): this is not a rightful panic; we don't know who'll be using
	// this client, and/or whether or not we're running critical code in the same
	// process.
	if err := results.Results[0].Error; err != nil {
		if params.IsCodeLeadershipClaimDenied(err) {
			return leadership.ErrClaimDenied
		}
		return err
	}
	return nil
}
752191
func (s *backendShim) ModelOwner() (names.UserTag, error) {
	model, err := s.Model()
	if err != nil {
		return names.UserTag{}, errors.Trace(err)
	}
	return model.Owner(), nil
}
116735
func (m *Model) IsControllerModel() bool {
	return m.st.controllerModelTag.Id() == m.doc.UUID
}
249121
func Get(r *http.Request) (claims map[string]interface{}, ok bool) {
	c, ok := context.GetOk(r, context_key)
	if !ok {
		return claims, ok
	}
	claims, castOk := c.(map[string]interface{})
	return claims, castOk
}
695019
func (p *RBACPolicyEnforcer) EnforceClaims(claims jwt.Claims, rvals ...interface{}) bool {
	mapClaims, err := jwtutil.MapClaims(claims)
	if err != nil {
		return false
	}

	subject := jwtutil.GetField(mapClaims, "sub")
	// Check if the request is for an application resource. We have special enforcement which takes
	// into consideration the project's token and group bindings
	var runtimePolicy string
	proj := p.getProjectFromRequest(rvals...)
	if proj != nil {
		if strings.HasPrefix(subject, "proj:") {
			return p.enforceProjectToken(subject, mapClaims, proj, rvals...)
		}
		runtimePolicy = proj.ProjectPoliciesString()
	}

	// Check the subject. This is typically the 'admin' case.
	// NOTE: the call to EnforceRuntimePolicy will also consider the default role
	vals := append([]interface{}{subject}, rvals[1:]...)
	if p.enf.EnforceRuntimePolicy(runtimePolicy, vals...) {
		return true
	}

	// Finally check if any of the user's groups grant them permissions
	groups := jwtutil.GetGroups(mapClaims)
	for _, group := range groups {
		vals := append([]interface{}{group}, rvals[1:]...)
		if p.enf.EnforceRuntimePolicy(runtimePolicy, vals...) {
			return true
		}
	}
	logCtx := log.WithField("claims", claims).WithField("rval", rvals)
	logCtx.Debug("enforce failed")
	return false
}
871760
func (ctx *facadeContext) LeadershipClaimer(modelUUID string) (leadership.Claimer, error) {
	if ctx.r.shared.featureEnabled(feature.LegacyLeases) {
		if modelUUID != ctx.State().ModelUUID() {
			return nil, errors.Errorf("can't get leadership claimer for different model with legacy lease manager")
		}
		return ctx.State().LeadershipClaimer(), nil
	}
	claimer, err := ctx.r.shared.leaseManager.Claimer(
		lease.ApplicationLeadershipNamespace,
		modelUUID,
	)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return leadershipClaimer{claimer}, nil
}
366983
func (cgi *ConsumergroupInstance) ClaimPartition(topic string, partition int32) error {
	root := fmt.Sprintf("%s/consumers/%s/owners/%s", cgi.cg.kz.conf.Chroot, cgi.cg.Name, topic)
	if err := cgi.cg.kz.mkdirRecursive(root); err != nil {
		return err
	}

	// Create an ephemeral node for the partition to claim the partition for this instance
	node := fmt.Sprintf("%s/%d", root, partition)
	err := cgi.cg.kz.create(node, []byte(cgi.ID), true)
	switch err {
	case zk.ErrNodeExists:
		data, _, err := cgi.cg.kz.conn.Get(node)
		if err != nil {
			return err
		}
		if string(data) != cgi.ID {
			// Return a separate error for this, to allow for implementing a retry mechanism.
			return ErrPartitionClaimedByOther
		}
		return nil
	default:
		return err
	}
}
230477
func Claim(nodeAvailableResources, taskAssigned *[]*api.GenericResource,
	taskReservations []*api.GenericResource) error {
	var resSelected []*api.GenericResource

	for _, res := range taskReservations {
		tr := res.GetDiscreteResourceSpec()
		if tr == nil {
			return fmt.Errorf("task should only hold Discrete type")
		}

		// Select the resources
		nrs, err := selectNodeResources(*nodeAvailableResources, tr)
		if err != nil {
			return err
		}

		resSelected = append(resSelected, nrs...)
	}

	ClaimResources(nodeAvailableResources, taskAssigned, resSelected)
	return nil
}
255839
func (x *Claim) UnmarshalJSON(data []byte) (err error) {
	x2 := claim{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = Claim(x2)
		return x.checkResourceType()
	}
	return
}