// ValidEntity ensures the enpoint has valid values, does not check vhosts, public ports and assignments
481779
func (endpoint ServiceEndpoint) ValidEntity() error {
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("endpoint.Name", endpoint.Name))
	violations.Add(validation.StringIn(endpoint.Purpose, "export", "import", "import_all"))

	if endpoint.Protocol != "" {
		violations.Add(validation.StringIn(endpoint.Protocol, "tcp", "udp"))
		violations.Add(validation.ValidPort(int(endpoint.PortNumber)))
	}

	violations.Add(validation.NotEmpty("endpoint.Application", endpoint.Application))

	if violations.HasError() {
		return violations
	}
	return nil
}
801766
func (u *User) ValidEntity() error {
	trimmed := strings.TrimSpace(u.Name)
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("User.Name", u.Name))
	violations.Add(validation.StringsEqual(u.Name, trimmed, "leading and trailing spaces not allowed for user name"))

	violations.Add(validation.NotEmpty("User.Password", u.Password))

	if len(violations.Errors) > 0 {
		return violations
	}
	return nil
}
266873
func (config MetricConfig) ValidEntity() error {
	if config.ID == "metrics" {
		return fmt.Errorf("'metrics' is a reserved word")
	}

	violations := validation.NewValidationError()
	for _, m := range config.Metrics {
		if m.BuiltIn {
			violations.AddViolation(fmt.Sprintf("config %s: metric %s cannot have BuiltIn set to true", config.ID, m.ID))
		}
	}
	if violations.HasError() {
		return violations
	}
	return nil
}
1039489
func (st *ServiceTemplate) ValidEntity() error {
	//	trimmedID := strings.TrimSpace(st.ID)
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("ServiceTemplate.ID", st.ID))
	//	violations.Add(validation.StringsEqual(st.ID, trimmedID, "leading and trailing spaces not allowed for service template id"))

	//TODO: check name, description, config files.
	//TODO: do servicedefinition names need to be unique?

	//TODO: Is there any special validation if more than one top level service definition?
	for _, sd := range st.Services {
		if err := sd.ValidEntity(); err != nil {
			violations.Add(err)
		}
	}

	//keep track of seen vhosts
	vhosts := make(map[string]struct{})

	//grab the vhost from every endpoing
	visit := func(sd *servicedefinition.ServiceDefinition) error {
		for _, ep := range sd.Endpoints {
			for _, vhost := range ep.VHostList {
				if _, found := vhosts[vhost.Name]; found {
					return fmt.Errorf("duplicate vhost found: %s; ServiceDefintion %s", vhost.Name, sd)
				}
				vhosts[vhost.Name] = struct{}{}
			}
		}
		return nil
	}

	for _, sd := range st.Services {
		violations.Add(servicedefinition.Walk(&sd, visit))
	}

	if len(violations.Errors) > 0 {
		return violations
	}
	return nil
}
1342723
func ValidateEndpoints(endpoints *api.Endpoints) validation.ErrorList {
	allErrs := ValidateObjectMeta(&endpoints.ObjectMeta, true, ValidateEndpointsName, validation.NewFieldPath("metadata"))
	allErrs = append(allErrs, validateEndpointSubsets(endpoints.Subsets, validation.NewFieldPath("subsets"))...)
	return allErrs
}
1337557
func (p *ResourcePool) ValidEntity() error {

	trimmedID := strings.TrimSpace(p.ID)
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("Pool.ID", p.ID))
	violations.Add(validation.ValidPoolId(p.ID))
	violations.Add(validation.StringsEqual(p.ID, trimmedID, "leading and trailing spaces not allowed for pool id"))

	trimmedRealm := strings.TrimSpace(p.Realm)
	violations.Add(validation.NotEmpty("Pool.Realm", p.Realm))
	violations.Add(validation.StringsEqual(p.Realm, trimmedRealm, "leading and trailing spaces not allowed for pool realm"))

	if p.ConnectionTimeout < 0 {
		violations.Add(validation.NewViolation(fmt.Sprintf("connection timeout cannot be less than 0")))
	}

	if len(violations.Errors) > 0 {
		return violations
	}
	return nil
}
1208913
func (m *HttpConnectionManager_Tracing) Validate() error {
	if m == nil {
		return nil
	}

	if _, ok := HttpConnectionManager_Tracing_OperationName_name[int32(m.GetOperationName())]; !ok {
		return HttpConnectionManager_TracingValidationError{
			field:  "OperationName",
			reason: "value must be one of the defined enum values",
		}
	}

	{
		tmp := m.GetClientSampling()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return HttpConnectionManager_TracingValidationError{
					field:  "ClientSampling",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	{
		tmp := m.GetRandomSampling()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return HttpConnectionManager_TracingValidationError{
					field:  "RandomSampling",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	{
		tmp := m.GetOverallSampling()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return HttpConnectionManager_TracingValidationError{
					field:  "OverallSampling",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	// no validation rules for Verbose

	return nil
}
940258
func (m *EndpointNetworking) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateAddressing(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateHostAddressing(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
1269891
func (vrsConnection *VRSConnection) CreateEntity(info EntityInfo) error {

	if len(info.UUID) == 0 {
		return fmt.Errorf("Uuid absent")
	}

	if len(info.Name) == 0 {
		return fmt.Errorf("Name absent")
	}

	// The Nuage_VM_Table has separate columns for enterprise and user.
	// Hence make a copy of the metadata and delete these keys.
	var metadata map[string]string
	if info.Metadata != nil {
		metadata = make(map[string]string)
		for k, v := range info.Metadata {
			metadata[string(k)] = v
		}
	}
	//delete(metadata, string(entity.MetadataKeyEnterprise))
	delete(metadata, string(entity.MetadataKeyUser))

	nuageVMTableRow := ovsdb.NuageVMTableRow{
		Type:            int(info.Type),
		VMName:          info.Name,
		VMUuid:          info.UUID,
		Domain:          info.Domain,
		NuageUser:       info.Metadata[entity.MetadataKeyUser],
		NuageEnterprise: info.Metadata[entity.MetadataKeyEnterprise],
		Metadata:        metadata,
		Ports:           info.Ports,
		Event:           int(entity.EventCategoryDefined),
		EventType:       int(entity.EventDefinedAdded),
		State:           int(entity.Running),
		Reason:          int(entity.RunningUnknown),
	}

	if info.Events != nil {
		nuageVMTableRow.Event = int(info.Events.EntityEventCategory)
		nuageVMTableRow.EventType = int(info.Events.EntityEventType)
		nuageVMTableRow.State = int(info.Events.EntityState)
		nuageVMTableRow.Reason = int(info.Events.EntityReason)
	}

	if err := vrsConnection.vmTable.InsertRow(vrsConnection.ovsdbClient, &nuageVMTableRow); err != nil {
		return fmt.Errorf("Problem adding entity info to VRS %v", err)
	}

	return nil
}
1127483
func (m *EndpointChangeRequest) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateAddressing(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateLabels(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateState(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
562330
func (m *ProxyStatistics) validateLocationEnum(path, location string, value string) error {
	if err := validate.Enum(path, location, value, proxyStatisticsTypeLocationPropEnum); err != nil {
		return err
	}
	return nil
}
353320
func (r *SignonRequest) Valid(version ofxVersion) (bool, error) {
	if len(r.UserID) < 1 || len(r.UserID) > 32 {
		return false, errors.New("SONRQ>USERID invalid length")
	}
	if (len(r.UserPass) == 0) == (len(r.UserKey) == 0) {
		return false, errors.New("One and only one of SONRQ>USERPASS and USERKEY must be supplied")
	}
	if len(r.UserPass) > 32 {
		return false, errors.New("SONRQ>USERPASS invalid length")
	}
	if len(r.UserKey) > 64 {
		return false, errors.New("SONRQ>USERKEY invalid length")
	}
	if len(r.Language) == 0 {
		r.Language = "ENG"
	} else if len(r.Language) != 3 {
		return false, fmt.Errorf("SONRQ>LANGUAGE invalid length: \"%s\"", r.Language)
	}
	if len(r.AppID) < 1 || len(r.AppID) > 5 {
		return false, errors.New("SONRQ>APPID invalid length")
	}
	if len(r.AppVer) < 1 || len(r.AppVer) > 4 {
		return false, errors.New("SONRQ>APPVER invalid length")
	}
	return true, nil
}
35758
func (m *EndpointHealth) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateBpf(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateOverallHealth(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validatePolicy(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
106814
func ValidateEndpointsName(name string, prefix bool) (bool, string) {
	return NameIsDNSSubdomain(name, prefix)
}
225857
func NewEntity() (*openpgp.Entity, error) {
	name := "" // intentionally empty
	comment := "camlistore"
	email := "" // intentionally empty
	return openpgp.NewEntity(name, comment, email, nil)
}
433342
func (m *Port) validateProtocolEnum(path, location string, value string) error {
	if err := validate.Enum(path, location, value, portTypeProtocolPropEnum); err != nil {
		return err
	}
	return nil
}
1280522
func (m *Status) validateStateEnum(path, location string, value string) error {
	if err := validate.Enum(path, location, value, statusTypeStatePropEnum); err != nil {
		return err
	}
	return nil
}