//ValidEntity makes sure all serviceTemplateWrapper have non-empty values
486171
func (st *serviceTemplateWrapper) ValidEntity() error {

	v := validation.NewValidationError()
	v.Add(validation.NotEmpty("ID", st.ID))
	v.Add(validation.NotEmpty("Name", st.Name))
	v.Add(validation.NotEmpty("Data", st.Data))
	if v.HasError() {
		return v
	}
	return nil
}
1047675
func (sd *ServiceDefinition) validate(context *validationContext) error {
	//TODO: check name, description, config files.

	//Check MinMax settings
	if err := sd.Instances.Validate(); err != nil {
		return fmt.Errorf("service Definition %v: %v", sd.Name, err)
	}

	if err := validation.StringIn(sd.Launch, commons.AUTO, commons.MANUAL); err != nil {
		return fmt.Errorf("service definition %v: invalid launch setting %v", sd.Name, err)
	}

	//validate endpoint config
	names := make(map[string]struct{})
	for _, se := range sd.Endpoints {
		if err := se.ValidEntity(); err != nil {
			return fmt.Errorf("service definition %v: %v", sd.Name, err)
		}
		if err := context.validateVHost(se); err != nil {
			return fmt.Errorf("service definition %v: %v", sd.Name, err)
		}
		//enable unique endpoint name validation
		trimName := strings.Trim(se.Name, " ")
		if _, found := names[trimName]; found {
			return fmt.Errorf("service definition %v: Endpoint name %s not unique in service definition", sd.Name, trimName)
		}
		names[trimName] = struct{}{}
	}
	//TODO: validate LogConfigs

	// validate Monitoring Profile
	if err := sd.MonitoringProfile.ValidEntity(); err != nil {
		return fmt.Errorf("service definition %v: invalid monitoring profile %s", sd.Name, err)
	}

	return validServiceDefinitions(&sd.Services, context)
}
441428
func (s *TemplateService) RegisterTemplate(p *RegisterTemplateParams) (*RegisterTemplateResponse, error) {
	resp, err := s.cs.newRequest("registerTemplate", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r RegisterTemplateResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
248053
func (h *Host) ValidEntity() error {
	//if err := validation.ValidHostID(entity.ID); err != nil {
	//	return fmt.Errorf("invalid hostid:'%s' for host Name:'%s' IP:%s", entity.ID, entity.Name, entity.IPAddr)
	//}

	trimmedID := strings.TrimSpace(h.ID)
	violations := validation.NewValidationError()
	violations.Add(validation.NotEmpty("Host.ID", h.ID))
	violations.Add(validation.ValidHostID(h.ID))
	violations.Add(validation.StringsEqual(h.ID, trimmedID, "leading and trailing spaces not allowed for host id"))
	violations.Add(validation.ValidPort(h.RPCPort))
	violations.Add(validation.NotEmpty("Host.PoolID", h.PoolID))
	violations.Add(validation.IsIP(h.IPAddr))

	//TODO: what should we be validating here? It doesn't seem to work for
	ipAddr, err := net.ResolveIPAddr("ip4", h.IPAddr)
	if err != nil {
		violations.Add(err)
	} else if ipAddr.IP.IsLoopback() {
		violations.Add(errors.New("host ip can not be a loopback address"))

	}
	if _, err := GetRAMLimit(h.RAMLimit, h.Memory); err == ErrSizeTooBig {
		h.RAMLimit = fmt.Sprintf("%d", h.Memory)
	} else if err != nil {
		violations.Add(err)
	}
	if len(violations.Errors) > 0 {
		return violations
	}
	return nil
}
912656
func (c *Config) validateVMXTemplatePath() error {
	f, err := os.Open(c.VMXTemplatePath)
	if err != nil {
		return err
	}
	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return err
	}

	return interpolate.Validate(string(data), &c.ctx)
}
56122
func serviceFromTemplate(template *templateapiv1.Template) *api.Service {
	metadata := make(map[string]interface{})
	for srcname, dstname := range annotationMap {
		if value, ok := template.Annotations[srcname]; ok {
			metadata[dstname] = value
		}
	}

	properties := map[string]*jsschema.Schema{}
	paramOrdering := []string{}
	required := []string{}
	for _, param := range template.Parameters {
		properties[param.Name] = &jsschema.Schema{
			Title:       param.DisplayName,
			Description: param.Description,
			Default:     param.Value,
			Type:        []jsschema.PrimitiveType{jsschema.StringType},
		}
		if param.Required && param.Generate == "" {
			required = append(required, param.Name)
		}
		paramOrdering = append(paramOrdering, param.Name)
	}

	bindable := strings.ToLower(template.Annotations[templateapi.BindableAnnotation]) != "false"

	plan := api.Plan{
		ID:          string(template.UID), // TODO: this should be a unique value
		Name:        "default",
		Description: "Default plan",
		Free:        true,
		Bindable:    bindable,
		Schemas: api.Schema{
			ServiceInstance: api.ServiceInstances{
				Create: map[string]*jsschema.Schema{
					"parameters": {
						SchemaRef:  jsschema.SchemaURL,
						Type:       []jsschema.PrimitiveType{jsschema.ObjectType},
						Properties: properties,
						Required:   required,
					},
				},
			},
			ServiceBinding: api.ServiceBindings{
				Create: map[string]*jsschema.Schema{
					"parameters": {
						SchemaRef:  jsschema.SchemaURL,
						Type:       []jsschema.PrimitiveType{jsschema.ObjectType},
						Properties: map[string]*jsschema.Schema{},
						Required:   []string{},
					},
				},
			},
		},
	}

	// This metadata ensures the template parameters are displayed in the
	// service catalog in the same order as they are defined in the template.
	plan.Metadata = make(map[string]interface{})
	plan.Metadata["schemas"] = api.ParameterSchemas{
		ServiceInstance: api.ParameterSchema{
			Create: api.OpenShiftMetadata{
				OpenShiftFormDefinition: paramOrdering,
			},
		},
	}

	description := template.Annotations["description"]
	if description == "" {
		description = noDescriptionProvided
	}

	return &api.Service{
		Name:        template.Name,
		ID:          string(template.UID),
		Description: description,
		Tags:        strings.Split(template.Annotations["tags"], ","),
		Bindable:    bindable,
		Metadata:    metadata,
		Plans:       []api.Plan{plan},
	}
}
285417
func (s *IndicesExistsTemplateService) Validate() error {
	var invalid []string
	if s.name == "" {
		invalid = append(invalid, "Name")
	}
	if len(invalid) > 0 {
		return fmt.Errorf("missing required fields: %v", invalid)
	}
	return nil
}
682291
func (p *Provision) ValidateInitialization() error {
	if p.namespaceLister == nil {
		return fmt.Errorf("missing namespaceLister")
	}
	if p.client == nil {
		return fmt.Errorf("missing client")
	}
	return nil
}
1020369
func (profile MonitorProfile) ValidEntity() error {
	violations := validation.NewValidationError()
	for _, mc := range profile.MetricConfigs {
		violations.Add(mc.ValidEntity())
	}
	for _, gc := range profile.GraphConfigs {
		violations.Add(gc.ValidEntity())
	}

	if violations.HasError() {
		return violations
	}
	return nil
}
193968
func (NoDoubleKeySchema) ValidateBytes(data []byte) error {
	var list []error
	if err := validateNoDuplicateKeys(data, "metadata", "labels"); err != nil {
		list = append(list, err)
	}
	if err := validateNoDuplicateKeys(data, "metadata", "annotations"); err != nil {
		list = append(list, err)
	}
	return utilerrors.NewAggregate(list)
}
129325
func isValidReqResType(t reflect.Type) bool {
	return (t == _interfaceEmptyType) ||
		(t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct) ||
		(t.Kind() == reflect.Map && t.Key().Kind() == reflect.String)
}
1088132
func (a *api) GetServiceTemplate(id string) (*template.ServiceTemplate, error) {
	client, err := a.connectMaster()
	if err != nil {
		return nil, err
	}

	templateMap, err := client.GetServiceTemplates()
	if err != nil {
		return nil, err
	}

	if _, ok := templateMap[id]; !ok {
		return nil, fmt.Errorf("unable to find template by id: %s", id)
	}
	t := templateMap[id]
	t.ID = id

	return &t, nil
}
666002
func ValidateServiceLB(obj *ServiceLB) error {
	collections.serviceLBMutex.Lock()
	defer collections.serviceLBMutex.Unlock()

	// Validate key is correct
	keyStr := obj.TenantName + ":" + obj.ServiceName
	if obj.Key != keyStr {
		log.Errorf("Expecting ServiceLB Key: %s. Got: %s", keyStr, obj.Key)
		return errors.New("Invalid Key")
	}

	// Validate each field

	if len(obj.IpAddress) > 15 {
		return errors.New("ipAddress string too long")
	}

	ipAddressMatch := regexp.MustCompile("^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})?$")
	if ipAddressMatch.MatchString(obj.IpAddress) == false {
		return errors.New("ipAddress string invalid format")
	}

	if len(obj.NetworkName) > 64 {
		return errors.New("networkName string too long")
	}

	networkNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if networkNameMatch.MatchString(obj.NetworkName) == false {
		return errors.New("networkName string invalid format")
	}

	if len(obj.ServiceName) > 256 {
		return errors.New("serviceName string too long")
	}

	serviceNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if serviceNameMatch.MatchString(obj.ServiceName) == false {
		return errors.New("serviceName string invalid format")
	}

	if len(obj.TenantName) > 64 {
		return errors.New("tenantName string too long")
	}

	tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if tenantNameMatch.MatchString(obj.TenantName) == false {
		return errors.New("tenantName string invalid format")
	}

	return nil
}
557240
func ValidateRoleBindingSubject(subject rbac.Subject, isNamespaced bool, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}

	if len(subject.Name) == 0 {
		allErrs = append(allErrs, field.Required(fldPath.Child("name"), ""))
	}

	switch subject.Kind {
	case rbac.ServiceAccountKind:
		if len(subject.Name) > 0 {
			for _, msg := range validation.ValidateServiceAccountName(subject.Name, false) {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), subject.Name, msg))
			}
		}
		if len(subject.APIGroup) > 0 {
			allErrs = append(allErrs, field.NotSupported(fldPath.Child("apiGroup"), subject.APIGroup, []string{""}))
		}
		if !isNamespaced && len(subject.Namespace) == 0 {
			allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), ""))
		}

	case rbac.UserKind:
		// TODO(ericchiang): What other restrictions on user name are there?
		if subject.APIGroup != rbac.GroupName {
			allErrs = append(allErrs, field.NotSupported(fldPath.Child("apiGroup"), subject.APIGroup, []string{rbac.GroupName}))
		}

	case rbac.GroupKind:
		// TODO(ericchiang): What other restrictions on group name are there?
		if subject.APIGroup != rbac.GroupName {
			allErrs = append(allErrs, field.NotSupported(fldPath.Child("apiGroup"), subject.APIGroup, []string{rbac.GroupName}))
		}

	default:
		allErrs = append(allErrs, field.NotSupported(fldPath.Child("kind"), subject.Kind, []string{rbac.ServiceAccountKind, rbac.UserKind, rbac.GroupKind}))
	}

	return allErrs
}
841934
func (s *StoredProperties) ValidEntity() error {
	violations := validation.NewValidationError()
	if s.Props == nil {
		violations.AddViolation("Props is nil")
	}

	if v, ok := s.CCVersion(); !ok || v == "" {
		violations.AddViolation("CCVersion is not set")
	}
	if violations.HasError() {
		return violations
	}
	return nil
}
849547
func (s *Server) AddServiceTemplate(serviceTemplate servicetemplate.ServiceTemplate, response *string) error  {
	reloadLogstashConfig := true
	templateID, err := s.f.AddServiceTemplate(s.context(), serviceTemplate, reloadLogstashConfig)
	if err != nil {
		return err
	}
	*response = templateID
	return nil
}
233670
func (s *IndicesPutTemplateService) Validate() error {
	var invalid []string
	if s.name == "" {
		invalid = append(invalid, "Name")
	}
	if s.bodyString == "" && s.bodyJson == nil {
		invalid = append(invalid, "BodyJson")
	}
	if len(invalid) > 0 {
		return fmt.Errorf("missing required fields: %v", invalid)
	}
	return nil
}