Skip to content

Commit 8e620d3

Browse files
committed
Allows running layersbox -script with older python
We have a server where updating python seems to be really difficult. As I’ve understood, the older version of python is not that picky with signed ssl, so it can do without create_default_context -trick.
1 parent f8d79cf commit 8e620d3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

layersbox

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,16 @@ def create_oidcclients(dir, service_name, oidcclient_env_files):
760760
if "LAYERS_API_URI" in line:
761761
layers_api_uri = line.split("=")[1].replace('\n', '')
762762

763+
# For Python >2.7.9, give context to override local unsigned https warnings
763764
# evil workaround from http://stackoverflow.com/questions/19268548/python-ignore-certicate-validation-urllib2
764-
ctx = ssl.create_default_context()
765-
ctx.check_hostname = False
766-
ctx.verify_mode = ssl.CERT_NONE
765+
if hasattr(ssl, 'create_default_context'):
766+
ctx = ssl.create_default_context()
767+
ctx.check_hostname = False
768+
ctx.verify_mode = ssl.CERT_NONE
769+
else:
770+
# For older pythons the warnings do not stop the show and can be ignored
771+
# (anyways, they don't have the ssl.create_default_context.)
772+
ctx = None
767773

768774
for env_file in oidcclient_env_files:
769775
# we support one OIDC client per env file currently
@@ -782,7 +788,10 @@ def create_oidcclients(dir, service_name, oidcclient_env_files):
782788
# run HTTP POST against OIDC endpoint and then save the results into the env file
783789
req = urllib2.Request(layers_api_uri + 'o/oauth2/register')
784790
req.add_header('Content-Type', 'application/json')
785-
response = urllib2.urlopen(req, oidc_json, context=ctx).read()
791+
if ctx:
792+
response = urllib2.urlopen(req, oidc_json, context=ctx).read()
793+
else:
794+
response = urllib2.urlopen(req, oidc_json).read()
786795
oidc_config = json.loads(response)
787796

788797
#print(oidc_config)

0 commit comments

Comments
 (0)