func ValidateHostName()

in internal/source/gitlab/client/utils.go [25:57]


func ValidateHostName(hostname string) error {
	// Handle potential protocols in the hostname for backwards compatibility.
	if strings.Contains(hostname, protocolDivider) {
		log.Info("hostname has protocol divider")

		if parts := strings.Split(hostname, protocolDivider); len(parts) > 1 {
			hostname = parts[1]
		}
	}

	if hostname == "" {
		return ErrHostnameEmpty
	}

	// Check if the hostname is too long
	if len(hostname) > FQDNMaxLength {
		return ErrHostnameToLong
	}

	labels := strings.Split(hostname, ".")
	for _, label := range labels {
		if len(label) > DNSLabelMaxLength {
			return ErrHostnameToLong
		}
	}

	// Check if the hostname contains invalid characters
	if !isValidHostname(hostname) {
		return ErrHostnameInvalid
	}

	return nil
}