1010import json
1111import locale
1212import os
13+ import random
1314import re
1415import sys
1516import time
@@ -1011,6 +1012,7 @@ def launch(
10111012 )
10121013 run_id = req_json ["id" ]
10131014 formatted_url = api .url (f"{ project } /runs/{ run_id } " )
1015+ click .echo (f"\n LR id: { req_id } " )
10141016 click .echo (f"\n Run created: { formatted_url } " )
10151017 return formatted_url
10161018 except Exception as err :
@@ -1064,6 +1066,38 @@ def select_org(api, config, organization=None):
10641066 click .echo (f"Logged in with organization: { organization } " )
10651067
10661068
1069+ def env (
1070+ api ,
1071+ config ,
1072+ organization = None ,
1073+ env = None ,
1074+ ):
1075+ env_root = env_prompt (env )
1076+ api .api_root = env_root
1077+ api .save (config )
1078+
1079+ click .echo ('\n ' )
1080+
1081+ try :
1082+ org_list = [
1083+ {"name" : org ["name" ], "subdomain" : org ["subdomain" ]}
1084+ for org in api .organizations ()
1085+ ]
1086+ if organization is None :
1087+ organization = org_prompt (org_list )
1088+ except :
1089+ organization = api .organization_id
1090+
1091+ r = api .get_organization (org_id = organization )
1092+ if r .status_code != 200 :
1093+ click .echo (f"Error accessing organization: { r .text } " )
1094+ sys .exit (1 )
1095+
1096+ api .organization_id = organization
1097+ api .save (config )
1098+ click .echo (f"Logged in with organization: { env_root } /{ organization } " )
1099+
1100+
10671101def login (api , config , api_root = None , analytics = True , rsa_key = None , web_staging = False ):
10681102 """Authenticate to your Transcriptic account."""
10691103 # If user does not specify staging web api argument, default to the "https://secure.strateos.com" domain
@@ -1073,6 +1107,21 @@ def login(api, config, api_root=None, analytics=True, rsa_key=None, web_staging=
10731107 api_root = "https://secure.strateos.com/"
10741108 rsa_auth = None
10751109 rsa_key_path = None
1110+ if rsa_key is not None :
1111+ try :
1112+ rsa_key_path = abspath (expanduser (rsa_key ))
1113+ with open (rsa_key_path , "rb" ) as key_file :
1114+ rsa_secret = key_file .read ()
1115+ except Exception :
1116+ click .echo (
1117+ f"Error loading RSA key. Please check that the file "
1118+ f"{ rsa_key } is accessible" ,
1119+ err = True ,
1120+ )
1121+ sys .exit (1 )
1122+ # replace the dummy rsa_auth with a handler using the given email
1123+ if rsa_auth is not None :
1124+ rsa_auth = StrateosSign (email , rsa_auth .secret , api_root )
10761125
10771126 if rsa_key is not None :
10781127 try :
@@ -1314,6 +1363,64 @@ def _get_quick_launch(api, protocol, project):
13141363 return quick_launch
13151364
13161365
1366+ def env_prompt (env = None ):
1367+ """"""
1368+ # "😺", "🐵", "🙈", "🙉", "🙊", "🐒",
1369+ rand = [
1370+ "(੭。╹▿╹。)੭" ,
1371+ " (੭ˊᵕˋ)੭ " ,
1372+ " ( *◑∇◑)☞" ,
1373+ " ( ^o^)ノ" ,
1374+ " ₍ᐢ. ̫.ᐢ₎" ,
1375+ "づ ᴗ _ᴗ)づ" ,
1376+ " ՞•ﻌ•՞ฅ " ,
1377+ " ⑅ᐢ..ᐢ " ,
1378+ " ʕ·ᴥ·ʔ " ,
1379+ " ᐡ ᐧ ﻌ ᐧ ᐡ " ,
1380+ " ₍˄·͈༝·͈˄ " ,
1381+ "૮ ˶ᵔ ᵕ ᵔ˶ ა" ,
1382+ "(* °ヮ° *) " ,
1383+ " (ˊ•͈ ◡ •͈ˋ) "
1384+ ]
1385+ envs = {
1386+ "PROD" : "https://secure.strateos.com" ,
1387+ "STAGING" : "https://webapp.staging.strateos.com" ,
1388+ "LOCAL" : "http://localhost:5000" ,
1389+ # "DOCKER": "http://host.docker.internal:5000"
1390+ }
1391+
1392+ def parse_valid_env (env_str , envs ):
1393+ try :
1394+ if env_str not in envs .keys ():
1395+ raise ValueError (
1396+ f'Environment "{ env_str } " selected not in: { list (envs .keys ())} ' )
1397+ else :
1398+ return env_str
1399+ except :
1400+ raise BadParameter (
1401+ f"Please enter one of the following { envs .keys ()} "
1402+ )
1403+
1404+ if env is None :
1405+ click .echo ("Select the which ENV you want to point to:" )
1406+ env_map = []
1407+ for name , endpoint in envs .items ():
1408+ env_map .append (name )
1409+ click .echo (f"{ random .choice (rand )} \t { name } \t { endpoint } " )
1410+
1411+
1412+ selected_env = click .prompt (
1413+ "Which ENV would you like to configure your session with" ,
1414+ default = 'STAGING' ,
1415+ prompt_suffix = "? " ,
1416+ type = str ,
1417+ value_proc = lambda x : parse_valid_env (x , envs ),
1418+ )
1419+ else :
1420+ selected_env = parse_valid_env (env , envs )
1421+ return envs [selected_env ]
1422+
1423+
13171424def org_prompt (org_list ):
13181425 """Organization prompt for helping with selecting organization"""
13191426 if len (org_list ) < 1 :
0 commit comments