// leaseDocId returns the id of the named lease document in the store's
// namespace.
425233
func (store *store) leaseDocId(name string) string {
	return leaseDocId(store.config.Namespace, name)
}
40338
func (v *version) Leases() LeaseInformer {
	return &leaseInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
611736
func (j *Job) NamespacedID() *NamespacedID {
	return &NamespacedID{
		ID:        j.ID,
		Namespace: j.Namespace,
	}
}
966865
func (s *CreateServiceInput) SetNamespaceId(v string) *CreateServiceInput {
	s.NamespaceId = &v
	return s
}
1103842
func (s *Store) Leases(keys ...lease.Key) map[lease.Key]lease.Info {
	leaseMap := s.fsm.Leases(s.config.Clock.Now, keys...)
	// Add trapdoors into the information from the FSM.
	for k, v := range leaseMap {
		v.Trapdoor = s.config.Trapdoor(k, v.Holder)
		leaseMap[k] = v
	}
	return leaseMap
}
989012
func (m Map) LeaseByClusterName(clusterName string) (*Lease, bool) {
	u, ok := m.nameMap[clusterName]
	if !ok {
		return nil, false
	}
	l, ok := m.uuidMap[u.String()]
	if !ok {
		return nil, false
	}
	return l, true
}
988654
func LeasePool(p leasepool.LeasePool) func(*Server) error {
	return func(s *Server) error {
		s.leasePool = p
		return nil
	}
}
1074680
func (c *Client) NamespaceService() namespaces.Store {
	if c.namespaceStore != nil {
		return c.namespaceStore
	}
	c.connMu.Lock()
	defer c.connMu.Unlock()
	return NewNamespaceStoreFromClient(namespacesapi.NewNamespacesClient(c.conn))
}
230222
func (doc leaseHolderDoc) validate() error {
	if doc.Id != leaseHolderDocId(doc.Namespace, doc.ModelUUID, doc.Lease) {
		return errors.Errorf("inconsistent _id")
	}
	if err := lease.ValidateString(doc.Holder); err != nil {
		return errors.Annotatef(err, "invalid holder")
	}
	return nil
}
1352623
func (c Config) HostUID(containerId int) (int, error) {
	if c.Namespaces.Contains(NEWUSER) {
		if c.UidMappings == nil {
			return -1, fmt.Errorf("User namespaces enabled, but no uid mappings found.")
		}
		id, found := c.hostIDFromMapping(containerId, c.UidMappings)
		if !found {
			return -1, fmt.Errorf("User namespaces enabled, but no user mapping found.")
		}
		return id, nil
	}
	// Return unchanged id.
	return containerId, nil
}
1367301
func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, int, error) {
	p := &ListDomainsParams{}
	p.p = make(map[string]interface{})

	p.p["name"] = name

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListDomains(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
	}

	if l.Count == 1 {
		return l.Domains[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.Domains {
			if v.Name == name {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
246953
func (c *Client) GetTenantID(serviceID string) (string, error) {
	tenantID := ""
	err := c.call("GetTenantID", serviceID, &tenantID)
	return tenantID, err
}
856791
func LookupLease(coll mongo.Collection, namespace, name string) (leaseDoc, error) {
	var doc leaseDoc
	err := coll.FindId(leaseDocId(namespace, name)).One(&doc)
	if err != nil {
		return leaseDoc{}, err
	}
	return doc, nil
}
815782
func (store *store) ExpireLease(key lease.Key) error {
	name := key.Lease
	if err := lease.ValidateString(name); err != nil {
		return errors.Annotatef(err, "invalid name")
	}

	store.mu.Lock()
	defer store.mu.Unlock()

	// No cache updates needed, only deletes; no closure here.
	err := store.config.Mongo.RunTransaction(func(attempt int) ([]txn.Op, error) {
		store.logger.Tracef("expiring lease %q (attempt %d)", name, attempt)

		// On the first attempt, assume cache is good.
		if attempt > 0 {
			if err := store.refresh(false); err != nil {
				return nil, errors.Trace(err)
			}
		}

		// No special error handling here.
		ops, err := store.expireLeaseOps(name)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return ops, nil
	})

	if err != nil {
		if errors.Cause(err) == lease.ErrInvalid {
			return lease.ErrInvalid
		}
		return errors.Trace(err)
	}

	// Uncache this lease entry.
	delete(store.entries, name)
	return nil
}
866930
func (mc MongoClient) ValueDescriptorById(id string) (contract.ValueDescriptor, error) {
	query, err := idToBsonM(id)
	if err != nil {
		return contract.ValueDescriptor{}, err
	}

	mvd, err := mc.getValueDescriptor(query)
	if err != nil {
		return contract.ValueDescriptor{}, err
	}
	return mvd.ToContract(), nil
}
738634
func (store *store) Leases(keys ...lease.Key) map[lease.Key]lease.Info {
	cfg := store.config
	limit := set.NewStrings()

	// Do a single pass over the keys for model and namespace.
	// This lets us use a set for filtering on lease name when we iterate
	// over the collection of leases.
	filtering := len(keys) > 0
	if filtering {
		for _, key := range keys {
			if key.Namespace == cfg.Namespace && key.ModelUUID == cfg.ModelUUID {
				limit.Add(key.Lease)
			}
		}
	}

	store.mu.Lock()
	localTime := store.config.LocalClock.Now()
	leases := make(map[lease.Key]lease.Info)
	for name, entry := range store.entries {
		if filtering && !limit.Contains(name) {
			continue
		}

		globalExpiry := entry.start.Add(entry.duration)
		remaining := globalExpiry.Sub(store.globalTime)
		localExpiry := localTime.Add(remaining)
		key := lease.Key{
			Namespace: store.config.Namespace,
			ModelUUID: store.config.ModelUUID,
			Lease:     name,
		}
		leases[key] = lease.Info{
			Holder:   entry.holder,
			Expiry:   localExpiry,
			Trapdoor: store.assertOpTrapdoor(name, entry.holder),
		}
	}
	defer store.mu.Unlock()

	return leases
}
1246412
func (c *CAClientImpl) GetIdentity(id, caname string) (*api.IdentityResponse, error) {

	if c.adapter == nil {
		return nil, fmt.Errorf("no CAs configured for organization: %s", c.orgName)
	}

	// Checke required parameters (ID and affiliation)
	if id == "" {
		return nil, errors.New("id is required")
	}

	registrar, err := c.getRegistrar(c.registrar.EnrollID, c.registrar.EnrollSecret)
	if err != nil {
		return nil, err
	}

	return c.adapter.GetIdentity(registrar.PrivateKey(), registrar.EnrollmentCertificate(), id, caname)
}