Commit da492ff5 authored by Adrien Dorsaz's avatar Adrien Dorsaz

style: apply some pep8 recommandations

parent 4ef84e71
......@@ -13,7 +13,7 @@ def get_crt(config, log=LOGGER):
# helper function base64 encode for jose spec
def _b64(b):
return base64.urlsafe_b64encode(b).decode("utf8").replace("=", "")
# helper function to run openssl command
def _openssl(command, options, communicate=None):
openssl = subprocess.Popen(["openssl", command] + options,
......@@ -22,7 +22,7 @@ def get_crt(config, log=LOGGER):
if openssl.returncode != 0:
raise IOError("OpenSSL Error: {0}".format(err))
return out
# helper function to send DNS dynamic update messages
def _update_dns(rrset, action):
algorithm = dns.name.from_text("hmac-{0}".format(config["TSIGKeyring"]["Algorithm"].lower()))
......@@ -54,7 +54,7 @@ def get_crt(config, log=LOGGER):
return getattr(e, "code", None), getattr(e, "read", e.__str__)(), None
# create DNS keyring and resolver
keyring = dns.tsigkeyring.from_text({ config["TSIGKeyring"]["KeyName"] : config["TSIGKeyring"]["KeyValue"]})
keyring = dns.tsigkeyring.from_text({config["TSIGKeyring"]["KeyName"]: config["TSIGKeyring"]["KeyValue"]})
try:
nameserver = [ipv4_rrset.to_text() for ipv4_rrset in dns.resolver.query(config["DNS"]["Host"], rdtype="A")]
finally:
......@@ -73,7 +73,7 @@ def get_crt(config, log=LOGGER):
accountkey = _openssl("rsa", ["-in", config["acmednstiny"]["AccountKeyFile"], "-noout", "-text"])
pub_hex, pub_exp = re.search(
r"modulus:\n\s+00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)",
accountkey.decode("utf8"), re.MULTILINE|re.DOTALL).groups()
accountkey.decode("utf8"), re.MULTILINE | re.DOTALL).groups()
pub_exp = "{0:x}".format(int(pub_exp))
pub_exp = "0{0}".format(pub_exp) if len(pub_exp) % 2 else pub_exp
header = {
......@@ -94,7 +94,7 @@ def get_crt(config, log=LOGGER):
common_name = re.search(r"Subject:.*? CN=([^\s,;/]+)", csr)
if common_name is not None:
domains.add(common_name.group(1))
subject_alt_names = re.search(r"X509v3 Subject Alternative Name: \n +([^\n]+)\n", csr, re.MULTILINE|re.DOTALL)
subject_alt_names = re.search(r"X509v3 Subject Alternative Name: \n +([^\n]+)\n", csr, re.MULTILINE | re.DOTALL)
if subject_alt_names is not None:
for san in subject_alt_names.group(1).split(", "):
if san.startswith("DNS:"):
......@@ -159,7 +159,6 @@ def get_crt(config, log=LOGGER):
if challenge_verified is False:
number_check_fail = number_check_fail + 1
time.sleep(2)
log.info("Ask ACME server to perform check...")
code, result, headers = _send_signed_request(challenge["uri"], {
"resource": "challenge",
......@@ -237,9 +236,9 @@ def main(argv):
args = parser.parse_args(argv)
config = ConfigParser()
config.read_dict({"acmednstiny" : {"CAUrl" : "https://acme-staging.api.letsencrypt.org",
"CheckChallengeDelay" : 2},
"DNS" : { "Port" : "53" }})
config.read_dict({"acmednstiny": {"CAUrl": "https://acme-staging.api.letsencrypt.org",
"CheckChallengeDelay": 2},
"DNS": {"Port": "53"}})
config.read(args.configfile)
if (set(["accountkeyfile", "csrfile", "caurl", "checkchallengedelay"]) - set(config.options("acmednstiny"))
......@@ -251,5 +250,5 @@ def main(argv):
signed_crt = get_crt(config, log=LOGGER)
sys.stdout.write(signed_crt)
if __name__ == "__main__": # pragma: no cover
if __name__ == "__main__": # pragma: no cover
main(sys.argv[1:])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment