praetorian-cli 2.2.13__py3-none-any.whl → 2.2.14__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.
@@ -64,25 +64,19 @@ class Chariot:
64
64
  import urllib3
65
65
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
66
66
 
67
- def chariot_request(self, method: str, url: str, **kwargs) -> requests.Response:
67
+ def chariot_request(self, method: str, url: str, headers: dict = {}, **kwargs) -> requests.Response:
68
68
  """
69
- Centralized method to make HTTP requests to the Chariot API with all global headers/parameters set.
69
+ Centralized wrapper around requests.request. Take care of proxy, beta flag, and
70
+ supplies the authentication headers
70
71
  """
71
-
72
72
  self.add_beta_url_param(kwargs)
73
73
 
74
- return self.request(method, url, self.keychain.headers(), **kwargs)
75
-
76
- def request(self, method: str, url: str, headers: dict = None, **kwargs) -> requests.Response:
77
- """
78
- Centralized wrapper around requests.request, ensuring the HTTP proxy is respected.
79
- """
80
-
81
74
  if self.proxy:
82
75
  kwargs['proxies'] = {'http': self.proxy, 'https': self.proxy}
83
76
  kwargs['verify'] = False
84
77
 
85
- return requests.request(method, url, headers=headers, **kwargs)
78
+ return requests.request(method, url, headers=(headers | self.keychain.headers()), **kwargs)
79
+
86
80
 
87
81
  def add_beta_url_param(self, kwargs: dict):
88
82
  if 'params' in kwargs:
@@ -206,8 +200,12 @@ class Chariot:
206
200
  return resp
207
201
 
208
202
  def _upload(self, chariot_filepath: str, content: str) -> dict:
209
- # It is a two-step upload. The PUT request to the /file endpoint is to get a presigned URL for S3.
210
- # There is no data transfer.
203
+ # Encrypted files have _encrypted/ prefix in the path. Encrypted files do not use presigned URLs.
204
+ # Instead, they use the /encrypted-file endpoint that directly gets and puts content.
205
+ if is_encrypted_partition(chariot_filepath):
206
+ return self.chariot_request('PUT', self.url('/encrypted-file'), params=dict(name=chariot_filepath), data=content)
207
+
208
+ # Regular files use presigned URLs
211
209
  presigned_url = self.chariot_request('PUT', self.url('/file'), params=dict(name=chariot_filepath))
212
210
  process_failure(presigned_url)
213
211
  resp = requests.put(presigned_url.json()['url'], data=content)
@@ -216,6 +214,15 @@ class Chariot:
216
214
 
217
215
  def download(self, name: str, global_=False) -> bytes:
218
216
  params = dict(name=name)
217
+ # Encrypted files have _encrypted/ prefix in the path. Encrypted files do not use presigned URLs.
218
+ # Instead, they use the /encrypted-file endpoint that directly gets and puts content.
219
+ if is_encrypted_partition(name):
220
+ accept_binary = {'Accept': 'application/octet-stream'}
221
+ resp = self.chariot_request('GET', self.url('/encrypted-file'), params=params, headers=accept_binary)
222
+ process_failure(resp)
223
+ return resp.content
224
+
225
+ # Regular files, use presigned URLs
219
226
  if global_:
220
227
  params |= GLOBAL_FLAG
221
228
 
@@ -228,7 +235,7 @@ class Chariot:
228
235
  message = f'Download request failed: response missing URL' + (f'\nBody: {resp.text}' if resp.text else '(empty)')
229
236
  raise Exception(message)
230
237
 
231
- resp = self.request('GET', url)
238
+ resp = requests.request('GET', url)
232
239
  process_failure(resp)
233
240
  return resp.content
234
241
 
@@ -355,3 +362,7 @@ def extend(accumulate: dict, new: dict) -> dict:
355
362
  extend(accumulate[key], value)
356
363
 
357
364
  return accumulate
365
+
366
+
367
+ def is_encrypted_partition(chariot_filepath: str) -> bool:
368
+ return chariot_filepath.startswith('_encrypted/')
@@ -12,6 +12,7 @@ class TestFile:
12
12
  self.sdk = setup_chariot()
13
13
  micro = epoch_micro()
14
14
  self.chariot_filepath = f'home/test-file-{micro}.txt'
15
+ self.encrypted_chariot_filepath = f'_encrypted/test-file-{micro}.txt'
15
16
  self.sanitized_filepath = f'home_test-file-{micro}.txt'
16
17
  self.bogus_filepath = f'bogus-filepath-{micro}.txt'
17
18
  self.local_filepath = f'./test-file-{micro}.txt'
@@ -52,6 +53,21 @@ class TestFile:
52
53
  self.sdk.files.get(self.chariot_filepath)
53
54
  assert str(ex_info.value) == f'File {self.chariot_filepath} not found.'
54
55
 
56
+ def test_add_encrypted_file(self):
57
+ self.sdk.files.add(self.local_filepath, self.encrypted_chariot_filepath)
58
+ files, offset = self.sdk.files.list(self.encrypted_chariot_filepath)
59
+ assert files[0]['name'] == self.encrypted_chariot_filepath
60
+
61
+ def test_get_encrypted_file(self):
62
+ content = self.sdk.files.get_utf8(self.encrypted_chariot_filepath)
63
+ assert content == self.content
64
+
65
+ def test_delete_encrypted_file(self):
66
+ self.sdk.files.delete(self.encrypted_chariot_filepath)
67
+ with pytest.raises(Exception) as ex_info:
68
+ self.sdk.files.get(self.encrypted_chariot_filepath)
69
+ assert str(ex_info.value) == f'File {self.encrypted_chariot_filepath} not found.'
70
+
55
71
  def teardown_class(self):
56
72
  os.remove(self.local_filepath)
