openshell-shared 0.1.2__py3-none-any.whl

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.
Files changed (62) hide show
  1. api/__init__.py +1 -0
  2. api/manager/__init__.py +1 -0
  3. api/manager/v1/__init__.py +78 -0
  4. api/manager/v1/authentication.py +278 -0
  5. api/manager/v1/client.py +111 -0
  6. api/manager/v1/domains.py +64 -0
  7. api/manager/v1/entities.py +97 -0
  8. api/manager/v1/exceptions.py +98 -0
  9. api/manager/v1/identity.py +44 -0
  10. api/manager/v1/models.py +342 -0
  11. api/manager/v1/passports.py +131 -0
  12. api/manager/v1/sessions.py +83 -0
  13. api/manager/v1/transport.py +253 -0
  14. api/manager/v1/tunnels.py +120 -0
  15. cryptography/__init__.py +0 -0
  16. cryptography/certificate.py +390 -0
  17. cryptography/encoding.py +0 -0
  18. cryptography/identity.py +124 -0
  19. cryptography/keys.py +463 -0
  20. cryptography/signatures.py +63 -0
  21. cryptography/utils.py +0 -0
  22. domain/__init__.py +0 -0
  23. domain/domain.py +80 -0
  24. domain/membership.py +21 -0
  25. domain/permissions.py +14 -0
  26. domain/policies.py +2 -0
  27. identity/__init__.py +0 -0
  28. identity/identification.py +64 -0
  29. identity/store.py +150 -0
  30. modules/__init__.py +0 -0
  31. modules/shell/__init__.py +0 -0
  32. modules/shell/client.py +361 -0
  33. modules/shell/models.py +61 -0
  34. modules/shell/protocol.py +249 -0
  35. modules/shell/server.py +511 -0
  36. modules/shell/session.py +339 -0
  37. modules/utils.py +212 -0
  38. openshell_shared-0.1.2.dist-info/METADATA +59 -0
  39. openshell_shared-0.1.2.dist-info/RECORD +62 -0
  40. openshell_shared-0.1.2.dist-info/WHEEL +5 -0
  41. openshell_shared-0.1.2.dist-info/top_level.txt +7 -0
  42. protocols/__init__.py +0 -0
  43. protocols/negotiation/challenge.py +127 -0
  44. protocols/negotiation/models.py +28 -0
  45. standards/__init__.py +0 -0
  46. standards/certificates/__init__.py +0 -0
  47. standards/certificates/status.py +12 -0
  48. standards/certificates/types.py +11 -0
  49. standards/entities/__init__.py +0 -0
  50. standards/entities/types.py +14 -0
  51. standards/events/__init__.py +0 -0
  52. standards/events/schemas/__init__.py +0 -0
  53. standards/events/schemas/entity_registered.py +13 -0
  54. standards/events/types.py +18 -0
  55. standards/passports/__init__.py +0 -0
  56. standards/passports/types.py +5 -0
  57. standards/permissions/__init__.py +0 -0
  58. standards/permissions/types.py +14 -0
  59. standards/roles/__init__.py +0 -0
  60. standards/roles/types.py +8 -0
  61. standards/transports/__init__.py +0 -0
  62. standards/transports/types.py +24 -0
