Skip to content

Commit 33c5b64

Browse files
committed
Fixed OIDC client creation 👍
1 parent f1c6bbe commit 33c5b64

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

layersbox

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import re
99
import yaml
1010
import json
1111
import urllib2
12+
import ssl
1213
import six
1314
import copy
1415
from zipfile import ZipFile
@@ -245,7 +246,7 @@ def merge_ymls(base, addon, databases=[], oidcclients=[]):
245246
if k == "create_databases":
246247
print("Added database {}".format(v))
247248
databases.append(v)
248-
elif k == "create_oidcclient":
249+
elif k == "create_oidcclients":
249250
print("Added OIDC client {}".format(v))
250251
oidcclients.append(v)
251252
else:
@@ -706,7 +707,6 @@ def box_init(args):
706707
def create_databases(dir, service_name, database_env_files):
707708
servicedir = join(dir, "services")
708709

709-
710710
for env_file in database_env_files:
711711
# we support one database per env file currently
712712
db_key = ""
@@ -752,36 +752,43 @@ def create_databases(dir, service_name, database_env_files):
752752

753753

754754
def create_oidcclients(dir, service_name, oidcclient_env_files):
755+
servicedir = join(dir, "services")
756+
755757
layers_api_uri = None
756758
with open(join(dir, 'common.env')) as common_file:
757759
for line in common_file:
758760
if "LAYERS_API_URI" in line:
759761
layers_api_uri = line.split("=")[1].replace('\n', '')
760762

763+
# 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
767+
761768
for env_file in oidcclient_env_files:
762769
# we support one OIDC client per env file currently
763770
oidc_key = None
764771
oidc_json = None
765-
with open(join(servicedir, service_name, env_file)) as infile:
772+
with open(join(servicedir, service_name, env_file[0])) as infile:
766773
for line in infile:
767774
if "_OIDC_FILE" in line:
768775
oidc_key = line.split("_OIDC_FILE=")[0]
769776
oidc_json_file = line.split("=")[1].replace('\n', '')
770-
with open (join(servicedir, oidc_json_file), "r") as myfile:
777+
with open (join(servicedir, service_name, oidc_json_file), "r") as myfile:
771778
oidc_json = myfile.read().replace('\n', '')
772779

773780
# run HTTP POST against OIDC endpoint and then save the results into the env file
774781
req = urllib2.Request(layers_api_uri + 'o/oauth2/register')
775782
req.add_header('Content-Type', 'application/json')
776-
response = urllib2.urlopen(req, oidc_json)
783+
response = urllib2.urlopen(req, oidc_json, context=ctx).read()
777784
oidc_config = json.loads(response)
778785

779786
#print(oidc_config)
780787

781788
# save values to env file
782-
with open(join(servicedir, service_name, env_file), "a") as outfile:
783-
outfile.write("{}_OIDC_CLIENT_ID={}".format(oidc_key, oidc_config['client_id']))
784-
outfile.write("{}_OIDC_CLIENT_SECRET={}".format(oidc_key, oidc_config['client_secret']))
789+
with open(join(servicedir, service_name, env_file[0]), "a") as outfile:
790+
outfile.write("{}_OIDC_CLIENT_ID={}\n".format(oidc_key, oidc_config['client_id']))
791+
outfile.write("{}_OIDC_CLIENT_SECRET={}\n".format(oidc_key, oidc_config['client_secret']))
785792
return 0
786793

787794

0 commit comments

Comments
 (0)