// loadEntity loads an EntityProto into PropertyLoadSaver or struct pointer.
490687
func loadEntity(dst interface{}, src *pb.EntityProto) (err error) {
	props, err := protoToProperties(src)
	if err != nil {
		return err
	}
	if e, ok := dst.(PropertyLoadSaver); ok {
		return e.Load(props)
	}
	return LoadStruct(dst, props)
}
1351310
func (i *ApplicationInfo) EntityId() EntityId {
	return EntityId{
		Kind:      "application",
		ModelUUID: i.ModelUUID,
		Id:        i.Name,
	}
}
625648
func (s *Service) ValidEntity() error {

	vErr := validation.NewValidationError()
	vErr.Add(validation.NotEmpty("ID", s.ID))
	vErr.Add(validation.NotEmpty("Name", s.Name))
	vErr.Add(validation.NotEmpty("PoolID", s.PoolID))

	vErr.Add(validation.StringIn(s.Launch, commons.AUTO, commons.MANUAL))
	vErr.Add(validation.IntIn(s.DesiredState, int(SVCRun), int(SVCStop), int(SVCPause)))

	// Validate the min/max/default instances
	vErr.Add(s.InstanceLimits.Validate())
	if s.Instances != 0 {
		if s.InstanceLimits.Max != 0 {
			if s.Instances < s.InstanceLimits.Min || s.Instances > s.InstanceLimits.Max {
				vErr.Add(fmt.Errorf("Instance count (%d) must be in InstanceLimits range [%d-%d]", s.Instances, s.InstanceLimits.Min, s.InstanceLimits.Max))
			}
		} else if s.Instances < s.InstanceLimits.Min {
			vErr.Add(fmt.Errorf("Instance count (%d) must be greater than InstanceLimits min %d", s.Instances, s.InstanceLimits.Min))
		}
	}

	// validate the monitoring profile
	vErr.Add(s.MonitoringProfile.ValidEntity())

	for _, ep := range s.Endpoints {
		vErr.Add(ep.ValidEntity())
	}

	for _, hc := range s.HealthChecks {
		vErr.Add(hc.ValidEntity())
	}

	if vErr.HasError() {
		return vErr
	}
	return nil
}
245357
func (gov *Governmint) loadEntities(store base.KVStore, entityAddrs [][]byte) ([]*types.Entity, []byte) {
	entities := make([]*types.Entity, len(entityAddrs))
	for i, entityAddr := range entityAddrs {
		entity, ok := gov.GetEntity(store, entityAddr)
		if !ok {
			return nil, entityAddr
		}
		entities[i] = entity
	}
	return entities, nil
}
305784
func LoadResource(db *mgo.Database, resourceType string, id bson.ObjectId) (interface{}, error) {
	// Determine the collection expected to hold the resource
	c := db.C(GetCollectionName(resourceType))
	result := NewStructForResourceName(resourceType)
	err := c.Find(bson.M{"_id": id}).One(result)
	if err != nil {
		return nil, err
	}
	logger.Log.WithFields(logrus.Fields{"result": result}).Debug("LoadResource")
	return result, nil
}
424573
func (l *Client) GetEntityParams(entitytype, fieldname, fieldval string, fields []string, params url.Values) (*Entity, error) {
	res := ApiResp{}
	data := Entity{}
	entFields := make(map[string]interface{})
	toAppend := ""
	endpointParams := map[string]string{}

	// handle optional endpointParams
	if entitytype == "" {
		entitytype = "user"
	}

	toAppend = fmt.Sprintf("/%s", ":entitytype")
	endpointParams["entitytype"] = entitytype

	if fieldname != "" {
		toAppend = fmt.Sprintf("%s/%s", toAppend, ":fieldname")
		endpointParams["fieldname"] = fieldname

		if fieldval != "" {
			toAppend = fmt.Sprintf("%s/%s", toAppend, ":fieldval")
			endpointParams["fieldval"] = fieldval
		}
	}
	// build dynamic endpoint
	endpoint := fmt.Sprintf("%s%s", entityEndpoint, toAppend)

	// if there are also fields, add them
	if len(fields) > 0 {
		params.Add("fields", strings.Join(fields, ","))
	}

	// make the request
	entityUrl := parseLyticsURL(endpoint, endpointParams)
	err := l.Get(entityUrl, params, nil, &res, &entFields)
	if err != nil {
		return nil, err
	}
	data.Meta = res.Meta
	data.Fields = entFields
	return &data, nil
}
7483
func NewEntity(name string, publicKey, privateKey []byte) Entity {
	return Entity{Name: name, PublicKey: publicKey, PrivateKey: privateKey}
}
200372
func (s *LogStream) Load(pmap ds.PropertyMap) error {
	// Handle custom properties. Consume them before using the default
	// PropertyLoadSaver.
	for k := range pmap {
		if !strings.HasPrefix(k, "_") {
			continue
		}

		switch k {
		case "_Tags":
			// Load the tag map. Ignore errors.
			tm, _ := tagMapFromProperties(pmap.Slice(k))
			s.Tags = tm
		}
	}

	if err := ds.GetPLS(s).Load(pmap); err != nil {
		return err
	}

	// Validate the log stream. Don't enforce ID correctness, since
	// datastore hasn't populated that field yet.
	if !s.noDSValidate {
		if err := s.validateImpl(false); err != nil {
			return err
		}
	}
	return nil
}
740314
func EntityFromSecring(keyID, keyFile string) (*openpgp.Entity, error) {
	if keyID == "" {
		return nil, errors.New("empty keyID passed to EntityFromSecring")
	}
	keyID = strings.ToUpper(keyID)
	if keyFile == "" {
		keyFile = osutil.SecretRingFile()
	}
	secring, err := wkfs.Open(keyFile)
	if err != nil {
		return nil, fmt.Errorf("jsonsign: failed to open keyring: %v", err)
	}
	defer secring.Close()

	el, err := openpgp.ReadKeyRing(secring)
	if err != nil {
		return nil, fmt.Errorf("openpgp.ReadKeyRing of %q: %v", keyFile, err)
	}
	var entity *openpgp.Entity
	for _, e := range el {
		pk := e.PrivateKey
		if pk == nil || (pk.KeyIdString() != keyID && pk.KeyIdShortString() != keyID) {
			continue
		}
		entity = e
	}
	if entity == nil {
		found := []string{}
		for _, e := range el {
			pk := e.PrivateKey
			if pk == nil {
				continue
			}
			found = append(found, pk.KeyIdShortString())
		}
		return nil, fmt.Errorf("didn't find a key in %q for keyID %q; other keyIDs in file = %v", keyFile, keyID, found)
	}
	return entity, nil
}
1323048
func (s *AffectedEntity) SetEntityValue(v string) *AffectedEntity {
	s.EntityValue = &v
	return s
}
223025
func (a *AddressAssignment) ValidEntity() error {
	v := validation.NewValidationError()
	v.Add(validation.NotEmpty("ServiceID", a.ServiceID))
	v.Add(validation.NotEmpty("EndpointName", a.EndpointName))
	v.Add(validation.IsIP(a.IPAddr))
	v.Add(validation.ValidPort(int(a.Port)))
	switch a.AssignmentType {
	case commons.STATIC:
		{
			v.Add(validation.NotEmpty("HostID", a.HostID))
		}
	case commons.VIRTUAL:
		{
			v.Add(validation.NotEmpty("PoolID", a.PoolID))
		}
	default:
		return fmt.Errorf("assignment type must be static of virtual, found %v", a.AssignmentType)
	}

	if v.HasError() {
		return v
	}
	return nil
}
1173040
func (cam *CameraSystem) FollowEntity(basic *ecs.BasicEntity, space *SpaceComponent, trackRotation bool) {
	cam.tracking = cameraEntity{basic, space}
	cam.trackRotation = trackRotation
}
271564
func (c *CacheLazyFill) normaliseAndSaveEntityToDatabase(entityType, uuid string, nv *entity) error {
	// Strip name suffixes if applicable. This is intended for blue green deployments,
	// so that things like -venerable can be stripped from renamed apps
	if entityType == "apps" {
		for _, suffix := range c.config.StripAppSuffixes {
			if strings.HasSuffix(nv.Name, suffix) {
				nv.Name = nv.Name[:len(nv.Name)-len(suffix)]
				break
			}
		}
	}

	// Set TTL to value between 75% and 125% of desired amount. This is to spread out cache invalidations
	nv.TTL = time.Now().Add(time.Duration(float64(c.config.CacheInvalidateTTL.Nanoseconds()) * (0.75 + (rand.Float64() / 2.0))))

	// Write to DB
	return c.store.Set(makeCacheStorageKey(entityType, uuid), nv)
}
99201
func (m *MockInstanceMutaterState) FindEntity(arg0 names_v2.Tag) (state.Entity, error) {
	ret := m.ctrl.Call(m, "FindEntity", arg0)
	ret0, _ := ret[0].(state.Entity)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
370114
func (sh *ServiceHealth) ValidEntity() error {
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("ID", sh.ID))
	violations.Add(validation.NotEmpty("Name", sh.Name))
	violations.Add(validation.NotEmpty("PoolID", sh.PoolID))

	if len(violations.Errors) > 0 {
		return violations
	}

	return nil
}
301576
func (r *Registry) NewEntity(item mo.Entity) mo.Entity {
	e := item.Entity()
	e.Self.Value = ""
	e.Self = r.newReference(item)
	return item
}
811992
func (c *CacheLazyFill) fetchEntityFromAPI(entityType, guid string) (*entity, error) {
	var md struct {
		Entity *entity `json:"entity"`
	}
	err := c.makeRequestAndDecodeJSON(fmt.Sprintf("/v2/%s/%s", entityType, guid), &md)
	if err != nil {
		return nil, err
	}
	return md.Entity, nil
}