Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's Encrypt compatibility with python3 #1057

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions roles/letsencrypt/templates/renew-certs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
ouun marked this conversation as resolved.
Show resolved Hide resolved

import os
import sys
Expand All @@ -15,15 +15,15 @@

if os.access(cert_path, os.F_OK):
stat = os.stat(cert_path)
print 'Certificate file ' + cert_path + ' already exists'
print('Certificate file ' + cert_path + ' already exists')

if time.time() - stat.st_mtime < {{ letsencrypt_min_renewal_age }} * 86400:
print ' The certificate is younger than {{ letsencrypt_min_renewal_age }} days. Not creating a new certificate.\n'
print('The certificate is younger than {{ letsencrypt_min_renewal_age }} days. Not creating a new certificate.\n')
continue

print 'Generating certificate for ' + site
print('Generating certificate for ' + site)

cmd = ('/usr/bin/env python {{ acme_tiny_software_directory }}/acme_tiny.py '
cmd = ('/usr/bin/env python3 {{ acme_tiny_software_directory }}/acme_tiny.py '
ouun marked this conversation as resolved.
Show resolved Hide resolved
'--quiet '
'--ca {{ letsencrypt_ca }} '
'--account-key {{ letsencrypt_account_key }} '
Expand All @@ -35,19 +35,19 @@
cert = check_output(cmd, stderr=STDOUT, shell=True)
except CalledProcessError as e:
failed = True
print 'Error while generating certificate for ' + site
print e.output
print('Error while generating certificate for ' + site)
print(e.output)
else:
with open(cert_path, 'w') as cert_file:
with open(cert_path, 'wb') as cert_file:
cert_file.write(cert)

with open('{{ letsencrypt_intermediate_cert_path }}') as intermediate_cert_file:
intermediate_cert = intermediate_cert_file.read()

with open(bundled_cert_path, 'w') as bundled_file:
bundled_file.write(''.join([cert, intermediate_cert]))
with open(bundled_cert_path, 'wb') as bundled_file:
bundled_file.write(b''.join(b[cert, intermediate_cert]))

print 'Created certificate for ' + site
print('Created certificate for ' + site)

if failed:
sys.exit(1)