//validateVHost ensures that the VHosts in a ServiceEndpoint have not already been defined
421776
func (vc validationContext) validateVHost(se EndpointDefinition) error {
	if len(se.VHostList) > 0 {
		for _, vhost := range se.VHostList {
			if _, found := vc.vhosts[vhost.Name]; found {
				return fmt.Errorf("duplicate VHost found: %v", vhost.Name)
			}
			vc.vhosts[vhost.Name] = se
		}
	}
	return nil
}
921251
func (p CassandraPlugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValueDefault("host", "")
	if err != nil {
		fmt.Printf("@R{\u2717 host          %s}\n", err)
		fail = true
	} else if s == "" {
		fmt.Printf("@G{\u2713 host}          using default node @C{%s}\n", DefaultHost)
	} else {
		fmt.Printf("@G{\u2713 host}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("port", "")
	if err != nil {
		fmt.Printf("@R{\u2717 port          %s}\n", err)
		fail = true
	} else if s == "" {
		fmt.Printf("@G{\u2713 port}          using default port @C{%s}\n", DefaultPort)
	} else {
		fmt.Printf("@G{\u2713 port}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("user", "")
	if err != nil {
		fmt.Printf("@R{\u2717 user          %s}\n", err)
		fail = true
	} else if s == "" {
		fmt.Printf("@G{\u2713 user}          using default user @C{%s}\n", DefaultUser)
	} else {
		fmt.Printf("@G{\u2713 user}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("password", "")
	if err != nil {
		fmt.Printf("@R{\u2717 password      %s}\n", err)
		fail = true
	} else if s == "" {
		fmt.Printf("@G{\u2713 password}      using default password @C{%s}\n", DefaultPassword)
	} else {
		fmt.Printf("@G{\u2713 password}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("keyspace")
	if err != nil {
		fmt.Printf("@R{\u2717 keyspace      %s}\n", err)
		fail = true
	} else {
		fmt.Printf("@G{\u2713 keyspace}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("datadir", "")
	if err != nil {
		fmt.Printf("@R{\u2717 datadir       %s}\n", err)
		fail = true
	} else if s == "" {
		fmt.Printf("@G{\u2713 datadir}       using default @C{%s}\n", DefaultDataDir)
	} else {
		fmt.Printf("@G{\u2713 datadir}       @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("cassandra: invalid configuration")
	}
	return nil
}
1137199
func (f *Facade) validateServiceMigration(ctx datastore.Context, svcs []service.Service, tenantID string) error {
	svcParentMapNameMap := make(map[string]map[string]struct{})
	endpointMap := make(map[string]string)
	for _, svc := range svcs {
		// check for name uniqueness within the set of new/modified/deployed services
		if svcNameMap, ok := svcParentMapNameMap[svc.ParentServiceID]; ok {
			if _, ok := svcNameMap[svc.Name]; ok {
				glog.Errorf("Found a collision for service name %s and parent %s", svc.Name, svc.ParentServiceID)
				return ErrServiceCollision
			}
			svcParentMapNameMap[svc.ParentServiceID][svc.Name] = struct{}{}
		} else {
			svcParentMapNameMap[svc.ParentServiceID] = make(map[string]struct{})
		}

		// check for endpoint name uniqueness within the set of new/modified/deployed services
		for _, ep := range svc.Endpoints {
			if ep.Purpose == "export" {
				if _, ok := endpointMap[ep.Application]; ok {
					glog.Errorf("Endpoint %s in migrated service %s is a duplicate of an endpoint in one of the other migrated services", ep.Application, svc.Name)
					return ErrServiceDuplicateEndpoint
				}
				endpointMap[ep.Application] = svc.ID
			}
		}
	}

	// check for endpoint name uniqueness btwn the migrated service and the services already defined in
	// the parent application.
	alleps, err := f.GetServiceExportedEndpoints(ctx, tenantID, true)
	if err != nil {
		glog.Errorf("Error looking up exported endpoints for tenant %s: %s", tenantID, err)
		return err
	}
	for _, ep := range alleps {
		if _, ok := endpointMap[ep.Application]; ok {
			if ep.ServiceID != endpointMap[ep.Application] {
				glog.Errorf("Endpoint %s in migrated service is a duplicate of an endpoint already in the application", ep.Application)
				return ErrServiceDuplicateEndpoint
			}
		}
	}

	return nil
}
109018
func ValidateExtraHost(val string) (string, error) {
	// allow for IPv6 addresses in extra hosts by only splitting on first ":"
	arr := strings.SplitN(val, ":", 2)
	if len(arr) != 2 || len(arr[0]) == 0 {
		return "", fmt.Errorf("bad format for add-host: %q", val)
	}
	if _, err := ValidateIPAddress(arr[1]); err != nil {
		return "", fmt.Errorf("invalid IP address in add-host: %q", arr[1])
	}
	return val, nil
}
413451
func isValidHostURL(hostURL string) (ok bool) {
	if strings.TrimSpace(hostURL) != "" {
		url := newClientURL(hostURL)
		if url.Scheme == "https" || url.Scheme == "http" {
			if url.Path == "/" {
				ok = true
			}
		}
	}
	return ok
}
115376
func (s *Service) AddVirtualHost(application, vhostName string, isEnabled bool) (*servicedefinition.VHost, error) {
	if s.Endpoints != nil {

		//find the matching endpoint
		for i := range s.Endpoints {
			ep := &s.Endpoints[i]

			if ep.Application == application && ep.Purpose == "export" {
				_vhostName := strings.ToLower(vhostName)
				vhosts := make([]servicedefinition.VHost, 0)
				for _, vhost := range ep.VHostList {
					if strings.ToLower(vhost.Name) != _vhostName {
						vhosts = append(vhosts, vhost)
					}
				}
				vhost := &servicedefinition.VHost{Name: _vhostName, Enabled: isEnabled}
				ep.VHostList = append(vhosts, *vhost)
				return vhost, nil
			}
		}
	}

	return nil, fmt.Errorf("unable to find application %s in service: %s", application, s.Name)
}
1133769
func (s *Service) EnableVirtualHost(application, vhostName string, enable bool) error {
	appFound := false
	vhostFound := false
	for _, ep := range s.GetServiceVHosts() {
		if ep.Application == application {
			appFound = true
			for i, vhost := range ep.VHostList {
				if vhost.Name == vhostName {
					vhostFound = true
					ep.VHostList[i].Enabled = enable
					plog.WithFields(log.Fields{
						"vhostname":   vhostName,
						"serviceid":   s.ID,
						"application": application,
						"enable":      enable,
					}).Debug("Enable vhost")
				}
			}
		}
	}
	if !appFound {
		return fmt.Errorf("vhost %s not found; application %s not found in service %s:%s", vhostName, application, s.ID, s.Name)
	}
	if !vhostFound {
		return fmt.Errorf("vhost %s not found in service %s:%s", vhostName, s.ID, s.Name)
	}

	return nil
}
117755
func (c *Client) ListVhosts() (rec []VhostInfo, err error) {
	req, err := newGETRequest(c, "vhosts")
	if err != nil {
		return []VhostInfo{}, err
	}

	if err = executeAndParseRequest(c, req, &rec); err != nil {
		return []VhostInfo{}, err
	}

	return rec, nil
}
178781
func ValidateHost(val string) (string, error) {
	host := strings.TrimSpace(val)
	// The empty string means default and is not handled by parseDaemonHost
	if host != "" {
		_, err := parseDaemonHost(host)
		if err != nil {
			return val, err
		}
	}
	// Note: unlike most flag validators, we don't return the mutated value here
	//       we need to know what the user entered later (using ParseHost) to adjust for TLS
	return val, nil
}
925301
func (s ServiceCommonGeneratorV1) validate() error {
	if len(s.Name) == 0 {
		return fmt.Errorf("name must be specified")
	}
	if len(s.Type) == 0 {
		return fmt.Errorf("type must be specified")
	}
	if s.ClusterIP == v1.ClusterIPNone && s.Type != v1.ServiceTypeClusterIP {
		return fmt.Errorf("ClusterIP=None can only be used with ClusterIP service type")
	}
	if s.ClusterIP != v1.ClusterIPNone && len(s.TCP) == 0 && s.Type != v1.ServiceTypeExternalName {
		return fmt.Errorf("at least one tcp port specifier must be provided")
	}
	if s.Type == v1.ServiceTypeExternalName {
		if errs := validation.IsDNS1123Subdomain(s.ExternalName); len(errs) != 0 {
			return fmt.Errorf("invalid service external name %s", s.ExternalName)
		}
	}
	return nil
}
483922
func validateVM(vm *VM) error {
	// Validate the OAUTH Credentials
	if vm.Creds.ClientID == "" {
		return fmt.Errorf("a client id must be specified")
	}

	if vm.Creds.ClientSecret == "" {
		return fmt.Errorf("a client secret must be specified")
	}

	if vm.Creds.TenantID == "" {
		return fmt.Errorf("a tenant id must be specified")
	}

	if vm.Creds.SubscriptionID == "" {
		return fmt.Errorf("a subscription id must be specified")
	}

	// Validate the image
	if vm.ImagePublisher == "" {
		return fmt.Errorf("an image publisher must be specified")
	}

	if vm.ImageOffer == "" {
		return fmt.Errorf("an image offer must be specified")
	}

	if vm.ImageSku == "" {
		return fmt.Errorf("an image sku must be specified")
	}

	// Validate the deployment
	if vm.ResourceGroup == "" {
		return fmt.Errorf("a resource group must be specified")
	}

	if vm.StorageAccount == "" {
		return fmt.Errorf("a storage account must be specified")
	}

	// Validate the network
	if vm.NetworkSecurityGroup == "" {
		return fmt.Errorf("a network security group must be specified")
	}

	if vm.Subnet == "" {
		return fmt.Errorf("a subnet must be specified")
	}

	if vm.VirtualNetwork == "" {
		return fmt.Errorf("a virtual network must be specified")
	}

	return nil
}
1020996
func ValidateEndpoints(endpoints *core.Endpoints) field.ErrorList {
	allErrs := ValidateObjectMeta(&endpoints.ObjectMeta, true, ValidateEndpointsName, field.NewPath("metadata"))
	allErrs = append(allErrs, ValidateEndpointsSpecificAnnotations(endpoints.Annotations, field.NewPath("annotations"))...)
	allErrs = append(allErrs, validateEndpointSubsets(endpoints.Subsets, field.NewPath("subsets"))...)
	return allErrs
}
1242079
func validateVMForCreation(v *crimson.VM) error {
	switch {
	case v == nil:
		return status.Error(codes.InvalidArgument, "VM specification is required")
	case v.Name == "":
		return status.Error(codes.InvalidArgument, "hostname is required and must be non-empty")
	case v.Vlan != 0:
		return status.Error(codes.InvalidArgument, "VLAN must not be specified, use IP address instead")
	case v.Host == "":
		return status.Error(codes.InvalidArgument, "physical hostname is required and must be non-empty")
	case v.HostVlan != 0:
		return status.Error(codes.InvalidArgument, "host VLAN must not be specified, use physical hostname instead")
	case v.Os == "":
		return status.Error(codes.InvalidArgument, "operating system is required and must be non-empty")
	case v.Ipv4 == "":
		return status.Error(codes.InvalidArgument, "IPv4 address is required and must be non-empty")
	case v.State == states.State_STATE_UNSPECIFIED:
		return status.Error(codes.InvalidArgument, "state is required")
	default:
		_, err := common.ParseIPv4(v.Ipv4)
		if err != nil {
			return status.Errorf(codes.InvalidArgument, "invalid IPv4 address %q", v.Ipv4)
		}
		return nil
	}
}
1325313
func (s Service) Validate(renderer shell.Renderer) error {
	if s.Name == "" {
		return errors.New("missing Name")
	}

	if err := s.Conf.Validate(renderer); err != nil {
		return errors.Trace(err)
	}

	return nil
}
292221
func (endpointsStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
	allErrs := validation.ValidateEndpoints(obj.(*api.Endpoints))
	allErrs = append(allErrs, validation.ValidateConditionalEndpoints(obj.(*api.Endpoints), nil)...)
	return allErrs
}
744910
func (m *EndpointPolicy) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
227017
func (s *StreamAddr) Validate() error {
	if s.Host == "" {
		return errors.New("cannot have empty Host")
	}
	if err := s.Project.Validate(); err != nil {
		return err
	}
	if err := s.Path.Validate(); err != nil {
		return err
	}
	return nil
}