remotivelabs-cli 0.0.1a3__py3-none-any.whl → 0.0.1a4__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.
cli/cloud/auth.py CHANGED
@@ -8,19 +8,21 @@ from pathlib import Path
8
8
  from threading import Thread
9
9
  import typer
10
10
  from . import rest_helper as rest
11
+ from . import auth_keys
11
12
 
12
13
  app = typer.Typer()
13
-
14
+ app.add_typer(auth_keys.app, name="keys", help="Manage users personal access keys")
14
15
  config_dir_name = str(Path.home()) + "/.config/.remotive/"
15
16
  token_file_name = str(Path.home()) + "/.config/.remotive/cloud.secret.token"
16
17
 
17
18
 
19
+
18
20
  class S(BaseHTTPRequestHandler):
19
21
  def _set_response(self):
20
22
  self.send_response(200)
21
- #self.send_response(301)
22
- #self.send_header('Location', 'https://cloud.remotivelabs.com')
23
- #self.end_headers()
23
+ # self.send_response(301)
24
+ # self.send_header('Location', 'https://cloud.remotivelabs.com')
25
+ # self.end_headers()
24
26
  self.send_header('Content-type', 'text/html')
25
27
  self.end_headers()
26
28
 
@@ -55,26 +57,32 @@ def login():
55
57
  webbrowser.open(f'{rest.base_url}/login?redirectUrl=http://localhost:8089', new=1, autoraise=True)
56
58
  start_local_webserver()
57
59
 
60
+ @app.command(help="Who am I?")
61
+ def whoami():
62
+ rest.handle_get('/api/whoami')
58
63
 
59
64
  @app.command(help="Print access token")
60
65
  def print_access_token():
61
66
  print(read_token())
62
67
 
68
+
63
69
  @app.command(help="List available auth tokens")
64
70
  def list():
65
71
  for file in os.listdir(config_dir_name):
66
72
  print(file)
67
73
 
74
+
68
75
  @app.command(help="Show token file")
69
76
  def describe(
70
77
  file: str = typer.Option(..., help="File name")):
71
78
  print(read_file(file))
72
79
 
73
80
 
81
+
82
+
74
83
  @app.command(help="Activate the account file")
75
84
  def activate(
76
85
  file: str = typer.Option(..., help="File name")):
77
-
78
86
  # Best effort to read file
79
87
  if os.path.exists(file):
80
88
  token_file = json.loads(read_file_with_path(file))
@@ -106,23 +114,29 @@ def read_token():
106
114
  f.close()
107
115
  return token
108
116
 
117
+
109
118
  def read_file_with_path(file):
110
119
  f = open(file, "r")
111
120
  token = f.read()
112
121
  f.close()
113
122
  return token
114
123
 
124
+
115
125
  def read_file(file):
116
126
  f = open(str(Path.home()) + f"/.config/.remotive/{file}", "r")
117
127
  token = f.read()
118
128
  f.close()
119
129
  return token
120
130
 
131
+
121
132
  def write_token(token):
122
133
  f = open(token_file_name, "w")
123
134
  f.write(token)
124
135
  f.close()
125
136
 
137
+
138
+
139
+
126
140
  # Key stuff
127
141
  # f = open(str(Path.home())+ "/.remotivelabs/privatekey.json", "r")
128
142
  # j = json.loads(f.read())
cli/cloud/auth_keys.py ADDED
@@ -0,0 +1,46 @@
1
+ from pathlib import Path
2
+
3
+ import typer
4
+ from . import rest_helper as rest
5
+
6
+ app = typer.Typer()
7
+
8
+
9
+ @app.command(name="create", help="Create and download a new personal access token")
10
+ def get_personal_access_token():
11
+ rest.ensure_auth_token()
12
+ rest.handle_post('/api/me/keys')
13
+
14
+ response = rest.handle_post(url='/api/me/keys',
15
+ return_response=True)
16
+
17
+ if response.status_code == 200:
18
+ name = response.json()['name']
19
+ write_personal_token(f"personal-{name}-key.json", response.text)
20
+ else:
21
+ print(f'Got status code: {response.status_code}')
22
+ print(response.text)
23
+
24
+
25
+ @app.command(name="list", help="List personal access tokens")
26
+ def list_personal_access_tokens():
27
+ rest.ensure_auth_token()
28
+ rest.handle_get('/api/me/keys')
29
+
30
+
31
+ @app.command(name="revoke", help="Revoke the specified key")
32
+ def revoke(
33
+ key_name: str = typer.Option(..., help="Name of the key to revoke")
34
+ ):
35
+ rest.ensure_auth_token()
36
+ rest.handle_delete(f'/api/me/keys/{key_name}')
37
+
38
+
39
+ def write_personal_token(file, token):
40
+ path = str(Path.home()) + f"/.config/.remotive/{file}"
41
+ f = open(path, "w")
42
+ f.write(token)
43
+ f.close()
44
+ print(f"Personal key written to {path}")
45
+ print("Use 'remotive cloud auth activate filename' to use this key from cli")
46
+ print('\033[93m This file contains secrets and must never be compromised')
cli/cloud/brokers.py CHANGED
@@ -2,7 +2,7 @@ import typer
2
2
  import json
