Pep8 fixes for letsencrypt module (#24144)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-05-02 22:05:06 +05:30 committed by Matt Martz
parent df5be2b8ea
commit fbb924ff24
2 changed files with 90 additions and 87 deletions

View file

@ -174,6 +174,7 @@ from datetime import datetime
def nopad_b64(data): def nopad_b64(data):
return base64.urlsafe_b64encode(data).decode('utf8').replace("=", "") return base64.urlsafe_b64encode(data).decode('utf8').replace("=", "")
def simple_get(module, url): def simple_get(module, url):
resp, info = fetch_url(module, url, method='GET') resp, info = fetch_url(module, url, method='GET')
@ -197,6 +198,7 @@ def simple_get(module,url):
module.fail_json(msg="ACME request failed: CODE: {0} RESULT: {1}".format(info['status'], result)) module.fail_json(msg="ACME request failed: CODE: {0} RESULT: {1}".format(info['status'], result))
return result return result
def get_cert_days(module, cert_file): def get_cert_days(module, cert_file):
''' '''
Return the days the certificate in cert_file remains valid and -1 Return the days the certificate in cert_file remains valid and -1
@ -218,6 +220,7 @@ def get_cert_days(module,cert_file):
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
return (not_after - now).days return (not_after - now).days
# function source: network/basics/uri.py # function source: network/basics/uri.py
def write_file(module, dest, content): def write_file(module, dest, content):
''' '''
@ -268,6 +271,7 @@ def write_file(module, dest, content):
os.remove(tmpsrc) os.remove(tmpsrc)
return changed return changed
class ACMEDirectory(object): class ACMEDirectory(object):
''' '''
The ACME server directory. Gives access to the available resources The ACME server directory. Gives access to the available resources
@ -294,6 +298,7 @@ class ACMEDirectory(object):
self.module.fail_json(msg="Failed to get replay-nonce, got status {0}".format(info['status'])) self.module.fail_json(msg="Failed to get replay-nonce, got status {0}".format(info['status']))
return info['replay-nonce'] return info['replay-nonce']
class ACMEAccount(object): class ACMEAccount(object):
''' '''
ACME account object. Handles the authorized communication with the ACME account object. Handles the authorized communication with the
@ -499,6 +504,7 @@ class ACMEAccount(object):
return authz return authz
class ACMEClient(object): class ACMEClient(object):
''' '''
ACME client class. Uses an ACME account object and a CSR to ACME client class. Uses an ACME account object and a CSR to
@ -540,7 +546,6 @@ class ACMEClient(object):
domains.add(san[4:]) domains.add(san[4:])
return domains return domains
def _get_domain_auth(self, domain): def _get_domain_auth(self, domain):
''' '''
Get the status string of the first authorization for the given domain. Get the status string of the first authorization for the given domain.
@ -763,6 +768,7 @@ class ACMEClient(object):
self.cert_days = get_cert_days(self.module, self.dest) self.cert_days = get_cert_days(self.module, self.dest)
self.changed = True self.changed = True
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
@ -789,15 +795,13 @@ def main():
# the authorization status...) would lead to potential changes of the current # the authorization status...) would lead to potential changes of the current
# state # state
if module.check_mode: if module.check_mode:
module.exit_json(changed=True,authorizations={}, module.exit_json(changed=True, authorizations={}, challenge_data={}, cert_days=cert_days)
challenge_data={},cert_days=cert_days)
else: else:
client = ACMEClient(module) client = ACMEClient(module)
client.cert_days = cert_days client.cert_days = cert_days
data = client.do_challenges() data = client.do_challenges()
client.get_certificate() client.get_certificate()
module.exit_json(changed=client.changed,authorizations=client.authorizations, module.exit_json(changed=client.changed, authorizations=client.authorizations, challenge_data=data, cert_days=client.cert_days)
challenge_data=data,cert_days=client.cert_days)
else: else:
module.exit_json(changed=False, cert_days=cert_days) module.exit_json(changed=False, cert_days=cert_days)

View file

@ -772,7 +772,6 @@ lib/ansible/modules/web_infrastructure/ejabberd_user.py
lib/ansible/modules/web_infrastructure/htpasswd.py lib/ansible/modules/web_infrastructure/htpasswd.py
lib/ansible/modules/web_infrastructure/jboss.py lib/ansible/modules/web_infrastructure/jboss.py
lib/ansible/modules/web_infrastructure/jira.py lib/ansible/modules/web_infrastructure/jira.py
lib/ansible/modules/web_infrastructure/letsencrypt.py
lib/ansible/modules/windows/win_disk_image.py lib/ansible/modules/windows/win_disk_image.py
lib/ansible/modules/windows/win_dns_client.py lib/ansible/modules/windows/win_dns_client.py
lib/ansible/modules/windows/win_domain.py lib/ansible/modules/windows/win_domain.py