Commit 28729d8e authored by prerana dubey's avatar prerana dubey
Browse files

Accept bootstrap values from environment variables

parent f7d9dc19
Pipeline #33560 passed with stages
in 30 minutes and 12 seconds
......@@ -19,24 +19,9 @@ class DeploySharedSchemas:
parser = argparse.ArgumentParser(
description="Given a path to an load sequence file, load/update the schemas "
"listed in the load sequence file.")
parser.add_argument('-a', type=str,
help='The schema authority or partition-id to replace (default via Env)',
default=None)
parser.add_argument('-l', type=str,
help='The path to the load sequence file, e.g. load_sequence.?.?.?',
default=None)
parser.add_argument('-u', help='The complete URL to the Schema Service.',
default=None)
arguments = parser.parse_args()
if arguments.l is not None:
RunEnv.LOAD_SEQUENCE = arguments.l
if arguments.a is not None:
self.schema_authority = arguments.a
elif RunEnv.SCHEMA_AUTHORITY:
self.schema_authority = RunEnv.SCHEMA_AUTHORITY
else:
self.schema_authority = 'osdu' # default
if arguments.u is not None:
RunEnv.SCHEMA_SERVICE_URL = arguments.u
if RunEnv.SCHEMA_SERVICE_URL is None:
......@@ -51,7 +36,6 @@ class DeploySharedSchemas:
'Authorization': RunEnv.BEARER_TOKEN
}
print('Current data-partition-id: {}'.format(RunEnv.DATA_PARTITION))
print('Current schema-authority: {}'.format(self.schema_authority))
ok, error_mess = RunEnv().is_ok()
if not ok:
exit('Error: environment setting incomplete: {}'.format(error_mess))
......@@ -61,12 +45,21 @@ class DeploySharedSchemas:
deployments = Utility.path_to_deployments()
start = time.time()
sequence = Utility.load_json(os.path.join(deployments, *RunEnv.OSDU, RunEnv.LOAD_SEQUENCE))
bootstrap_options = json.loads(RunEnv.BOOTSTRAP_OPTIONS)
for option in bootstrap_options:
try:
schema_path = option['folder']
schema_authority = option['authority']
load_sequence = option['load-sequence']
except KeyError as e:
exit('Key missing in bootstrap-options::{}'.format(str(e)))
sequence = Utility.load_json(os.path.join(deployments, RunEnv.SCHEMAS_FOLDER, schema_path, load_sequence))
for item in sequence:
self.schema_registered = None
schema_file = os.path.join(deployments, item['relativePath'])
schema = open(schema_file, 'r').read()
schema = schema.replace(self.SCHEMA_AUTHORITY_TO_REPLACE, self.schema_authority)
schema = schema.replace(self.SCHEMA_AUTHORITY_TO_REPLACE, schema_authority)
kind = self.__kind_from_schema_info(schema)
self.__register_one(kind, schema, messages)
......
......@@ -14,8 +14,9 @@ class RunEnv(object):
STORAGE_SERVICE_URL = None
DATA_PARTITION = os.environ.get('DATA_PARTITION')
SCHEMA_AUTHORITY = os.environ.get('SCHEMA_AUTHORITY')
OSDU = ['shared-schemas', 'osdu']
LOAD_SEQUENCE = 'load_sequence.1.0.0.json'
SCHEMAS_FOLDER = 'shared-schemas'
DEFAULT_BOOTSTRAP_OPTIONS = '[{"authority": "osdu", "folder": "osdu", "load-sequence": "load_sequence.1.0.0.json"}]'
BOOTSTRAP_OPTIONS = os.environ.get('BOOTSTRAP_OPTIONS', DEFAULT_BOOTSTRAP_OPTIONS)
def __init__(self):
"""Empty constructor"""
......@@ -119,9 +120,12 @@ class Utility(object):
@staticmethod
def load_json(path):
"""Load a JSON file"""
with open(path, "r", encoding='utf-8') as text_file:
j_obj = json.load(text_file)
return j_obj
try:
with open(path, "r", encoding='utf-8') as text_file:
j_obj = json.load(text_file)
return j_obj
except FileNotFoundError as e:
exit("Given File path not found::{}".format(str(e)))
@staticmethod
def save_json(schema, path, sort_keys=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment