-# TODO: read from ../.env
-base = 'https://identity:8463'
-username = 'admin'
-password = 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
-realmFile = os.path.dirname(os.path.abspath(__file__)) + '/o-ran-sc-realm.json'
-authFile = os.path.dirname(os.path.abspath(__file__)) + '/authentication.json'
-
-# Request a token for futher communication
+
+
+def get_environment_variable(name):
+ configs = Properties()
+ env_file = os.path.dirname(os.path.abspath(__file__)) + '/' + '../' + '.env'
+ with open(env_file, "rb") as read_prop:
+ configs.load(read_prop)
+ return configs.get(name).data
+
+
+def load_arguments(args: List[str]) -> tuple:
+ realm_file = os.path.dirname(os.path.abspath(
+ __file__)) + '/o-ran-sc-realm.json'
+ auth_file = os.path.dirname(os.path.abspath(
+ __file__)) + '/authentication.json'
+ ready_timeout = 180
+ args.pop(0)
+ while len(args) > 0:
+ arg = args.pop(0)
+ if arg == '--auth' and len(args) > 0:
+ auth_file = args.pop(0)
+ print('overwriting auth file: {}'.format(auth_file))
+ elif arg == '--realm' and len(args) > 0:
+ realm_file = args.pop(0)
+ print('overwriting realm file: {}'.format(realm_file))
+ elif arg == '--timeout' and len(args) > 0:
+ ready_timeout = int(args.pop(0))
+ print('waiting for ready {} seconds'.format(ready_timeout))
+
+ return (realm_file, auth_file, ready_timeout)
+
+
+def isReady(timeoutSeconds=180):
+ url = getBaseUrl()
+ while timeoutSeconds > 0:
+ try:
+ response = requests.get(url, verify=False, headers={})
+ except:
+ pass
+ if response is not None and response.status_code == 200:
+ return True
+ time.sleep(1)
+ timeoutSeconds -= 1
+ return False
+
+
+def getBaseUrl():
+ return get_environment_variable("IDENTITY_PROVIDER_URL")
+
+# Request a token for further communication