remotivelabs-cli 0.0.1a13__tar.gz → 0.0.1a15__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.
Files changed (23) hide show
  1. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/PKG-INFO +1 -1
  2. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/auth_tokens.py +2 -3
  3. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/recordings.py +99 -1
  4. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/rest_helper.py +6 -4
  5. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/service_account_tokens.py +2 -2
  6. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/pyproject.toml +1 -1
  7. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/LICENSE +0 -0
  8. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/README.md +0 -0
  9. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/__about__.py +0 -0
  10. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/__init__.py +0 -0
  11. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/brokers.py +0 -0
  12. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/__init__.py +0 -0
  13. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/auth.py +0 -0
  14. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/brokers.py +0 -0
  15. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/cloud_cli.py +0 -0
  16. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/configs.py +0 -0
  17. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/projects.py +0 -0
  18. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/cloud/service_accounts.py +0 -0
  19. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/lib/__about__.py +0 -0
  20. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/lib/broker.py +0 -0
  21. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/remotive.py +0 -0
  22. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/requirements.txt +0 -0
  23. {remotivelabs_cli-0.0.1a13 → remotivelabs_cli-0.0.1a15}/cli/test/test_simple.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: remotivelabs-cli
3
- Version: 0.0.1a13
3
+ Version: 0.0.1a15
4
4
  Summary:
5
5
  Author: Johan Rask
6
6
  Author-email: johan.rask@remotivelabs.com
@@ -35,11 +35,10 @@ def list_personal_access_tokens():
35
35
 
36
36
  @app.command(name="revoke", help="Revoke the specified access token")
37
37
  def revoke(
38
- token_name: str = typer.Option(..., help="Name of the access token to revoke")
38
+ name: str = typer.Option(..., help="Name of the access token to revoke")
39
39
  ):
40
40
  rest.ensure_auth_token()
41
- rest.handle_delete(f'/api/me/keys/{token_name}')
42
-
41
+ rest.handle_delete(f'/api/me/keys/{name}', success_msg="Successfully revoked")
43
42
 
44
43
  @app.command()
