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

Update dependencies #33

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
applications:
- name: letsencrypt
buildpack: python_buildpack
buildpacks:
- https://github.com/cloudfoundry/python-buildpack.git
memory: 128M
instances: 1
no-route: true
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cffi >= 0.8.0
letsencrypt >= 0.7.0
six >= 1.7
Copy link
Member

@lmsurpre lmsurpre Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was for python2 compatibility and our goal was for it to run on either 2 or 3. however, I'm not even sure it was used and now python2 is end-of-life, so I'm ok with this change

pyyaml >= 3.11
certbot >= 1.14.0
pyyaml >= 5.3.1
wheel
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys
import time
import threading
from http.server import SimpleHTTPRequestHandler
from http.server import SimpleHTTPRequestHandler
import socketserver
from letsencrypt import main as cli
from certbot import main as cli

cwd = os.getcwd()
logs = cwd+"/logs"
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.6.x
python-3.x
35 changes: 15 additions & 20 deletions setup-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def domain_has_ssl(domain, full_host, print_info=False):
The print_info parameter can be used to dump the certificate information
from Bluemix to stdout.
"""
pipe = Popen("ibmcloud app domain-cert %s" % domain,
stdout=PIPE, shell=True)
print("Checking whether %s already has a certificate assigned..." % primary_domain)

pipe = Popen("ibmcloud app domain-cert %s" % domain, stdout=PIPE, shell=True)
output = pipe.stdout.read().decode("unicode_escape")
cert_exists = "OK" in output
if print_info and cert_exists:
Expand Down Expand Up @@ -109,27 +110,22 @@ def check_ssl(full_host):

# Figure out which domain name to look for
primary_domain = settings['domains'][0]['domain']

domain_with_first_host = "%s.%s" % (settings['domains'][0]['hosts'][0],
primary_domain)
domain_with_first_host = "%s.%s" % (settings['domains'][0]['hosts'][0], primary_domain)

# Hostname is sometimes '.', which requires special handling
if domain_with_first_host.startswith('..'):
domain_with_first_host = domain_with_first_host[2:]

print("\nWaiting for container to mount filesystem")
time.sleep(5)

cert1Proc = get_cert(appname, domain_with_first_host, 'cert.pem')
cert2Proc = get_cert(appname, domain_with_first_host, 'chain.pem')
cert3Proc = get_cert(appname, domain_with_first_host, 'fullchain.pem')
cert4Proc = get_cert(appname, domain_with_first_host, 'privkey.pem')

# wait for get_cert subprocesses to finish
cert1Proc.wait()
cert2Proc.wait()
cert3Proc.wait()
cert4Proc.wait()
# Retrieve the certs from the letsencrypt app container
for cert in ["cert", "chain", "privkey"]:
seconds_waited = 0
MAX_WAIT_SECONDS = 60
while get_cert(appname, domain_with_first_host, "%s.pem" % cert).wait() != 0:
if seconds_waited >= MAX_WAIT_SECONDS:
print("ERROR: Failed to retrieve %s" % cert)
sys.exit(1)
time.sleep(5)
seconds_waited = seconds_waited + 5

# Check if there is already an SSL in place
if domain_has_ssl(primary_domain, domain_with_first_host, True):
Expand All @@ -153,8 +149,7 @@ def check_ssl(full_host):
while(failure and count < 3):
# Upload new cert
print("Attempting certificate upload...")
call("ibmcloud app domain-cert-add %s -c cert.pem -k privkey.pem -i chain.pem"
% primary_domain, shell=True)
call("ibmcloud app domain-cert-add %s --cert cert.pem --key privkey.pem --intermediate-cert chain.pem" % primary_domain, shell=True)
failure = not domain_has_ssl(primary_domain, domain_with_first_host, True)
count = count + 1
time.sleep(5)
Expand Down