@@ -0,0 +1,249 @@
1
+ # shell/protocol.py
2
+
3
+ # =====================================================
4
+ # LIBRARY IMPORTS
5
+ # =====================================================
6
+
7
+ import time
8
+
9
+ from uuid6 import uuid7
10
+
11
+ from .models import (
12
+ ProtocolType,
13
+ ProtocolStandard
14
+ )
15
+
16
+
17
+ # =====================================================
18
+ # PACKAGE BASE
19
+ # =====================================================
20
+
21
+ class PackageBase:
22
+
23
+ def __init__(
24
+ self,
25
+ auth_token: str,
26
+ tunnel_token: str,
27
+ session_token: str
28
+ ):
29
+
30
+ self.auth_token = auth_token
31
+ self.tunnel_token = tunnel_token
32
+ self.session_token = session_token
33
+
34
+ def header(self) -> dict:
35
+
36
+ return {
37
+ "auth_token":
38
+ self.auth_token,
39
+
40
+ "tunnel_token":
41
+ self.tunnel_token,
42
+
43
+ "session_token":
44
+ self.session_token,
45
+
46
+ "packet_type":
47
+ "DATA"
48
+ }
49
+
50
+
51
+ # =====================================================
52
+ # SHELL PROTOCOL
53
+ # =====================================================
54
+
55
+ class ShellProtocol(
56
+ PackageBase
57
+ ):
58
+
59
+ PROTOCOL = (
60
+ ProtocolStandard.SHELL
61
+ )
62
+
63
+ PROTOCOL_VERSION = 2
64
+
65
+ # ================================================
66
+ # INTERNAL
67
+ # ================================================
68
+
69
+ def _payload(
70
+ self,
71
+ protocol_type: str,
72
+ event: str,
73
+ **kwargs
74
+ ):
75
+
76
+ payload = {
77
+ "protocol":
78
+ self.PROTOCOL.value,
79
+
80
+ "protocol_type":
81
+ protocol_type,
82
+
83
+ "protocol_version":
84
+ self.PROTOCOL_VERSION,
85
+
86
+ "event":
87
+ event,
88
+
89
+ "timestamp":
90
+ time.time()
91
+ }
92
+
93
+ payload.update(kwargs)
94
+
95
+ return payload
96
+
97
+ # ================================================
98
+ # CLIENT EVENTS
99
+ # ================================================
100
+
101
+ def open(self):
102
+
103
+ packet = self.header()
104
+
105
+ packet["payload"] = (
106
+ self._payload(
107
+ protocol_type=
108
+ ProtocolType.CLIENT.value,
109
+
110
+ event="OPEN",
111
+
112
+ request_id=
113
+ str(uuid7())
114
+ )
115
+ )
116
+
117
+ return packet
118
+
119
+ def input(
120
+ self,
121
+ data: str
122
+ ):
123
+
124
+ packet = self.header()
125
+
126
+ packet["payload"] = (
127
+ self._payload(
128
+ protocol_type=
129
+ ProtocolType.CLIENT.value,
130
+
131
+ event="INPUT",
132
+
133
+ data=data
134
+ )
135
+ )
136
+
137
+ return packet
138
+
139
+ def resize(
140
+ self,
141
+ rows: int,
142
+ cols: int
143
+ ):
144
+
145
+ packet = self.header()
146
+
147
+ packet["payload"] = (
148
+ self._payload(
149
+ protocol_type=
150
+ ProtocolType.CLIENT.value,
151
+
152
+ event="RESIZE",
153
+
154
+ rows=rows,
155
+ cols=cols
156
+ )
157
+ )
158
+
159
+ return packet
160
+
161
+ def signal(
162
+ self,
163
+ signal_name: str
164
+ ):
165
+
166
+ packet = self.header()
167
+
168
+ packet["payload"] = (
169
+ self._payload(
170
+ protocol_type=
171
+ ProtocolType.CLIENT.value,
172
+
173
+ event="SIGNAL",
174
+
175
+ signal=signal_name
176
+ )
177
+ )
178
+
179
+ return packet
180
+
181
+ def close(self):
182
+
183
+ packet = self.header()
184
+
185
+ packet["payload"] = (
186
+ self._payload(
187
+ protocol_type=
188
+ ProtocolType.CLIENT.value,
189
+
190
+ event="CLOSE"
191
+ )
192
+ )
193
+
194
+ return packet
195
+
196
+ # ================================================
197
+ # SERVER EVENTS
198
+ # ================================================
199
+
200
+ def output(
201
+ self,
202
+ session_token: str,
203
+ data: str
204
+ ):
205
+
206
+ packet = self.header()
207
+
208
+ packet["session_token"] = (
209
+ session_token
210
+ )
211
+
212
+ packet["payload"] = (
213
+ self._payload(
214
+ protocol_type=
215
+ ProtocolType.SERVER.value,
216
+
217
+ event="OUTPUT",
218
+
219
+ data=data
220
+ )
221
+ )
222
+
223
+ return packet
224
+
225
+ def exit(
226
+ self,
227
+ session_token: str,
228
+ return_code: int
229
+ ):
230
+
231
+ packet = self.header()
232
+
233
+ packet["session_token"] = (
234
+ session_token
235
+ )
236
+
237
+ packet["payload"] = (
238
+ self._payload(
239
+ protocol_type=
240
+ ProtocolType.SERVER.value,
241
+
242
+ event="EXIT",
243
+
244
+ return_code=
245
+ return_code
246
+ )
247
+ )
248
+
249
+ return packet