From 8413e40f9ef04b2edd9f1913b0eb7a911ca35f07 Mon Sep 17 00:00:00 2001 From: Luke Bigum Date: Sat, 25 Jan 2020 20:30:41 +0000 Subject: [PATCH] handle CONSUL_HTTP_ADDR including a http:// or https:// scheme --- consul/base.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/consul/base.py b/consul/base.py index ee6ab254..3a717aff 100755 --- a/consul/base.py +++ b/consul/base.py @@ -313,13 +313,19 @@ def __init__( if os.getenv('CONSUL_HTTP_ADDR'): try: host, port = os.getenv('CONSUL_HTTP_ADDR').split(':') + scheme = 'http' except ValueError: - raise ConsulException('CONSUL_HTTP_ADDR (%s) invalid, ' - 'does not match :' - % os.getenv('CONSUL_HTTP_ADDR')) + try: + scheme, host, port = os.getenv('CONSUL_HTTP_ADDR').split(':') + host = host.lstrip('//') + except ValueError: + raise ConsulException('CONSUL_HTTP_ADDR (%s) invalid, ' + 'does not match : or ' + '::' + % os.getenv('CONSUL_HTTP_ADDR')) use_ssl = os.getenv('CONSUL_HTTP_SSL') - if use_ssl is not None: - scheme = 'https' if use_ssl == 'true' else 'http' + if use_ssl == 'true': + scheme = 'https' if os.getenv('CONSUL_HTTP_SSL_VERIFY') is not None: verify = os.getenv('CONSUL_HTTP_SSL_VERIFY') == 'true'