// validName returns true if s is valid domain name and shorter than 256 characters.
168945
func validName(s string) bool {
	_, ok := dns.IsDomainName(s)
	if !ok {
		return false
	}
	if len(dns.Name(s).String()) > 255 {
		return false
	}

	return true
}
667207
func (c *Config) Valid() error {
	if c.Security.SkipGrantTable && !hasRootPrivilege() {
		return fmt.Errorf("TiDB run with skip-grant-table need root privilege")
	}
	if _, ok := ValidStorage[c.Store]; !ok {
		nameList := make([]string, 0, len(ValidStorage))
		for k, v := range ValidStorage {
			if v {
				nameList = append(nameList, k)
			}
		}
		return fmt.Errorf("invalid store=%s, valid storages=%v", c.Store, nameList)
	}
	if c.Store == "mocktikv" && !c.RunDDL {
		return fmt.Errorf("can't disable DDL on mocktikv")
	}
	if c.Log.File.MaxSize > MaxLogFileSize {
		return fmt.Errorf("invalid max log file size=%v which is larger than max=%v", c.Log.File.MaxSize, MaxLogFileSize)
	}
	c.OOMAction = strings.ToLower(c.OOMAction)

	// lower_case_table_names is allowed to be 0, 1, 2
	if c.LowerCaseTableNames < 0 || c.LowerCaseTableNames > 2 {
		return fmt.Errorf("lower-case-table-names should be 0 or 1 or 2")
	}

	if c.TxnLocalLatches.Enabled && c.TxnLocalLatches.Capacity == 0 {
		return fmt.Errorf("txn-local-latches.capacity can not be 0")
	}

	// For tikvclient.
	if c.TiKVClient.GrpcConnectionCount == 0 {
		return fmt.Errorf("grpc-connection-count should be greater than 0")
	}
	if c.TiKVClient.MaxTxnTimeUse == 0 {
		return fmt.Errorf("max-txn-time-use should be greater than 0")
	}
	return nil
}
544476
func ValidateServiceAccountName(name string, prefix bool) (bool, string) {
	return NameIsDNSSubdomain(name, prefix)
}
209855
func (m *Variable) Valid() error {
	// todo(leodido) > check it org ID validity?

	if m.Name == "" {
		return fmt.Errorf("missing variable name")
	}

	validTypes := map[string]bool{
		"constant": true,
		"map":      true,
		"query":    true,
	}

	if _, prs := validTypes[m.Arguments.Type]; !prs {
		return fmt.Errorf("invalid arguments type")
	}

	return nil
}
254529
func (c *Client) Valid() bool {
	if c == nil {
		return false
	}

	if c.Client == nil {
		return false
	}

	// Use arbitrary pointer field in the service content.
	// Doesn't matter which one, as long as it is populated by default.
	if c.ServiceContent.SessionManager == nil {
		return false
	}

	return true
}
304960
func isValidServiceIdentityName(name string) bool {
	if len(name) < 1 || len(name) > serviceIdentityNameMaxLength {
		return false
	}
	return validServiceIdentityName.MatchString(name)
}
426225
func GetQualifiedName(ctx context.Context, elementName string) string {
	parts := strings.Split(elementName, ".")
	if len(parts) == 1 {
		if providerName, ok := ctx.Value(providerKey).(string); ok {
			return MakeQualifiedName(providerName, parts[0])
		}
	}
	return elementName
}
1008557
func ValidateAccountName(name string) error {
	if name == "" {
		str := "accounts may not be named the empty string"
		return managerError(ErrInvalidAccount, str, nil)
	}
	if isReservedAccountName(name) {
		str := "reserved account name"
		return managerError(ErrInvalidAccount, str, nil)
	}
	return nil
}
535262
func ossIsValidBucketName(bucket string) bool {
	// dot is not allowed in bucket name
	if strings.Contains(bucket, ".") {
		return false
	}
	if s3utils.CheckValidBucketNameStrict(bucket) != nil {
		return false
	}
	return true
}
213669
func ValidateConfigMapName(name string, prefix bool) (bool, string) {
	return apivalidation.NameIsDNSSubdomain(name, prefix)
}
987320
func (n *namespace) Hostname(machineID string) (string, error) {
	if !names.IsValidMachine(machineID) {
		return "", errors.Errorf("machine ID %q is not a valid machine", machineID)
	}
	machineID = strings.Replace(machineID, "/", "-", -1)
	return n.Value(machineID), nil
}
963682
func validateName(name string) error {
	if !nameRegexp.Match([]byte(name)) {
		return errors.Wrapf(ErrName, "'%s'", name)
	}
	return nil
}
466345
func (m *Macro) Valid() error {
	if m.Name == "" {
		return fmt.Errorf("name empty")
	}

	validTypes := map[string]bool{
		"constant": true,
		"map":      true,
		"query":    true,
	}

	if _, prs := validTypes[m.Arguments.Type]; !prs {
		return fmt.Errorf("invalid arguments type")
	}

	if len(m.Selected) == 0 {
		return fmt.Errorf("no selected values")
	}

	return nil
}
790223
func (c *Conn) VerifyHostname(host string) error {
	cert, err := c.PeerCertificate()
	if err != nil {
		return err
	}
	return cert.VerifyHostname(host)
}
878140
func ValidNamespace(ctx Context, resource *ObjectMeta) bool {
	ns, ok := NamespaceFrom(ctx)
	if len(resource.Namespace) == 0 {
		resource.Namespace = ns
	}
	return ns == resource.Namespace && ok
}
1223837
func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
	var allErrors field.ErrorList
	if len(name) == 0 {
		return append(allErrors, field.Required(fldPath, ""))
	}
	if errs := IsDNS1123Subdomain(name); len(errs) > 0 {
		return append(allErrors, field.Invalid(fldPath, name, strings.Join(errs, ",")))
	}
	if len(strings.Split(name, ".")) < 3 {
		return append(allErrors, field.Invalid(fldPath, name, "should be a domain with at least three segments separated by dots"))
	}
	return allErrors
}
16827
func (n Name) Validate(_ interface{}) error {
	if nameRegex.Match([]byte(n)) {
		return nil
	}

	return errInvalidName
}