|
10 | 10 | import json |
11 | 11 | import locale |
12 | 12 | import os |
| 13 | +import random |
13 | 14 | import re |
14 | 15 | import sys |
15 | 16 | import time |
@@ -1013,6 +1014,7 @@ def launch( |
1013 | 1014 | ) |
1014 | 1015 | run_id = req_json["id"] |
1015 | 1016 | formatted_url = api.url(f"{project}/runs/{run_id}") |
| 1017 | + click.echo(f"\nLR id: {req_id}") |
1016 | 1018 | click.echo(f"\nRun created: {formatted_url}") |
1017 | 1019 | return formatted_url |
1018 | 1020 | except Exception as err: |
@@ -1066,6 +1068,38 @@ def select_org(api, config, organization=None): |
1066 | 1068 | click.echo(f"Logged in with organization: {organization}") |
1067 | 1069 |
|
1068 | 1070 |
|
| 1071 | +def env( |
| 1072 | + api, |
| 1073 | + config, |
| 1074 | + organization=None, |
| 1075 | + env=None, |
| 1076 | +): |
| 1077 | + env_root = env_prompt(env) |
| 1078 | + api.api_root = env_root |
| 1079 | + api.save(config) |
| 1080 | + |
| 1081 | + click.echo('\n') |
| 1082 | + |
| 1083 | + try: |
| 1084 | + org_list = [ |
| 1085 | + {"name": org["name"], "subdomain": org["subdomain"]} |
| 1086 | + for org in api.organizations() |
| 1087 | + ] |
| 1088 | + if organization is None: |
| 1089 | + organization = org_prompt(org_list) |
| 1090 | + except: |
| 1091 | + organization = api.organization_id |
| 1092 | + |
| 1093 | + r = api.get_organization(org_id=organization) |
| 1094 | + if r.status_code != 200: |
| 1095 | + click.echo(f"Error accessing organization: {r.text}") |
| 1096 | + sys.exit(1) |
| 1097 | + |
| 1098 | + api.organization_id = organization |
| 1099 | + api.save(config) |
| 1100 | + click.echo(f"Logged in with organization: {env_root}/{organization}") |
| 1101 | + |
| 1102 | + |
1069 | 1103 | def login(api, config, api_root=None, analytics=True, rsa_key=None): |
1070 | 1104 | """Authenticate to your Transcriptic account.""" |
1071 | 1105 | if api_root is None: |
@@ -1318,6 +1352,64 @@ def _get_quick_launch(api, protocol, project): |
1318 | 1352 | return quick_launch |
1319 | 1353 |
|
1320 | 1354 |
|
| 1355 | +def env_prompt(env=None): |
| 1356 | + """""" |
| 1357 | + # "😺", "🐵", "🙈", "🙉", "🙊", "🐒", |
| 1358 | + rand = [ |
| 1359 | + "(੭。╹▿╹。)੭", |
| 1360 | + " (੭ˊᵕˋ)੭ ", |
| 1361 | + " ( *◑∇◑)☞", |
| 1362 | + " ( ^o^)ノ", |
| 1363 | + " ₍ᐢ. ̫.ᐢ₎", |
| 1364 | + "づ ᴗ _ᴗ)づ", |
| 1365 | + " ՞•ﻌ•՞ฅ ", |
| 1366 | + " ⑅ᐢ..ᐢ ", |
| 1367 | + " ʕ·ᴥ·ʔ ", |
| 1368 | + " ᐡ ᐧ ﻌ ᐧ ᐡ ", |
| 1369 | + " ₍˄·͈༝·͈˄ ", |
| 1370 | + "૮ ˶ᵔ ᵕ ᵔ˶ ა", |
| 1371 | + "(* °ヮ° *) ", |
| 1372 | + " (ˊ•͈ ◡ •͈ˋ) " |
| 1373 | + ] |
| 1374 | + envs = { |
| 1375 | + "PROD": "https://secure.strateos.com", |
| 1376 | + "STAGING": "https://webapp.staging.strateos.com", |
| 1377 | + "LOCAL": "http://localhost:5000", |
| 1378 | + # "DOCKER": "http://host.docker.internal:5000" |
| 1379 | + } |
| 1380 | + |
| 1381 | + def parse_valid_env(env_str, envs): |
| 1382 | + try: |
| 1383 | + if env_str not in envs.keys(): |
| 1384 | + raise ValueError( |
| 1385 | + f'Environment "{env_str}" selected not in: {list(envs.keys())}') |
| 1386 | + else: |
| 1387 | + return env_str |
| 1388 | + except: |
| 1389 | + raise BadParameter( |
| 1390 | + f"Please enter one of the following {envs.keys()}" |
| 1391 | + ) |
| 1392 | + |
| 1393 | + if env is None: |
| 1394 | + click.echo("Select the which ENV you want to point to:") |
| 1395 | + env_map = [] |
| 1396 | + for name, endpoint in envs.items(): |
| 1397 | + env_map.append(name) |
| 1398 | + click.echo(f"{random.choice(rand)}\t{name}\t{endpoint}") |
| 1399 | + |
| 1400 | + |
| 1401 | + selected_env = click.prompt( |
| 1402 | + "Which ENV would you like to configure your session with", |
| 1403 | + default='STAGING', |
| 1404 | + prompt_suffix="? ", |
| 1405 | + type=str, |
| 1406 | + value_proc=lambda x: parse_valid_env(x, envs), |
| 1407 | + ) |
| 1408 | + else: |
| 1409 | + selected_env = parse_valid_env(env, envs) |
| 1410 | + return envs[selected_env] |
| 1411 | + |
| 1412 | + |
1321 | 1413 | def org_prompt(org_list): |
1322 | 1414 | """Organization prompt for helping with selecting organization""" |
1323 | 1415 | if len(org_list) < 1: |
|
0 commit comments