Refactored domain flag checks into their own helper function to clear space for future checks

This commit is contained in:
Joona Hoikkala 2015-11-08 21:43:48 +02:00
parent c80e4c0f2f
commit ee38585eb4

View file

@ -1152,17 +1152,29 @@ def check_config_sanity(args):
"""
# Domain checks
if args.domains is not None:
# Check if there's a wildcard domain
if any(d.startswith("*.") for d in args.domains):
raise errors.ConfigurationError("Error: Wildcard domains are not supported")
# Punycode
if any("xn--" in d for d in args.domains):
raise errors.ConfigurationError("Error: Punycode domains are not supported")
# FQDN, checks:
# Characters used, domain parts < 63 chars, tld > 3 < 6 chars
fqdn = re.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$")
if any(True for d in args.domains if not fqdn.match(d)):
raise errors.ConfigurationError("Error: Requested domain is not FQDN")
_check_config_domain_sanity(args.domains)
def _check_config_domain_sanity(domains):
"""Helper method for check_config_sanity which validates
domain flag values and errors out if the requirements are not met.
:param domains: List of domains
:type args: `list` of `string`
"""
# Check if there's a wildcard domain
if any(d.startswith("*.") for d in domains):
raise errors.ConfigurationError(
"Error: Wildcard domains are not supported")
# Punycode
if any("xn--" in d for d in domains):
raise errors.ConfigurationError(
"Error: Punycode domains are not supported")
# FQDN, checks:
# Characters used, domain parts < 63 chars, tld > 3 < 6 chars
fqdn = re.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$")
if any(True for d in domains if not fqdn.match(d)):
raise errors.ConfigurationError("Error: Requested domain is not FQDN")
if __name__ == "__main__":
err_string = main()