3
3
  from rich.progress import Progress, SpinnerColumn, TextColumn
4
4
  from . import rest_helper as rest
5
-
5
+ from rich import print
6
6
  app = typer.Typer()
7
7
 
8
8
 
cli/cloud/cloud_cli.py CHANGED
@@ -1,16 +1,11 @@
1
1
  import typer
2
2
 
3
- from . import recordings, brokers, configs, auth, service_accounts
3
+ from . import recordings, brokers, configs, auth, service_accounts, projects
4
4
  from . import rest_helper as rest
5
5
 
6
6
  app = typer.Typer()
7
7
 
8
8
 
9
- @app.command(help="Who am I?")
10
- def whoami():
11
- rest.handle_get('/api/whoami')
12
-
13
-
14
9
  @app.command(help="List licenses for an organisation")
15
10
  def licenses(
16
11
  organisation: str = typer.Option(..., help="Organisation ID", envvar='REMOTIVE_CLOUD_ORGANISATION'),
@@ -38,10 +33,11 @@ def users(
38
33
  rest.handle_get(f"/api/bu/{organisation}/users")
39
34
 
40
35
 
36
+ app.add_typer(projects.app, name="projects", help="Manage projects")
37
+ app.add_typer(auth.app, name="auth", help="Manage access to cloud resources")
41
38
  app.add_typer(brokers.app, name="brokers", help="Manage cloud broker lifecycle")
42
39
  app.add_typer(recordings.app, name="recordings", help="Manage recordings")
43
- app.add_typer(configs.app, name="configs", help="Manage signal databases")
44
- app.add_typer(auth.app, name="auth", help="Manage access to cloud resources")
40
+ app.add_typer(configs.app, name="signal-databases", help="Manage signal databases")
45
41
  app.add_typer(service_accounts.app, name="service-accounts", help="Manage project service account keys")
46
42
 
47
43
 
cli/cloud/projects.py ADDED
@@ -0,0 +1,30 @@
1
+ import json
2
+
3
+ import typer
4
+ from . import rest_helper as rest
5
+ app = typer.Typer()
6
+
7
+
8
+ @app.command(name="list", help="List your projects")
9
+ def list_projects(organisation: str = typer.Option(..., help="Organisation ID", envvar='REMOTIVE_CLOUD_ORGANISATION')):
10
+ r = rest.handle_get(url=f'/api/bu/{organisation}/me', return_response=True)
11
+ if r.status_code == 200:
12
+ projects = r.json()['projects']
13
+ projects = map(lambda p: p['uid'], projects)
14
+ print(json.dumps(list(projects)))
15
+
16
+
17
+ @app.command(name="create")
18
+ def create_project(
19
+ organisation: str = typer.Option(..., help="Organisation ID", envvar='REMOTIVE_CLOUD_ORGANISATION'),
20
+ project_uid: str = typer.Option(..., help="Project UID"),
21
+ project_display_name: str = typer.Option(default="", help="Project display name")
22
+ ):
23
+
24
+ create_project_req = {
25
+ 'uid': project_uid,
26
+ 'displayName': project_display_name if project_display_name != "" else project_uid,
27
+ 'description': ''
28
+ }
29
+
30
+ rest.handle_post(url=f'/api/bu/{organisation}/project', body=json.dumps(create_project_req))
cli/cloud/rest_helper.py CHANGED
@@ -6,7 +6,7 @@ import json
6
6
  import logging
7
7
  from pathlib import Path
8
8
  from os.path import exists
9
-
9
+ #from rich import print
10
10
  import typer
11
11
 
12
12
  if 'REMOTIVE_CLOUD_HTTP_LOGGING' in os.environ:
@@ -51,9 +51,13 @@ def ensure_auth_token():
51
51
  headers = {"Authorization": "Bearer " + token.strip()}
52
52
 
53
53
 
54
- def handle_get(url, params={}):
54
+ def handle_get(url, params={},return_response: bool = False):
55
55
  ensure_auth_token()
56
56
  r = requests.get(f'{base_url}{url}', headers=headers, params=params)
57
+
58
+ if return_response:
59
+ return r
60
+
57
61
  if r.status_code == 200:
58
62
  print(json.dumps(r.json()))
59
63
  else:
@@ -97,3 +101,4 @@ def handle_post(url, body=None, params={}, return_response: bool = False):
97
101
  print(r.status_code)
98
102
  else:
99
103
  print(f'Got status code: {r.status_code}')
104
+ print(r.text)
@@ -35,6 +35,14 @@ def list_keys(
35
35
  rest.handle_get(f"/api/project/{project}/admin/accounts/{service_account}/keys")
36
36
 
37
37
 
38
+ @app.command(name="revoke", help="Revoke service account key")
39
+ def revoke(
40
+ service_account: str = typer.Option(..., help="Service account name"),
41
+ key_name: str = typer.Option(..., help="Key name"),
42
+ project: str = typer.Option(..., help="Project ID", envvar='REMOTIVE_CLOUD_PROJECT')):
43
+ rest.handle_delete(f"/api/project/{project}/admin/accounts/{service_account}/keys/{key_name}")
44
+
45
+
38
46
  def write_token(file, token):
39
47
  path = str(Path.home()) + f"/.config/.remotive/{file}"
40
48
  f = open(path, "w")
cli/remotive.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import typer
2
2
  from .brokers import app as broker_app
3
3
  from .cloud.cloud_cli import app as cloud_app
4
+ from rich import print
4
5
 
5
6
  app = typer.Typer()
6
7
 
@@ -0,0 +1,17 @@
1
+ Apache-2.0
2
+
3
+ RemotiveLabs CLI
4
+ Copyright 2022 RemotiveLabs <hello@remotivelabs.com>
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: remotivelabs-cli
3
- Version: 0.0.1a3
3
+ Version: 0.0.1a4
4
4
  Summary:
5
5
  Author: Johan Rask
6
6
  Author-email: johan.rask@remotivelabs.com
@@ -0,0 +1,24 @@
1
+ cli/__about__.py,sha256=tcTE7G1_tGq5vqrGkFTYv986sz3ebNRnnkAmNlkF0rE,122
2
+ cli/__init__.py,sha256=Mjnyow0Ngm-b-SdPz4HAkREzch7wKZ2Wy_hxLez49Lc,26
3
+ cli/brokers.py,sha256=2rs9W7p6BG6rXlEuMvd4EmJHwUWaWa2lUuhBDsoFtc4,2910
4
+ cli/cloud/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5
+ cli/cloud/auth.py,sha256=jcaQX-GMD4gpthTjSTe_rtfBZHnKjnbe9ez-NHbxqmU,3875
6
+ cli/cloud/auth_keys.py,sha256=B2C0tKkA2ggFjL1y1goY3YCljXUJaGUX9GWWFsIamrg,1392
7
+ cli/cloud/brokers.py,sha256=0aD2K_NWhaWUDiswkDeZbjSctn2dKWuytstmv-YIsls,2306
8
+ cli/cloud/cloud_cli.py,sha256=KSTXOTOLucuFjW4ZapYld1D4E2DQ9XoQaAxzZQuLLfI,1611
9
+ cli/cloud/configs.py,sha256=Y5XVYwfPLJzRvc46DjDyYGON8tINV5xcowcHBk8dKO0,3132
10
+ cli/cloud/projects.py,sha256=J-hQTNRbM7oY3rhkZVrmuezOQF___oke3EajjqxAgQM,1083
11
+ cli/cloud/recordings.py,sha256=m0aMNGAblPGiw8zIjpoPsX4RmRVdyhHtyWIkjRjrsRc,6887
12
+ cli/cloud/rest_helper.py,sha256=-qER-i9y5yeLHypBhoCWTBJZoL1LASjARjJK2uHKH1M,2979
13
+ cli/cloud/service_account_keys.py,sha256=hA_hSqP9fjx6OblmxjJPFdsumXQg-7n2rWJ7m8PsJVo,1990
14
+ cli/cloud/service_accounts.py,sha256=LNae9imZYsOY2zTHwyiG9syIZ7EYs7hgLxZyUthu8eI,1176
15
+ cli/lib/__about__.py,sha256=GLOW8iEx5xn9rbJvxUH3elZiLi47SAWamMjdJTd52k0,141
16
+ cli/lib/broker.py,sha256=zYCgABQZSBfR5Ps3jDCuL6jwlJNU4Q8D1UoiMX5vjHc,4905
17
+ cli/remotive.py,sha256=9OkfLJT7ebAShkZ0aCitXsYywCJYxrkwmbpUTzum_8o,315
18
+ cli/requirements.txt,sha256=k2SdtUayWWypl_24paMPHrMu7oH0E3_S_9w9zdAng-Y,77
19
+ cli/test/test_simple.py,sha256=c60_dg5EmhNVmBC6rDcDP-tvKJCBqjIA2Z5Ym9ums4M,63
20
+ remotivelabs_cli-0.0.1a4.dist-info/LICENSE,sha256=qDPP_yfuv1fF-u7EfexN-cN3M8aFgGVndGhGLovLKz0,608
21
+ remotivelabs_cli-0.0.1a4.dist-info/METADATA,sha256=IQyQM8cGfNMsy0D2HoLZRQ9rbI_80z9T_HrC7u_tuDo,2744
22
+ remotivelabs_cli-0.0.1a4.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
23
+ remotivelabs_cli-0.0.1a4.dist-info/entry_points.txt,sha256=lvDhPgagLqW_KTnLPCwKSqfYlEp-1uYVosRiPjsVj10,45
24
+ remotivelabs_cli-0.0.1a4.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- cli/__about__.py,sha256=tcTE7G1_tGq5vqrGkFTYv986sz3ebNRnnkAmNlkF0rE,122
2
- cli/__init__.py,sha256=Mjnyow0Ngm-b-SdPz4HAkREzch7wKZ2Wy_hxLez49Lc,26
3
- cli/brokers.py,sha256=2rs9W7p6BG6rXlEuMvd4EmJHwUWaWa2lUuhBDsoFtc4,2910
4
- cli/cloud/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5
- cli/cloud/auth.py,sha256=fng1uXlCjuabzISHl502VfWB0gwAoyRpD5MWWvGTVWQ,3675
6
- cli/cloud/brokers.py,sha256=UudXB5XU1c3NFCl_zm8ma3SHzaTWGab-QhqsWp3u_mE,2284
7
- cli/cloud/cloud_cli.py,sha256=CYzROy70r-XLt4AMY_nM8V1O33t-E09cOCeVwasRE48,1605
8
- cli/cloud/configs.py,sha256=Y5XVYwfPLJzRvc46DjDyYGON8tINV5xcowcHBk8dKO0,3132
9
- cli/cloud/recordings.py,sha256=m0aMNGAblPGiw8zIjpoPsX4RmRVdyhHtyWIkjRjrsRc,6887
10
- cli/cloud/rest_helper.py,sha256=MBxPo8_oOePtt-4Wm_6UXBwgRs2XX7VUiDI5waI5qrE,2861
11
- cli/cloud/service_account_keys.py,sha256=sYCA-XjeqPOIcRcY1cLG90FHSwykV3pRHY3K2sSr9bE,1580
12
- cli/cloud/service_accounts.py,sha256=LNae9imZYsOY2zTHwyiG9syIZ7EYs7hgLxZyUthu8eI,1176
13
- cli/lib/__about__.py,sha256=GLOW8iEx5xn9rbJvxUH3elZiLi47SAWamMjdJTd52k0,141
14
- cli/lib/broker.py,sha256=zYCgABQZSBfR5Ps3jDCuL6jwlJNU4Q8D1UoiMX5vjHc,4905
15
- cli/remotive.py,sha256=lo829TPRsQS1Hh7td8NXJ7l_L_4JkiRXrg5wH15N0ik,292
16
- cli/requirements.txt,sha256=k2SdtUayWWypl_24paMPHrMu7oH0E3_S_9w9zdAng-Y,77
17
- cli/test/test_simple.py,sha256=c60_dg5EmhNVmBC6rDcDP-tvKJCBqjIA2Z5Ym9ums4M,63
18
- remotivelabs_cli-0.0.1a3.dist-info/METADATA,sha256=fGnQZD3ErfXhONrgeZQmA74KYMmPoDWUZqe28F_0Y54,2744
19
- remotivelabs_cli-0.0.1a3.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
20
- remotivelabs_cli-0.0.1a3.dist-info/entry_points.txt,sha256=lvDhPgagLqW_KTnLPCwKSqfYlEp-1uYVosRiPjsVj10,45
21
- remotivelabs_cli-0.0.1a3.dist-info/RECORD,,