Skip to content

Commit

Permalink
Refactored domain flag checks into their own helper function to clear…
Browse files Browse the repository at this point in the history
… space for future checks
  • Loading branch information
joohoi committed Nov 8, 2015
1 parent c80e4c0 commit ee38585
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions letsencrypt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ee38585

Please sign in to comment.