57
73
  os.remove(self.sanitized_filepath)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: praetorian-cli
3
- Version: 2.2.13
3
+ Version: 2.2.14
4
4
  Summary: For interacting with the Chariot API
5
5
  Home-page: https://github.com/praetorian-inc/praetorian-cli
6
6
  Author: Praetorian
@@ -25,7 +25,7 @@ praetorian_cli/scripts/utils.py,sha256=lGCf4trEpsfECa9U42pDJ-f48EimlS-hG6AjnKjNt
25
25
  praetorian_cli/scripts/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  praetorian_cli/scripts/commands/nmap-example.py,sha256=varKTkHKG4DAs9Ssf0c6SygP9GfuCG01aFxhfvixLM0,2727
27
27
  praetorian_cli/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
- praetorian_cli/sdk/chariot.py,sha256=owN3nRg5Oh-p88PGOQ7DpHflkcMxBsE1xS1aAU_lOvA,13926
28
+ praetorian_cli/sdk/chariot.py,sha256=amMgs7FxX9DY0tWNoizg7XfrVYWyLixbqqcaBQsuAKg,14626
29
29
  praetorian_cli/sdk/keychain.py,sha256=KCz2mOTv09jgg6mrZQooRg1VrnvF9W0_BjRlEQhbzqU,7468
30
30
  praetorian_cli/sdk/mcp_server.py,sha256=8UoTotD4UVl-tp1gqMjkOVpO__KeGCvy7mIpKXVc8Rg,8750
31
31
  praetorian_cli/sdk/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -68,7 +68,7 @@ praetorian_cli/sdk/test/test_configuration.py,sha256=ysyWpt7iq_tNkdvLU8gULCuwbXV
68
68
  praetorian_cli/sdk/test/test_conversation.py,sha256=i1cBaRmFmtLcFLr85OtgE60DynUgWB7EqqjGU-NBWvc,6951
69
69
  praetorian_cli/sdk/test/test_definition.py,sha256=8ShZFXJYHJUPH5rfmF3LYk9NE8W4lJBNHE2DhyJgXaY,1016
70
70
  praetorian_cli/sdk/test/test_extend.py,sha256=bHTCwtW0jN1GvFocB_uMJcEj4_IXvCkr35yMWKESbTU,1778
71
- praetorian_cli/sdk/test/test_file.py,sha256=rRikM2ceMy5TEX7YOFMPB2dnCRqROE9w8qoqVeCs9HM,2133
71
+ praetorian_cli/sdk/test/test_file.py,sha256=ZpFBSKbfq9kzfQdy_tmwCH8rwYxW6GB4NlhTQHEw87Y,2940
72
72
  praetorian_cli/sdk/test/test_job.py,sha256=J7VqnVxRfvbpxNnYN9Rt3LvxmbNvSKwVqsSZxFEW1xc,1916
73
73
  praetorian_cli/sdk/test/test_key.py,sha256=yDrR0-JLwMB3eDx-tI-ss8GGbiJaJijE4dAK8-FUuzc,1425
74
74
  praetorian_cli/sdk/test/test_mcp.py,sha256=Ltg283j4Q12dcfCgUgDMKk6neRdDaThcndyywZl5XWs,938
@@ -96,9 +96,9 @@ praetorian_cli/ui/aegis/commands/set.py,sha256=WJ0Qt30fBa_hyWEaawyA3h3rSeWHFPbJS
96
96
  praetorian_cli/ui/aegis/commands/ssh.py,sha256=KGsNlN0i-Cwp6gWyr-cjML9_L13oE7xFenysF2pC8Rc,3045
97
97
  praetorian_cli/ui/conversation/__init__.py,sha256=sNhNN_ZG1Va_7OLTaoXlIFL6ageKHWdufFVYw6F_aV8,90
98
98
  praetorian_cli/ui/conversation/textual_chat.py,sha256=gGgEs7HhNAto9rTVrGbz62mG10OqmtArI-aKxFLSfVs,24405
99
- praetorian_cli-2.2.13.dist-info/licenses/LICENSE,sha256=Zv97QripiVALv-WokW_Elsiz9vtOfbtNt1aLZhhk67I,1067
100
- praetorian_cli-2.2.13.dist-info/METADATA,sha256=MUJwo3wrkUulp376p98YNPnFC_tmNaMvSwGWbANr5xI,7752
101
- praetorian_cli-2.2.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
102
- praetorian_cli-2.2.13.dist-info/entry_points.txt,sha256=uJbDvZdkYaLiCh2DMvXPUGKFm2p5ZfzJCizUK3-PUEE,56
103
- praetorian_cli-2.2.13.dist-info/top_level.txt,sha256=QbUdRPGEj_TyHO-E7AD5BxFfR8ore37i273jP4Gn43c,15
104
- praetorian_cli-2.2.13.dist-info/RECORD,,
99
+ praetorian_cli-2.2.14.dist-info/licenses/LICENSE,sha256=Zv97QripiVALv-WokW_Elsiz9vtOfbtNt1aLZhhk67I,1067
100
+ praetorian_cli-2.2.14.dist-info/METADATA,sha256=Nks5hBUNGyPMWrjo3B3PnexprHRYdxHBXH880UcBouY,7752
101
+ praetorian_cli-2.2.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
102
+ praetorian_cli-2.2.14.dist-info/entry_points.txt,sha256=uJbDvZdkYaLiCh2DMvXPUGKFm2p5ZfzJCizUK3-PUEE,56
103
+ praetorian_cli-2.2.14.dist-info/top_level.txt,sha256=QbUdRPGEj_TyHO-E7AD5BxFfR8ore37i273jP4Gn43c,15
104
+ praetorian_cli-2.2.14.dist-info/RECORD,,