orrin-cli 0.2.0.2__tar.gz → 0.3.0b2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orrin_cli-0.3.0b2/PKG-INFO +16 -0
- orrin_cli-0.3.0b2/README.md +5 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin/cli.py +492 -0
- orrin_cli-0.3.0b2/orrin/default_websocket_handler.py +50 -0
- orrin_cli-0.3.0b2/orrin_cli.egg-info/PKG-INFO +16 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin_cli.egg-info/SOURCES.txt +1 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/pyproject.toml +1 -1
- orrin_cli-0.2.0.2/PKG-INFO +0 -18
- orrin_cli-0.2.0.2/README.md +0 -7
- orrin_cli-0.2.0.2/orrin_cli.egg-info/PKG-INFO +0 -18
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/LICENSE +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin/Spinner.py +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin/__init__.py +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin_cli.egg-info/dependency_links.txt +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin_cli.egg-info/entry_points.txt +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin_cli.egg-info/requires.txt +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/orrin_cli.egg-info/top_level.txt +0 -0
- {orrin_cli-0.2.0.2 → orrin_cli-0.3.0b2}/setup.cfg +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: orrin-cli
|
|
3
|
+
Version: 0.3.0b2
|
|
4
|
+
Summary: Orrin CLI
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: typer[all]>=0.12.0
|
|
9
|
+
Requires-Dist: click<8.2
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Orrin CLI v0.3.0b1
|
|
13
|
+
|
|
14
|
+
## What's New
|
|
15
|
+
|
|
16
|
+
In v0.3.0b1, the ability to create terminal sessions have been added. This includes many sub commands surrounding terminal sessions, including commands to pause and start sessions, as well as start default terminal session handlers.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Orrin CLI v0.3.0b1
|
|
2
|
+
|
|
3
|
+
## What's New
|
|
4
|
+
|
|
5
|
+
In v0.3.0b1, the ability to create terminal sessions have been added. This includes many sub commands surrounding terminal sessions, including commands to pause and start sessions, as well as start default terminal session handlers.
|
|
@@ -9,6 +9,8 @@ from platformdirs import user_config_dir
|
|
|
9
9
|
import yaml, tomli, toml
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from orrin.Spinner import Spinner
|
|
12
|
+
import websockets
|
|
13
|
+
import asyncio
|
|
12
14
|
|
|
13
15
|
app = typer.Typer(help="""
|
|
14
16
|
Welcome to Orrin CLI v0.1.9!\n\n
|
|
@@ -28,6 +30,9 @@ app.add_typer(ui, name="ui")
|
|
|
28
30
|
projects = typer.Typer(help='OrrinSDK project commands')
|
|
29
31
|
app.add_typer(projects, name='projects')
|
|
30
32
|
|
|
33
|
+
sessions = typer.Typer(help='Terminal Sessions enabling projects to be created in your terminal env from iOS and Web app')
|
|
34
|
+
app.add_typer(sessions, name='sessions')
|
|
35
|
+
|
|
31
36
|
API_BASE = "https://stellr-company.com"
|
|
32
37
|
|
|
33
38
|
APP_NAME = "orrin"
|
|
@@ -812,6 +817,493 @@ def itp():
|
|
|
812
817
|
|
|
813
818
|
# --------------------------------
|
|
814
819
|
|
|
820
|
+
# ---- Terminal Sessions ----
|
|
821
|
+
|
|
822
|
+
from default_websocket_handler import establish_default_handler
|
|
823
|
+
|
|
824
|
+
@sessions.command(help='''
|
|
825
|
+
Create a new terminal session. Once created, this session will automatically be live and will display in the iOS and Web applications
|
|
826
|
+
All sessions will be stored in developer configuration.
|
|
827
|
+
''')
|
|
828
|
+
def create():
|
|
829
|
+
config = load_config()
|
|
830
|
+
|
|
831
|
+
if config is None or not 'api_key' in config:
|
|
832
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
833
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
834
|
+
return
|
|
835
|
+
|
|
836
|
+
session_name = typer.prompt(
|
|
837
|
+
'Session Name',
|
|
838
|
+
hide_input=False
|
|
839
|
+
)
|
|
840
|
+
session_desc = typer.prompt(
|
|
841
|
+
'Session description',
|
|
842
|
+
hide_input=False
|
|
843
|
+
)
|
|
844
|
+
|
|
845
|
+
resp = requests.post(
|
|
846
|
+
f'{API_BASE}/api/terminal_sessions/create_terminal_session',
|
|
847
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] },
|
|
848
|
+
json={
|
|
849
|
+
'session_name': session_name,
|
|
850
|
+
'session_desc': session_desc
|
|
851
|
+
}
|
|
852
|
+
)
|
|
853
|
+
|
|
854
|
+
if resp.ok:
|
|
855
|
+
session_id = resp.json()['session_id'] # get session id
|
|
856
|
+
|
|
857
|
+
if not 'terminal_sessions' in config:
|
|
858
|
+
config['terminal_sessions'] = [
|
|
859
|
+
{
|
|
860
|
+
'session_name': session_name,
|
|
861
|
+
'session_desc': session_desc,
|
|
862
|
+
'session_id': session_id,
|
|
863
|
+
'active': True,
|
|
864
|
+
'connections': []
|
|
865
|
+
}
|
|
866
|
+
]
|
|
867
|
+
else:
|
|
868
|
+
config['terminal_sessions'].append({
|
|
869
|
+
'session_name': session_name,
|
|
870
|
+
'session_desc': session_desc,
|
|
871
|
+
'session_id': session_id,
|
|
872
|
+
'active': True,
|
|
873
|
+
'connections': []
|
|
874
|
+
})
|
|
875
|
+
|
|
876
|
+
write_config(config)
|
|
877
|
+
|
|
878
|
+
typer.echo(
|
|
879
|
+
'\n' + typer.style(
|
|
880
|
+
'Session created.',
|
|
881
|
+
fg=typer.colors.GREEN
|
|
882
|
+
) + '\n'
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
typer.echo(json.dumps({
|
|
886
|
+
'session_name': session_name,
|
|
887
|
+
'session_desc': session_desc,
|
|
888
|
+
'session_id': session_id,
|
|
889
|
+
'active': True,
|
|
890
|
+
'connections': []
|
|
891
|
+
}, indent=2) + '\n')
|
|
892
|
+
else:
|
|
893
|
+
try:
|
|
894
|
+
j = resp.json()
|
|
895
|
+
typer.echo(
|
|
896
|
+
'\n' + typer.style(
|
|
897
|
+
f'Failed to create session: {j["Message"]}.',
|
|
898
|
+
fg=typer.colors.RED
|
|
899
|
+
)
|
|
900
|
+
)
|
|
901
|
+
|
|
902
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
903
|
+
except:
|
|
904
|
+
typer.echo(
|
|
905
|
+
'\n' + typer.style(
|
|
906
|
+
f'Failed to create session: {resp.text}.',
|
|
907
|
+
fg=typer.colors.RED
|
|
908
|
+
)
|
|
909
|
+
)
|
|
910
|
+
|
|
911
|
+
@sessions.command(help='''
|
|
912
|
+
Delete an existing terminal session.
|
|
913
|
+
Developer configuration will be updated accordingly.
|
|
914
|
+
''')
|
|
915
|
+
def delete():
|
|
916
|
+
config = load_config()
|
|
917
|
+
|
|
918
|
+
if config is None or not 'api_key' in config:
|
|
919
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
920
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
921
|
+
return
|
|
922
|
+
|
|
923
|
+
if not 'terminal_sessions' in config:
|
|
924
|
+
typer.echo('\nYou have not created any terminal sessions. Run the below to create a session:')
|
|
925
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
926
|
+
return
|
|
927
|
+
|
|
928
|
+
if config['terminal_sessions'] == []:
|
|
929
|
+
typer.echo('\nYou have no terminal sessions available. Run the below to create a session:')
|
|
930
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
931
|
+
return
|
|
932
|
+
|
|
933
|
+
typer.echo('\nAvailable terminal sessions:')
|
|
934
|
+
|
|
935
|
+
for i in range(len(config['terminal_sessions'])):
|
|
936
|
+
typer.echo('\t' + f'{i+1}: {config["terminal_sessions"][i]["session_name"]}')
|
|
937
|
+
|
|
938
|
+
typer.echo()
|
|
939
|
+
session_to_delete = int(typer.prompt(
|
|
940
|
+
'Selection',
|
|
941
|
+
hide_input=False
|
|
942
|
+
)) - 1
|
|
943
|
+
|
|
944
|
+
if session_to_delete == -1 or session_to_delete > len(config['terminal_sessions']):
|
|
945
|
+
typer.echo('\nValue must be non-zero, or within bounds.')
|
|
946
|
+
return
|
|
947
|
+
|
|
948
|
+
session_id_to_delete = config['terminal_sessions'][session_to_delete]['session_id']
|
|
949
|
+
|
|
950
|
+
resp = requests.post(
|
|
951
|
+
f'{API_BASE}/api/terminal_sessions/delete_terminal_session',
|
|
952
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] },
|
|
953
|
+
json={
|
|
954
|
+
'session_id': session_id_to_delete
|
|
955
|
+
}
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
if resp.ok:
|
|
959
|
+
del config['terminal_sessions'][session_to_delete]
|
|
960
|
+
write_config(config)
|
|
961
|
+
|
|
962
|
+
typer.echo(
|
|
963
|
+
'\n' + typer.style(
|
|
964
|
+
'Session deleted. Remaining sessions:',
|
|
965
|
+
fg=typer.colors.GREEN
|
|
966
|
+
) + '\n'
|
|
967
|
+
)
|
|
968
|
+
|
|
969
|
+
if not config['terminal_sessions'] == []:
|
|
970
|
+
typer.echo(json.dumps(config['terminal_sessions'], indent=2) + '\n')
|
|
971
|
+
else:
|
|
972
|
+
typer.echo('You have no sessions.' + '\n')
|
|
973
|
+
else:
|
|
974
|
+
try:
|
|
975
|
+
j = resp.json()
|
|
976
|
+
typer.echo(
|
|
977
|
+
'\n' + typer.style(
|
|
978
|
+
f'Failed to delete session: {j["Message"]}.',
|
|
979
|
+
fg=typer.colors.RED
|
|
980
|
+
)
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
984
|
+
except:
|
|
985
|
+
typer.echo(
|
|
986
|
+
'\n' + typer.style(
|
|
987
|
+
f'Failed to delete session: {resp.text}.',
|
|
988
|
+
fg=typer.colors.RED
|
|
989
|
+
)
|
|
990
|
+
)
|
|
991
|
+
|
|
992
|
+
@sessions.command(help='Pauses a session (makes it to where connections are closed, and no new connections can be established)')
|
|
993
|
+
def pause():
|
|
994
|
+
config = load_config()
|
|
995
|
+
|
|
996
|
+
if config is None or not 'api_key' in config:
|
|
997
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
998
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
999
|
+
return
|
|
1000
|
+
|
|
1001
|
+
if not 'terminal_sessions' in config:
|
|
1002
|
+
typer.echo('\nYou have not created any terminal sessions. Run the below to create a session:')
|
|
1003
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1004
|
+
return
|
|
1005
|
+
|
|
1006
|
+
if config['terminal_sessions'] == []:
|
|
1007
|
+
typer.echo('\nYou have no terminal sessions available. Run the below to create a session:')
|
|
1008
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1009
|
+
return
|
|
1010
|
+
|
|
1011
|
+
active_sessions = [session for session in config['terminal_sessions'] if session['active']]
|
|
1012
|
+
|
|
1013
|
+
if active_sessions == []:
|
|
1014
|
+
typer.echo('\nYou have no active terminal sessions. All are paused. Run the below to start up a session:')
|
|
1015
|
+
typer.echo('\t' + typer.style(' orrin sessions start ', fg=typer.colors.YELLOW) + '\n')
|
|
1016
|
+
return
|
|
1017
|
+
|
|
1018
|
+
typer.echo('\nAvailable terminal sessions:')
|
|
1019
|
+
|
|
1020
|
+
for i in range(len(active_sessions)):
|
|
1021
|
+
typer.echo('\t' + f'{i+1}: {active_sessions[i]["session_name"]}')
|
|
1022
|
+
|
|
1023
|
+
typer.echo()
|
|
1024
|
+
session_to_pause = int(typer.prompt(
|
|
1025
|
+
'Selection',
|
|
1026
|
+
hide_input=False
|
|
1027
|
+
)) - 1
|
|
1028
|
+
|
|
1029
|
+
if session_to_pause == -1 or session_to_pause > len(active_sessions):
|
|
1030
|
+
typer.echo('\nValue must be non-zero, or within bounds.')
|
|
1031
|
+
return
|
|
1032
|
+
|
|
1033
|
+
session_id_to_pause = config['terminal_sessions'][session_to_pause]['session_id']
|
|
1034
|
+
|
|
1035
|
+
resp = requests.post(
|
|
1036
|
+
f'{API_BASE}/api/terminal_sessions/pause_terminal_session',
|
|
1037
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] },
|
|
1038
|
+
json={ 'session_id': session_id_to_pause }
|
|
1039
|
+
)
|
|
1040
|
+
|
|
1041
|
+
if resp.ok:
|
|
1042
|
+
for i in range(len(config['terminal_sessions'])):
|
|
1043
|
+
if config['terminal_sessions'][i]['session_id'] == session_id_to_pause:
|
|
1044
|
+
config['terminal_sessions'][i]['active'] = False
|
|
1045
|
+
break
|
|
1046
|
+
|
|
1047
|
+
write_config(config)
|
|
1048
|
+
|
|
1049
|
+
typer.echo(
|
|
1050
|
+
'\n' + typer.style(
|
|
1051
|
+
f'Session "{config["terminal_sessions"][session_to_pause]["session_name"]}" paused.',
|
|
1052
|
+
fg=typer.colors.GREEN
|
|
1053
|
+
) + '\n'
|
|
1054
|
+
)
|
|
1055
|
+
else:
|
|
1056
|
+
try:
|
|
1057
|
+
j = resp.json()
|
|
1058
|
+
typer.echo(
|
|
1059
|
+
'\n' + typer.style(
|
|
1060
|
+
f'Failed to pause session: {j["Message"]}.',
|
|
1061
|
+
fg=typer.colors.RED
|
|
1062
|
+
)
|
|
1063
|
+
)
|
|
1064
|
+
|
|
1065
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
1066
|
+
except:
|
|
1067
|
+
typer.echo(
|
|
1068
|
+
'\n' + typer.style(
|
|
1069
|
+
f'Failed to pause session: {resp.text}.',
|
|
1070
|
+
fg=typer.colors.RED
|
|
1071
|
+
)
|
|
1072
|
+
)
|
|
1073
|
+
|
|
1074
|
+
@sessions.command(help='Starts a session (makes it to where new connections can be established)')
|
|
1075
|
+
def start():
|
|
1076
|
+
config = load_config()
|
|
1077
|
+
|
|
1078
|
+
if config is None or not 'api_key' in config:
|
|
1079
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
1080
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
1081
|
+
return
|
|
1082
|
+
|
|
1083
|
+
if not 'terminal_sessions' in config:
|
|
1084
|
+
typer.echo('\nYou have not created any terminal sessions. Run the below to create a session:')
|
|
1085
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1086
|
+
return
|
|
1087
|
+
|
|
1088
|
+
if config['terminal_sessions'] == []:
|
|
1089
|
+
typer.echo('\nYou have no terminal sessions available. Run the below to create a session:')
|
|
1090
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1091
|
+
return
|
|
1092
|
+
|
|
1093
|
+
inactive_sessions = [session for session in config['terminal_sessions'] if not session['active']]
|
|
1094
|
+
|
|
1095
|
+
if inactive_sessions == []:
|
|
1096
|
+
typer.echo('\nYou have no inactive terminal sessions. All are live. Run the below to pause a session:')
|
|
1097
|
+
typer.echo('\t' + typer.style(' orrin sessions pause ', fg=typer.colors.YELLOW) + '\n')
|
|
1098
|
+
return
|
|
1099
|
+
|
|
1100
|
+
typer.echo('\nAvailable terminal sessions:')
|
|
1101
|
+
|
|
1102
|
+
for i in range(len(inactive_sessions)):
|
|
1103
|
+
typer.echo('\t' + f'{i+1}: {inactive_sessions[i]["session_name"]}')
|
|
1104
|
+
|
|
1105
|
+
typer.echo()
|
|
1106
|
+
session_to_start = int(typer.prompt(
|
|
1107
|
+
'Selection',
|
|
1108
|
+
hide_input=False
|
|
1109
|
+
)) - 1
|
|
1110
|
+
|
|
1111
|
+
if session_to_start == -1 or session_to_start > len(inactive_sessions):
|
|
1112
|
+
typer.echo('\nValue must be non-zero, or within bounds.')
|
|
1113
|
+
return
|
|
1114
|
+
|
|
1115
|
+
session_id_to_start = config['terminal_sessions'][session_to_start]['session_id']
|
|
1116
|
+
|
|
1117
|
+
resp = requests.post(
|
|
1118
|
+
f'{API_BASE}/api/terminal_sessions/start_terminal_session',
|
|
1119
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] },
|
|
1120
|
+
json={ 'session_id': session_id_to_start }
|
|
1121
|
+
)
|
|
1122
|
+
|
|
1123
|
+
if resp.ok:
|
|
1124
|
+
for i in range(len(config['terminal_sessions'])):
|
|
1125
|
+
if config['terminal_sessions'][i]['session_id'] == session_id_to_start:
|
|
1126
|
+
config['terminal_sessions'][i]['active'] = True
|
|
1127
|
+
break
|
|
1128
|
+
|
|
1129
|
+
write_config(config)
|
|
1130
|
+
|
|
1131
|
+
typer.echo(
|
|
1132
|
+
'\n' + typer.style(
|
|
1133
|
+
f'Session "{config["terminal_sessions"][session_to_start]["session_name"]}" started.',
|
|
1134
|
+
fg=typer.colors.GREEN
|
|
1135
|
+
) + '\n'
|
|
1136
|
+
)
|
|
1137
|
+
|
|
1138
|
+
typer.echo(
|
|
1139
|
+
'\n' + typer.style(
|
|
1140
|
+
f'Starting websocket...',
|
|
1141
|
+
fg=typer.colors.GREEN
|
|
1142
|
+
) + '\n'
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1145
|
+
asyncio.run(establish_default_handler(session_id_to_start, config['api_key']))
|
|
1146
|
+
else:
|
|
1147
|
+
try:
|
|
1148
|
+
j = resp.json()
|
|
1149
|
+
typer.echo(
|
|
1150
|
+
'\n' + typer.style(
|
|
1151
|
+
f'Failed to start session: {j["Message"]}.',
|
|
1152
|
+
fg=typer.colors.RED
|
|
1153
|
+
)
|
|
1154
|
+
)
|
|
1155
|
+
|
|
1156
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
1157
|
+
except:
|
|
1158
|
+
typer.echo(
|
|
1159
|
+
'\n' + typer.style(
|
|
1160
|
+
f'Failed to start session: {resp.text}.',
|
|
1161
|
+
fg=typer.colors.RED
|
|
1162
|
+
)
|
|
1163
|
+
)
|
|
1164
|
+
|
|
1165
|
+
@sessions.command(help='Start default websocket handler')
|
|
1166
|
+
def start_default_handler():
|
|
1167
|
+
config = load_config()
|
|
1168
|
+
|
|
1169
|
+
if config is None or not 'api_key' in config:
|
|
1170
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
1171
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
1172
|
+
return
|
|
1173
|
+
|
|
1174
|
+
if not 'terminal_sessions' in config:
|
|
1175
|
+
typer.echo('\nYou have not created any terminal sessions. Run the below to create a session:')
|
|
1176
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1177
|
+
return
|
|
1178
|
+
|
|
1179
|
+
if config['terminal_sessions'] == []:
|
|
1180
|
+
typer.echo('\nYou have no terminal sessions available. Run the below to create a session:')
|
|
1181
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1182
|
+
return
|
|
1183
|
+
|
|
1184
|
+
typer.echo('\nAvailable terminal sessions:')
|
|
1185
|
+
|
|
1186
|
+
for i in range(len(config['terminal_sessions'])):
|
|
1187
|
+
typer.echo('\t' + f'{i+1}: {config["terminal_sessions"][i]["session_name"]}')
|
|
1188
|
+
|
|
1189
|
+
typer.echo()
|
|
1190
|
+
session_to_start = int(typer.prompt(
|
|
1191
|
+
'Selection',
|
|
1192
|
+
hide_input=False
|
|
1193
|
+
)) - 1
|
|
1194
|
+
|
|
1195
|
+
if session_to_start == -1 or session_to_start > len(config['terminal_sessions']):
|
|
1196
|
+
typer.echo('\nValue must be non-zero, or within bounds.')
|
|
1197
|
+
return
|
|
1198
|
+
|
|
1199
|
+
asyncio.run(establish_default_handler(config['terminal_sessions'][session_to_start]['session_id'], config['api_key']))
|
|
1200
|
+
|
|
1201
|
+
@sessions.command(help='Remove a specific connection')
|
|
1202
|
+
def remove_connection(session_name: str, type: str, connection_name: str):
|
|
1203
|
+
config = load_config()
|
|
1204
|
+
|
|
1205
|
+
if config is None or not 'api_key' in config:
|
|
1206
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
1207
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
1208
|
+
return
|
|
1209
|
+
|
|
1210
|
+
if config['terminal_sessions'] == []:
|
|
1211
|
+
typer.echo('\nYou have no terminal sessions available. Run the below to create a session:')
|
|
1212
|
+
typer.echo('\t' + typer.style(' orrin sessions create ', fg=typer.colors.YELLOW) + '\n')
|
|
1213
|
+
return
|
|
1214
|
+
|
|
1215
|
+
if not any(session_name == session['session_name'] for session in config['terminal_sessions']):
|
|
1216
|
+
typer.echo(f'\nYou have no session `{session_name}`')
|
|
1217
|
+
return
|
|
1218
|
+
|
|
1219
|
+
connection_type = 'handler' if type == 'h' else 'sender'
|
|
1220
|
+
|
|
1221
|
+
resp = requests.post(
|
|
1222
|
+
f'{API_BASE}/api/terminal_sessions/remove_connection',
|
|
1223
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] },
|
|
1224
|
+
json={ 'session_name': session_name, 'connection_type': connection_type, 'connection_name': connection_name }
|
|
1225
|
+
)
|
|
1226
|
+
|
|
1227
|
+
if resp.ok:
|
|
1228
|
+
for i in range(len(config['terminal_sessions'])):
|
|
1229
|
+
if config['terminal_sessions'][i]['session_name'] == session_name:
|
|
1230
|
+
for c in range(len(config['terminal_sessions'][i]['connections'])):
|
|
1231
|
+
if config['terminal_sessions'][i]['connections'][c]['type'] == connection_type and config['terminal_sessions'][i]['connections'][c][f'{connection_type}_name'] == connection_name:
|
|
1232
|
+
del config['terminal_sessions'][i]['connections'][c]
|
|
1233
|
+
break
|
|
1234
|
+
|
|
1235
|
+
typer.echo(
|
|
1236
|
+
'\n' + typer.style(
|
|
1237
|
+
f'Connection removed',
|
|
1238
|
+
fg=typer.colors.GREEN
|
|
1239
|
+
) + '\n'
|
|
1240
|
+
)
|
|
1241
|
+
else:
|
|
1242
|
+
try:
|
|
1243
|
+
j = resp.json()
|
|
1244
|
+
typer.echo(
|
|
1245
|
+
'\n' + typer.style(
|
|
1246
|
+
f'Failed to remove connection from session `{session_name}`: {j["message"]}.',
|
|
1247
|
+
fg=typer.colors.RED
|
|
1248
|
+
)
|
|
1249
|
+
)
|
|
1250
|
+
|
|
1251
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
1252
|
+
except:
|
|
1253
|
+
typer.echo(
|
|
1254
|
+
'\n' + typer.style(
|
|
1255
|
+
f'Failed to remove connection session `{session_name}`: {resp.text}.',
|
|
1256
|
+
fg=typer.colors.RED
|
|
1257
|
+
)
|
|
1258
|
+
)
|
|
1259
|
+
|
|
1260
|
+
@sessions.command(help='Refresh sessions, ensuring state of sessions in configuration is up to date')
|
|
1261
|
+
def refresh():
|
|
1262
|
+
config = load_config()
|
|
1263
|
+
|
|
1264
|
+
if config is None or not 'api_key' in config:
|
|
1265
|
+
typer.echo('\nYou have not configured a developer API. Please run:')
|
|
1266
|
+
typer.echo('\t' + typer.style(' orrin config configure-dev ', fg=typer.colors.YELLOW) + '\n')
|
|
1267
|
+
return
|
|
1268
|
+
|
|
1269
|
+
resp = requests.get(
|
|
1270
|
+
f'{API_BASE}/api/terminal_sessions/sessions',
|
|
1271
|
+
headers={ 'fsdk': 'yes', 'authorization': config['api_key'] }
|
|
1272
|
+
)
|
|
1273
|
+
|
|
1274
|
+
if resp.ok:
|
|
1275
|
+
sessions = resp.json()['Sessions']
|
|
1276
|
+
config['sessions'] = sessions
|
|
1277
|
+
write_config(config)
|
|
1278
|
+
|
|
1279
|
+
typer.echo(
|
|
1280
|
+
'\n' + typer.style(
|
|
1281
|
+
'Refreshed sessions.',
|
|
1282
|
+
fg=typer.colors.GREEN
|
|
1283
|
+
) + '\n'
|
|
1284
|
+
)
|
|
1285
|
+
|
|
1286
|
+
typer.echo(json.dumps(sessions, indent=2) + '\n')
|
|
1287
|
+
else:
|
|
1288
|
+
try:
|
|
1289
|
+
j = resp.json()
|
|
1290
|
+
typer.echo(
|
|
1291
|
+
'\n' + typer.style(
|
|
1292
|
+
f'Failed to refresh sessions: {j["message"]}.',
|
|
1293
|
+
fg=typer.colors.RED
|
|
1294
|
+
)
|
|
1295
|
+
)
|
|
1296
|
+
|
|
1297
|
+
typer.echo(json.dumps(j, indent=2) + '\n')
|
|
1298
|
+
except:
|
|
1299
|
+
typer.echo(
|
|
1300
|
+
'\n' + typer.style(
|
|
1301
|
+
f'Failed to refresh sessions: {resp.text}.',
|
|
1302
|
+
fg=typer.colors.RED
|
|
1303
|
+
)
|
|
1304
|
+
)
|
|
1305
|
+
# ---------------------------
|
|
1306
|
+
|
|
815
1307
|
def main():
|
|
816
1308
|
app()
|
|
817
1309
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import websockets
|
|
2
|
+
import json
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
# Helper function: establish websockt connection as default handler
|
|
6
|
+
# Developer can create a sender websocket
|
|
7
|
+
async def establish_default_handler(session_id, auth):
|
|
8
|
+
async with websockets.connect(
|
|
9
|
+
f"wss://stellr-company.com/terminal_sessions/connect/{session_id}",
|
|
10
|
+
additional_headers={ 'authorization': auth }
|
|
11
|
+
) as ws:
|
|
12
|
+
await ws.send(json.dumps({'connection_type': 'handler', 'websocket_dependencies': []}))
|
|
13
|
+
data = await ws.recv()
|
|
14
|
+
data = json.loads(data)
|
|
15
|
+
connection_id = data['connection_id']
|
|
16
|
+
|
|
17
|
+
typer.echo(f'Default handler connection id: {connection_id}\nSession ID: {session_id}\nUse this when creating sender websockets.\nYou are free to create as many custom handlers/senders as you would like, and are not restricted to the default handler.\n')
|
|
18
|
+
|
|
19
|
+
while True:
|
|
20
|
+
data = await ws.recv()
|
|
21
|
+
data = json.loads(data)
|
|
22
|
+
|
|
23
|
+
if not 'type' in data: continue
|
|
24
|
+
|
|
25
|
+
match data['type']:
|
|
26
|
+
case 'close':
|
|
27
|
+
await ws.close()
|
|
28
|
+
break
|
|
29
|
+
case 'log':
|
|
30
|
+
if data['log_type'] == 'error':
|
|
31
|
+
typer.echo('\n' + typer.style(
|
|
32
|
+
f'Error: {data["log_message"]}',
|
|
33
|
+
fg=typer.colors.RED
|
|
34
|
+
) + '\n')
|
|
35
|
+
elif data['log_type'] == 'warning':
|
|
36
|
+
typer.echo('\n' + typer.style(
|
|
37
|
+
f'Warning: {data["log_message"]}',
|
|
38
|
+
fg=typer.colors.YELLOW
|
|
39
|
+
) + '\n')
|
|
40
|
+
else:
|
|
41
|
+
typer.echo('\n' + typer.style(
|
|
42
|
+
f'Log: {data["log_message"]}',
|
|
43
|
+
fg=typer.colors.WHITE
|
|
44
|
+
) + '\n')
|
|
45
|
+
|
|
46
|
+
await ws.send(json.dumps({
|
|
47
|
+
'type': 'respond',
|
|
48
|
+
'response_type': 'received',
|
|
49
|
+
'to': data["from"]
|
|
50
|
+
}))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: orrin-cli
|
|
3
|
+
Version: 0.3.0b2
|
|
4
|
+
Summary: Orrin CLI
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: typer[all]>=0.12.0
|
|
9
|
+
Requires-Dist: click<8.2
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Orrin CLI v0.3.0b1
|
|
13
|
+
|
|
14
|
+
## What's New
|
|
15
|
+
|
|
16
|
+
In v0.3.0b1, the ability to create terminal sessions have been added. This includes many sub commands surrounding terminal sessions, including commands to pause and start sessions, as well as start default terminal session handlers.
|
orrin_cli-0.2.0.2/PKG-INFO
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: orrin-cli
|
|
3
|
-
Version: 0.2.0.2
|
|
4
|
-
Summary: Orrin CLI
|
|
5
|
-
Requires-Python: >=3.9
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
9
|
-
Requires-Dist: click<8.2
|
|
10
|
-
Dynamic: license-file
|
|
11
|
-
|
|
12
|
-
# Orrin CLI v0.2.0.2
|
|
13
|
-
|
|
14
|
-
## What's New
|
|
15
|
-
|
|
16
|
-
In v0.2.0.2, a minor change was made to support new icon sizes of 64x64, 128x128, 256x256, and 512x512.
|
|
17
|
-
|
|
18
|
-
Please refer to [the docs](https://stellr-company.com/orrin/docs) for more information over Orrin CLI.
|
orrin_cli-0.2.0.2/README.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: orrin-cli
|
|
3
|
-
Version: 0.2.0.2
|
|
4
|
-
Summary: Orrin CLI
|
|
5
|
-
Requires-Python: >=3.9
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
9
|
-
Requires-Dist: click<8.2
|
|
10
|
-
Dynamic: license-file
|
|
11
|
-
|
|
12
|
-
# Orrin CLI v0.2.0.2
|
|
13
|
-
|
|
14
|
-
## What's New
|
|
15
|
-
|
|
16
|
-
In v0.2.0.2, a minor change was made to support new icon sizes of 64x64, 128x128, 256x256, and 512x512.
|
|
17
|
-
|
|
18
|
-
Please refer to [the docs](https://stellr-company.com/orrin/docs) for more information over Orrin CLI.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|