45
44
  def describe(
@@ -1,13 +1,16 @@
1
1
  import sys
2
2
  import signal
3
3
  import re
4
+ import pathlib
4
5
  from multiprocessing import Process
5
6
  import typer
6
7
  import requests
7
8
  import os
9
+
10
+ import glob
8
11
  import json
9
12
  import shutil
10
- from rich.progress import Progress, SpinnerColumn, TextColumn
13
+ from rich.progress import Progress, SpinnerColumn, TextColumn,TaskProgressColumn
11
14
  from . import rest_helper as rest
12
15
 
13
16
  app = typer.Typer()
@@ -192,6 +195,101 @@ def upload(path: str = typer.Argument(..., help="Path to valid recording to upl
192
195
  else:
193
196
  print(r.text)
194
197
 
198
+ @app.command()
199
+ def upload_broker_configuration(
200
+ directory:str = typer.Argument(..., help="Configuration directory"),
201
+ recording_session: str = typer.Option(..., help="Recording session id", envvar='REMOTIVE_CLOUD_RECORDING_SESSION'),
202
+ project: str = typer.Option(..., help="Project ID", envvar='REMOTIVE_CLOUD_PROJECT'),
203
+ overwrite: bool = typer.Option(False, help="Overwrite existing configuration if it exists")
204
+ ):
205
+ with Progress(
206
+ SpinnerColumn(),
207
+ TextColumn("[progress.description]{task.description}"),
208
+ transient=True,
209
+ ) as progress:
210
+
211
+ #
212
+ # List files in specified directory. Look for interfaces.json and use that directory where this is located
213
+ # as configuration home directory
214
+ #
215
+ files = list(filter(lambda item : "interfaces.json" in item, glob.iglob(directory + '**/**', recursive=True)))
216
+ if len(files) == 0:
217
+ sys.stderr.write("No interfaces.json found in directory, this file is required")
218
+ raise typer.Exit(1)
219
+ if len(files) > 1:
220
+ sys.stderr.write(f"{len(files)} interfaces.json found in directoryw which is not supported")
221
+ raise typer.Exit(1)
222
+ broker_config_dir_name = os.path.dirname(files[0]).rsplit('/', 1)[-1]
223
+
224
+ #
225
+ # Get the current details about broker configurations to see if a config with this
226
+ # name already exists
227
+ #
228
+ task=progress.add_task(description=f"Preparing upload of {broker_config_dir_name}", total=1)
229
+ details_resp=rest.handle_get(f"/api/project/{project}/files/recording/{recording_session}", return_response=True)
230
+ details=details_resp.json()
231
+ existing_configs = details['brokerConfigurations']
232
+ if (len(existing_configs) > 0):
233
+ data=list(filter(lambda x : x['name'] == broker_config_dir_name, existing_configs))
234
+ if len(data) > 0:
235
+ if (overwrite):
236
+ rest.handle_delete(f'/api/project/{project}/files/recording/{recording_session}/configuration/{broker_config_dir_name}', quiet=True)
237
+ else:
238
+ sys.stderr.write("Broker configuration already exists, use --overwrite to replace\n")
239
+ raise typer.Exit(1)
240
+
241
+ #
242
+ # From the list of files, create a tuple of local_path to the actual file
243
+ # and a remote path as it should be stored in cloud
244
+ #
245
+ file_infos = list(map(lambda item :
246
+ { 'local_path' : item,
247
+ 'remote_path' : f"/{broker_config_dir_name}{item.rsplit(broker_config_dir_name,1)[-1]}"} ,glob.iglob(directory + '**/*.*', recursive=True)))
248
+
249
+ #
250
+ # convert this remote paths and ask cloud to prepare upload urls for those
251
+ #
252
+ json_request_upload_urls_req = {
253
+ 'name' : 'not_used',
254
+ 'paths' : list(map(lambda x: x['remote_path'], file_infos))
255
+ }
256
+
257
+ response = rest.handle_put(url = f'/api/project/{project}/files/recording/{recording_session}/configuration', return_response=True, body=json.dumps(json_request_upload_urls_req))
258
+ if (response.status_code != 200):
259
+ print(f'Failed to prepare configuration upload')
260
+ print(f'{response.text} - {response.status_code}')
261
+ raise typer.Exit(1)
262
+ progress.update(task, advance=1)
263
+
264
+
265
+
266
+ task=progress.add_task(description=f"Uploading {broker_config_dir_name}", total=len(file_infos))
267
+
268
+ #
269
+ # Upload urls is a remote_path : upload_url dict
270
+ # '/my_config/interfaces.json' : "<upload_url>"
271
+ #
272
+ upload_urls = json.loads(response.text)
273
+
274
+ # For each file - upload
275
+ for file in file_infos:
276
+ key=file['remote_path']
277
+ path=file['local_path']
278
+ url=upload_urls[key]
279
+ headers={
280
+ 'Content-Type' : "application/x-www-form-urlencoded"
281
+ }
282
+ r = requests.put(url, open(path, 'rb'), headers=headers)
283
+ progress.update(task, advance=1)
284
+ if r.status_code != 200:
285
+ print("Failed to upload broker configuration")
286
+ print(r.status_code)
287
+ print(r.text)
288
+ typer.Exit(1)
289
+
290
+ print(f"Successfully uploaded broker configuration {broker_config_dir_name}")
291
+
292
+
195
293
 
196
294
  @app.command(help="Downloads the specified broker configuration directory as zip file")
197
295
  def download_configuration(
@@ -77,17 +77,19 @@ def has_access(url, params={}):
77
77
  return True
78
78
 
79
79
 
80
- def handle_delete(url, params={}):
80
+ def handle_delete(url, params={}, quiet=False, success_msg="Successfully deleted"):
81
81
  ensure_auth_token()
82
82
  r = requests.delete(f'{base_url}{url}', headers=headers, params=params)
83
83
  if r.status_code == 200:
84
- print(json.dumps(r.json()))
84
+ if quiet == False:
85
+ print(json.dumps(r.json()))
85
86
  if r.status_code == 204:
86
- sys.stderr.write('Successfully deleted\n')
87
+ if quiet == False:
88
+ sys.stderr.write(f'{success_msg}\n')
87
89
  else:
88
90
  print(f'Got status code: {r.status_code}')
89
91
  print(r.text)
90
-
92
+ typer.Exit(1)
91
93
 
92
94
  def handle_post(url, body=None, params={}, return_response: bool = False):
93
95
  ensure_auth_token()
@@ -47,10 +47,10 @@ def list_files():
47
47
 
48
48
  @app.command(name="revoke", help="Revoke service account access token")
49
49
  def revoke(
50
+ name: str = typer.Argument(..., help="Access token name"),
50
51
  service_account: str = typer.Option(..., help="Service account name"),
51
- token_name: str = typer.Option(..., help="Access token name"),
52
52
  project: str = typer.Option(..., help="Project ID", envvar='REMOTIVE_CLOUD_PROJECT')):
53
- rest.handle_delete(f"/api/project/{project}/admin/accounts/{service_account}/keys/{token_name}")
53
+ rest.handle_delete(f"/api/project/{project}/admin/accounts/{service_account}/keys/{name}")
54
54
 
55
55
 
56
56
  def write_token(file, token):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "remotivelabs-cli"
3
- version = "0.0.1.alpha13"
3
+ version = "0.0.1.alpha15"
4
4
  description = ""
5
5
  authors = ["Johan Rask <johan.rask@remotivelabs.com>"]
6
6
  readme = "README.md"