From a5cce1565f51deaba3483d0576610f77bd73c4d4 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Tue, 25 Jul 2017 14:12:41 -0700 Subject: [PATCH] Handle env vars set to the empty string in fetch --- letsencrypt-auto-source/letsencrypt-auto | 13 ++++++++++--- letsencrypt-auto-source/pieces/fetch.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/letsencrypt-auto-source/letsencrypt-auto b/letsencrypt-auto-source/letsencrypt-auto index 593f83c8c..7a6ac36c3 100755 --- a/letsencrypt-auto-source/letsencrypt-auto +++ b/letsencrypt-auto-source/letsencrypt-auto @@ -1176,7 +1176,14 @@ from subprocess import check_call, CalledProcessError from sys import argv, exit from urllib2 import build_opener, HTTPHandler, HTTPSHandler, HTTPError -PUBLIC_KEY = environ.get('LE_AUTO_PUBLIC_KEY', """-----BEGIN PUBLIC KEY----- + +def get_environ(name, default=None): + """os.environ.get except the default is also used for empty strings.""" + value = environ.get(name) + return value if value else default + + +PUBLIC_KEY = get_environ('LE_AUTO_PUBLIC_KEY', """-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6MR8W/galdxnpGqBsYbq OzQb2eyW15YFjDDEMI0ZOzt8f504obNs920lDnpPD2/KqgsfjOgw2K7xWDJIj/18 xUvWPk3LDkrnokNiRkA3KOx3W6fHycKL+zID7zy+xZYBuh2fLyQtWV1VGQ45iNRp @@ -1224,7 +1231,7 @@ def write(contents, dir, filename): def latest_stable_version(get): """Return the latest stable release of letsencrypt.""" metadata = loads(get( - environ.get('LE_AUTO_JSON_URL', + get_environ('LE_AUTO_JSON_URL', 'https://pypi.python.org/pypi/certbot/json'))) # metadata['info']['version'] actually returns the latest of any kind of # release release, contrary to https://wiki.python.org/moin/PyPIJSON. @@ -1242,7 +1249,7 @@ def verified_new_le_auto(get, tag, temp_dir): with the verification process, raise ExpectedError. """ - le_auto_dir = environ.get( + le_auto_dir = get_environ( 'LE_AUTO_DIR_TEMPLATE', 'https://raw.githubusercontent.com/certbot/certbot/%s/' 'letsencrypt-auto-source/') % tag diff --git a/letsencrypt-auto-source/pieces/fetch.py b/letsencrypt-auto-source/pieces/fetch.py index e7ebb9e0a..cb250ddf3 100644 --- a/letsencrypt-auto-source/pieces/fetch.py +++ b/letsencrypt-auto-source/pieces/fetch.py @@ -22,7 +22,14 @@ from subprocess import check_call, CalledProcessError from sys import argv, exit from urllib2 import build_opener, HTTPHandler, HTTPSHandler, HTTPError -PUBLIC_KEY = environ.get('LE_AUTO_PUBLIC_KEY', """-----BEGIN PUBLIC KEY----- + +def get_environ(name, default=None): + """os.environ.get except the default is also used for empty strings.""" + value = environ.get(name) + return value if value else default + + +PUBLIC_KEY = get_environ('LE_AUTO_PUBLIC_KEY', """-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6MR8W/galdxnpGqBsYbq OzQb2eyW15YFjDDEMI0ZOzt8f504obNs920lDnpPD2/KqgsfjOgw2K7xWDJIj/18 xUvWPk3LDkrnokNiRkA3KOx3W6fHycKL+zID7zy+xZYBuh2fLyQtWV1VGQ45iNRp @@ -70,7 +77,7 @@ def write(contents, dir, filename): def latest_stable_version(get): """Return the latest stable release of letsencrypt.""" metadata = loads(get( - environ.get('LE_AUTO_JSON_URL', + get_environ('LE_AUTO_JSON_URL', 'https://pypi.python.org/pypi/certbot/json'))) # metadata['info']['version'] actually returns the latest of any kind of # release release, contrary to https://wiki.python.org/moin/PyPIJSON. @@ -88,7 +95,7 @@ def verified_new_le_auto(get, tag, temp_dir): with the verification process, raise ExpectedError. """ - le_auto_dir = environ.get( + le_auto_dir = get_environ( 'LE_AUTO_DIR_TEMPLATE', 'https://raw.githubusercontent.com/certbot/certbot/%s/' 'letsencrypt-auto-source/') % tag