remotivelabs-cli 0.2.2__py3-none-any.whl → 0.3.0__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.

Potentially problematic release.


This version of remotivelabs-cli might be problematic. Click here for more details.

cli/cloud/__init__.py CHANGED
@@ -0,0 +1,17 @@
1
+ from cli.cloud import auth, brokers, configs, organisations, projects, recordings, sample_recordings, service_accounts, storage
2
+ from cli.cloud.licenses.cmd import licenses
3
+ from cli.typer import typer_utils
4
+
5
+ app = typer_utils.create_typer()
6
+
7
+ app.command(name="licenses", help="List licenses for an organization")(licenses)
8
+
9
+ app.add_typer(organisations.app, name="organizations", help="Manage organizations")
10
+ app.add_typer(projects.app, name="projects", help="Manage projects")
11
+ app.add_typer(auth.app, name="auth")
12
+ app.add_typer(brokers.app, name="brokers", help="Manage cloud broker lifecycle")
13
+ app.add_typer(recordings.app, name="recordings", help="Manage recordings")
14
+ app.add_typer(configs.app, name="signal-databases", help="Manage signal databases")
15
+ app.add_typer(storage.app, name="storage")
16
+ app.add_typer(service_accounts.app, name="service-accounts", help="Manage project service account keys")
17
+ app.add_typer(sample_recordings.app, name="samples", help="Manage sample recordings")
cli/cloud/auth/cmd.py CHANGED
@@ -1,22 +1,25 @@
1
1
  from __future__ import annotations
2
2
 
3
- import sys
3
+ import os
4
4
 
5
5
  import typer
6
+ from rich.console import Console
7
+ from rich.table import Table
6
8
 
7
9
  from cli.cloud.auth.login import login as do_login
8
10
  from cli.errors import ErrorPrinter
9
- from cli.settings import TokenNotFoundError, settings
11
+ from cli.settings import settings
10
12
  from cli.typer import typer_utils
11
13
  from cli.utils.rest_helper import RestHelper as Rest
12
14
 
13
15
  from .. import auth_tokens
14
16
 
17
+ console = Console(stderr=False)
18
+
15
19
  HELP = """
16
20
  Manage how you authenticate with our cloud platform
17
21
  """
18
22
  app = typer_utils.create_typer(help=HELP)
19
- # app.add_typer(auth_tokens.app, name="credentials", help="Manage account credentials")
20
23
 
21
24
 
22
25
  @app.command(name="login")
@@ -36,11 +39,7 @@ def whoami() -> None:
36
39
  """
37
40
  Validates authentication and fetches your account information
38
41
  """
39
- try:
40
- Rest.handle_get("/api/whoami")
41
- except TokenNotFoundError as e:
42
- ErrorPrinter.print_hint(str(e))
43
- sys.exit(1)
42
+ Rest.handle_get("/api/whoami")
44
43
 
45
44
 
46
45
  @app.command()
@@ -50,39 +49,78 @@ def print_access_token(
50
49
  """
51
50
  Print current active access token or the token for the specified account
52
51
  """
53
- if account is None:
54
- try:
55
- print(settings.get_active_token())
56
- except TokenNotFoundError:
52
+ if not account:
53
+ active_token = settings.get_active_token() or os.getenv("REMOTIVE_CLOUD_ACCESS_TOKEN", None)
54
+ if not active_token:
57
55
  ErrorPrinter.print_generic_error("You have no active account", exit_code=1)
58
- else:
59
- config = settings.get_cli_config()
60
- if account in config.accounts:
61
- token_file_name = config.accounts[account].credentials_file
62
- try:
63
- print(settings.get_token_file(token_file_name).token)
64
- except TokenNotFoundError:
65
- ErrorPrinter.print_generic_error(f"Token file for {account} could not be found", exit_code=1)
66
- else:
67
- ErrorPrinter.print_generic_error(f"No account for {account} was found", exit_code=1)
56
+ return
57
+
58
+ print(active_token)
59
+ return
60
+
61
+ accounts = settings.list_accounts()
62
+ if account not in accounts:
63
+ ErrorPrinter.print_generic_error(f"No account for {account} was found", exit_code=1)
64
+ return
65
+
66
+ token_file_name = accounts[account].credentials_file
67
+ token_file = settings.get_token_file(token_file_name)
68
+ if not token_file:
69
+ ErrorPrinter.print_generic_error(f"Token file for {account} could not be found", exit_code=1)
70
+ return
71
+
72
+ print(token_file.token)
68
73
 
69
74
 
70
75
  def print_access_token_file() -> None:
71
76
  """
72
77
  Print current active token and its metadata
73
78
  """
74
- try:
75
- print(settings.get_active_token_file())
76
- except TokenNotFoundError as e:
77
- ErrorPrinter.print_hint(str(e))
78
- sys.exit(1)
79
+ active_token_file = settings.get_active_token_file()
80
+ if not active_token_file:
81
+ ErrorPrinter.print_generic_error("You have no active account", exit_code=1)
82
+ return
83
+
84
+ print(active_token_file)
85
+
86
+
87
+ @app.command(name="deactivate")
88
+ def deactivate() -> None:
89
+ """
90
+ Clears active account
91
+ """
92
+ settings.clear_active_account()
93
+ print("Account no longer active")
79
94
 
80
95
 
81
- # @app.command(help="Clears active credentials")
82
- def logout() -> None:
83
- settings.clear_active_token()
84
- print("Access token removed")
96
+ @app.command("activate")
97
+ def activate(token_name: str = typer.Argument(None, help="Name, filename or path to a credentials file")) -> None:
98
+ """
99
+ Set the active account
100
+ """
101
+ auth_tokens.do_activate(token_name)
85
102
 
86
103
 
87
- app.command("activate")(auth_tokens.select_personal_token)
88
- app.command("list")(auth_tokens.list_pats_files)
104
+ @app.command(name="list")
105
+ def list() -> None:
106
+ """
107
+ Lists available credential files on filesystem
108
+ """
109
+ accounts = settings.list_accounts()
110
+
111
+ table = Table("#", "Active", "Type", "Token", "Account", "Organization", "Created", "Expires")
112
+ for idx, (email, account) in enumerate(accounts.items(), start=1):
113
+ token_file = settings.get_token_file_by_email(email)
114
+ is_active = settings.is_active_account(email)
115
+
116
+ table.add_row(
117
+ f"[yellow]{idx}",
118
+ ":white_check_mark:" if is_active else "",
119
+ "unknown" if not token_file else "user" if token_file.type == "authorized_user" else "sa",
120
+ token_file.name if token_file else "",
121
+ f"[bold]{email}[/bold]",
122
+ account.default_organization if account.default_organization else "",
123
+ str(token_file.created) if token_file else "",
124
+ str(token_file.expires) if token_file else "",
125
+ )
126
+ console.print(table)
cli/cloud/auth/login.py CHANGED
@@ -18,7 +18,7 @@ from typing_extensions import override
18
18
 
19
19
  from cli.cloud.auth_tokens import do_activate, prompt_to_set_org
20
20
  from cli.errors import ErrorPrinter
21
- from cli.settings import TokenNotFoundError, settings
21
+ from cli.settings import settings
22
22
  from cli.settings.token_file import TokenFile
23
23
  from cli.utils.rest_helper import RestHelper as Rest
24
24
 
@@ -174,14 +174,13 @@ def create_personal_token() -> None:
174
174
 
175
175
 
176
176
  def _do_prompt_to_use_existing_credentials() -> Optional[TokenFile]:
177
- files = settings.list_personal_token_files()
178
- if len(files) > 0:
177
+ token_files = settings.list_personal_token_files()
178
+ if len(token_files) > 0:
179
179
  should_select_token = typer.confirm(
180
180
  "You have credentials available already, would you like to choose one of these instead?", default=True
181
181
  )
182
182
  if should_select_token:
183
183
  token = do_activate(token_name=None)
184
- # token = list_and_select_personal_token(skip_prompt=False, include_service_accounts=True)
185
184
  if token is not None:
186
185
  return token
187
186
  # TODO - fix so this is not needed
@@ -189,7 +188,7 @@ def _do_prompt_to_use_existing_credentials() -> Optional[TokenFile]:
189
188
  return None
190
189
 
191
190
 
192
- def login(headless: bool = False) -> bool: # noqa: C901, PLR0912, PLR0915
191
+ def login(headless: bool = False) -> bool: # noqa: C901, PLR0915
193
192
  """
194
193
  Initiate login
195
194
  """
@@ -197,31 +196,30 @@ def login(headless: bool = False) -> bool: # noqa: C901, PLR0912, PLR0915
197
196
  #
198
197
  # Check login.md flowchart for better understanding
199
198
  #
200
- # 1. Check for active token valid and working credentials
201
- #
202
- try:
203
- activate_token = settings.get_active_token_file()
204
-
205
- if not activate_token.is_expired():
206
- if Rest.has_access("/api/whoami"):
207
- token = _do_prompt_to_use_existing_credentials()
208
- if token is not None:
209
- return True
210
- else:
211
- settings.clear_active_token()
212
- raise TokenNotFoundError()
213
- else:
214
- # TODO - Cleanup token since expired
215
- pass
216
-
217
- except TokenNotFoundError:
218
- #
219
- # 2. If no token was found, let user choose an existing if exists
220
- #
221
- token = _do_prompt_to_use_existing_credentials()
222
- if token is not None:
199
+
200
+ active_token_file = settings.get_active_token_file()
201
+ if active_token_file:
202
+ # check if the active token is valid, if not, prompt user to select a new token
203
+ if not Rest.has_access("/api/whoami") or active_token_file.is_expired():
204
+ settings.clear_active_account()
205
+ newly_activated_token_file = _do_prompt_to_use_existing_credentials()
206
+ if newly_activated_token_file:
207
+ return True
208
+
209
+ # intentional fall through to login since we have no token
210
+
211
+ else:
212
+ # no active token, prompt user to select a new token
213
+ newly_activated_token_file = _do_prompt_to_use_existing_credentials()
214
+ if newly_activated_token_file:
223
215
  return True
224
216
 
217
+ # intentional fall through to login since we have no token
218
+
219
+ #
220
+ # 2. Login in if no valid token found...
221
+ #
222
+
225
223
  prepare_local_webserver()
226
224
 
227
225
  def force_use_webserver_callback() -> bool:
cli/cloud/auth_tokens.py CHANGED
@@ -1,34 +1,27 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import List, Literal, Optional
3
+ from typing import List, Optional
4
4
 
5
5
  import typer
6
6
  from rich.console import Console
7
7
  from rich.table import Table
8
8
 
9
- from cli.api.cloud import tokens
10
9
  from cli.cloud.organisations import do_select_default_org
11
10
  from cli.errors import ErrorPrinter
12
- from cli.settings import TokenNotFoundError, settings
13
- from cli.settings.config_file import Account
11
+ from cli.settings import settings
14
12
  from cli.settings.token_file import TokenFile
15
- from cli.typer import typer_utils
16
13
  from cli.utils.rest_helper import RestHelper as Rest
17
14
 
18
15
  console = Console(stderr=False)
19
16
  err_console = Console(stderr=True)
20
17
 
21
- app = typer_utils.create_typer()
22
18
 
23
- PromptType = Literal["activate", "login"]
24
-
25
-
26
- def _prompt_choice( # noqa: C901, PLR0912
19
+ def _prompt_choice( # noqa: C901
27
20
  choices: List[TokenFile],
28
21
  skip_prompt: bool = False,
29
22
  info_message: Optional[str] = None,
30
23
  ) -> Optional[TokenFile]:
31
- accounts = settings.get_cli_config().accounts
24
+ accounts = settings.list_accounts()
32
25
 
33
26
  table = Table("#", "Active", "Type", "Token", "Account", "Created", "Expires")
34
27
 
@@ -38,11 +31,10 @@ def _prompt_choice( # noqa: C901, PLR0912
38
31
  for token in choices:
39
32
  account = accounts.get(token.account.email)
40
33
  if account and account.credentials_file:
41
- try:
42
- token_file = settings.get_token_file(account.credentials_file)
43
- if token_file.name in (token.name or ""):
44
- included_tokens.append(token)
45
- except TokenNotFoundError:
34
+ token_file = settings.get_token_file(account.credentials_file)
35
+ if token_file and token_file.name in (token.name or ""):
36
+ included_tokens.append(token)
37
+ else:
46
38
  excluded_tokens.append(token)
47
39
  else:
48
40
  excluded_tokens.append(token)
@@ -52,22 +44,7 @@ def _prompt_choice( # noqa: C901, PLR0912
52
44
 
53
45
  included_tokens.sort(key=lambda token: token.created, reverse=True)
54
46
 
55
- def get_active_account_or_none() -> Optional[Account]:
56
- try:
57
- return settings.get_cli_config().get_active()
58
- except TokenNotFoundError:
59
- return None
60
-
61
- def get_active_token_or_none() -> Optional[TokenFile]:
62
- try:
63
- active_account = get_active_account_or_none()
64
- if active_account is not None:
65
- return settings.get_token_file(active_account.credentials_file)
66
- except TokenNotFoundError:
67
- pass
68
- return None
69
-
70
- active_token = get_active_token_or_none()
47
+ active_token = settings.get_active_token_file()
71
48
  active_token_index = None
72
49
  for idx, choice in enumerate(included_tokens, start=1):
73
50
  is_active = active_token is not None and active_token.name == choice.name
@@ -108,62 +85,9 @@ def _prompt_choice( # noqa: C901, PLR0912
108
85
  return _prompt_choice(included_tokens, skip_prompt, info_message)
109
86
 
110
87
 
111
- # @app.command(name="create")
112
- def create(
113
- activate: bool = typer.Option(False, help="Activate the token for use after download"),
114
- ) -> None:
115
- """
116
- Create a new personal access token in [bold]cloud[/bold] and download locally
117
- """
118
- response = tokens.create()
119
- pat = settings.add_personal_token(response.text())
120
- print(f"Personal access token added: {pat.name}")
121
-
122
- if not activate:
123
- print(f"Use 'remotive cloud auth tokens activate {pat.name}' to use this access token from cli")
124
- else:
125
- settings.activate_token(pat)
126
- print("Token file activated and ready for use")
127
- print("\033[93m This file contains secrets and must be kept safe")
128
-
129
-
130
- # @app.command(name="list", help="List personal credentials in [bold]cloud[/bold]")
131
- def list_tokens() -> None:
132
- Rest.handle_get("/api/me/keys")
133
-
134
-
135
- # @app.command(name="revoke")
136
- def revoke(
137
- name: str = typer.Argument(help="Access token name"),
138
- delete: bool = typer.Option(True, help="Also delete token"),
139
- ) -> None:
140
- """
141
- Revoke personal credentials in cloud and removes the file from filesystem
142
-
143
- If cloud token is not found but token is found on file system it will delete it and
144
- vice versa.
145
- """
146
- _revoke_and_delete_personal_token(name, delete)
147
-
148
-
149
- # @app.command(name="activate")
150
- def activate(
151
- token_name: str = typer.Argument(..., help="Token path, filename or name to activate"),
152
- ) -> None:
153
- """
154
- Activate a credential file to be used for authentication using filename, path or name.
155
-
156
- This will be used as the current access token in all requests.
157
- """
158
- try:
159
- token_file = settings.get_token_file(token_name)
160
- settings.activate_token(token_file)
161
- except TokenNotFoundError:
162
- err_console.print(f":boom: [bold red] Error: [/bold red] Token with filename or name {token_name} could not be found")
163
-
164
-
165
88
  def prompt_to_set_org() -> None:
166
- if settings.get_cli_config().get_active_default_organisation() is None:
89
+ active_account = settings.get_active_account()
90
+ if active_account and not active_account.default_organization:
167
91
  set_default_organisation = typer.confirm(
168
92
  "You have not set a default organization\nWould you like to choose one now?",
169
93
  abort=False,
@@ -173,45 +97,32 @@ def prompt_to_set_org() -> None:
173
97
  do_select_default_org(get=False)
174
98
 
175
99
 
176
- @app.command("activate")
177
- def select_personal_token(
178
- token_name: str = typer.Argument(None, help="Name, filename or path to a credentials file"),
179
- ) -> None:
180
- """
181
- Activates is setting the current active credentials to use by the CLI, this can be done by specifying a name
182
- of the token or getting prompted and choosing from existing.
183
- """
184
- do_activate(token_name)
185
-
186
-
187
100
  def do_activate(token_name: Optional[str]) -> Optional[TokenFile]:
188
- if token_name is not None:
189
- try:
190
- token_file = settings.get_token_file(token_name)
191
- settings.activate_token(token_file)
192
- return token_file
193
- except TokenNotFoundError:
101
+ if token_name:
102
+ token_file = settings.get_token_file(token_name)
103
+ if not token_file:
194
104
  err_console.print(f":boom: [bold red] Error: [/bold red] Token with filename or name {token_name} could not be found")
195
105
  return None
196
- else:
197
- token_files = settings.list_personal_tokens()
198
- token_files.extend(settings.list_service_account_tokens())
199
- if len(token_files) > 0:
200
- token_selected = list_and_select_personal_token(include_service_accounts=True)
201
- if token_selected is not None:
202
- is_logged_in = Rest.has_access("/api/whoami")
203
- if not is_logged_in:
204
- ErrorPrinter.print_generic_error("Could not access RemotiveCloud with selected token")
205
- else:
206
- console.print("[green]Success![/green] Access to RemotiveCloud granted")
207
- # Only select default if activate was done with selection and successful
208
- # and not SA since SA cannot list available organizations
209
- if token_selected.type == "authorized_user":
210
- prompt_to_set_org()
211
- return token_selected
106
+ return settings.activate_token(token_file)
107
+
108
+ token_files = settings.list_personal_token_files()
109
+ token_files.extend(settings.list_service_account_token_files())
110
+ if len(token_files) > 0:
111
+ token_selected = list_and_select_personal_token(include_service_accounts=True)
112
+ if token_selected is not None:
113
+ is_logged_in = Rest.has_access("/api/whoami")
114
+ if not is_logged_in:
115
+ ErrorPrinter.print_generic_error("Could not access RemotiveCloud with selected token")
116
+ else:
117
+ console.print("[green]Success![/green] Access to RemotiveCloud granted")
118
+ # Only select default if activate was done with selection and successful
119
+ # and not SA since SA cannot list available organizations
120
+ if token_selected.type == "authorized_user":
121
+ prompt_to_set_org()
122
+ return token_selected
212
123
 
213
- ErrorPrinter.print_hint("No credentials available, login to activate credentials")
214
- return None
124
+ ErrorPrinter.print_hint("No credentials available, login to activate credentials")
125
+ return None
215
126
 
216
127
 
217
128
  def list_and_select_personal_token(
@@ -219,10 +130,10 @@ def list_and_select_personal_token(
219
130
  include_service_accounts: bool = False,
220
131
  info_message: Optional[str] = None,
221
132
  ) -> Optional[TokenFile]:
222
- personal_tokens = settings.list_personal_tokens()
133
+ personal_tokens = settings.list_personal_token_files()
223
134
 
224
135
  if include_service_accounts:
225
- sa_tokens = settings.list_service_account_tokens()
136
+ sa_tokens = settings.list_service_account_token_files()
226
137
  personal_tokens.extend(sa_tokens)
227
138
 
228
139
  selected_token = _prompt_choice(personal_tokens, skip_prompt=skip_prompt, info_message=info_message)
@@ -230,126 +141,3 @@ def list_and_select_personal_token(
230
141
  settings.activate_token(selected_token)
231
142
 
232
143
  return selected_token
233
-
234
-
235
- # @app.command("select-revoke")
236
- def select_revoke_personal_token() -> None:
237
- """
238
- Prompts a user to select one of the credential files to revoke and delete
239
- """
240
- personal_tokens = settings.list_personal_tokens()
241
- sa_tokens = settings.list_service_account_tokens()
242
- personal_tokens.extend(sa_tokens)
243
-
244
- is_logged_in = Rest.has_access("/api/whoami")
245
- if not is_logged_in:
246
- ErrorPrinter.print_hint("You must be logged in")
247
- raise typer.Exit(0)
248
-
249
- # merged = _merge_local_tokens_with_cloud(personal_tokens)
250
-
251
- selected_token = _prompt_choice(personal_tokens)
252
-
253
- if selected_token is not None:
254
- _revoke_and_delete_personal_token(selected_token.name, True)
255
- # Rest.handle_patch(f"/api/me/keys/{selected_token.name}/revoke", quiet=True, access_token=selected_token.token)
256
- # Rest.handle_delete(f"/api/me/keys/{selected_token.name}", quiet=True, access_token=selected_token.token)
257
- # settings.remove_token_file(selected_token.name)
258
- # active_token = settings.get_active_token_file()
259
- # if active_token.name == selected_token.name:
260
- # settings.clear_active_token()
261
- # select_revoke_personal_token()
262
-
263
-
264
- # @app.command("test-all")
265
- def test_all_personal_tokens() -> None:
266
- """
267
- Tests each credential file to see if it is valid
268
- """
269
- personal_tokens = settings.list_personal_tokens()
270
- personal_tokens.extend(settings.list_service_account_tokens())
271
- if len(personal_tokens) == 0:
272
- console.print("No personal tokens found on disk")
273
- return
274
-
275
- for token in personal_tokens:
276
- r = Rest.handle_get(
277
- "/api/whoami",
278
- allow_status_codes=[401],
279
- access_token=token.token,
280
- use_progress_indicator=True,
281
- return_response=True,
282
- )
283
- if r.status_code == 200:
284
- if token.account is not None:
285
- console.print(f"{token.account.email} ({token.name}) :white_check_mark:")
286
- else:
287
- console.print(f"{token.name} :white_check_mark:")
288
- elif token.account is not None:
289
- console.print(f"{token.account.email} ({token.name}) :x: Failed")
290
- else:
291
- console.print(f"{token.name} :x: Failed")
292
-
293
-
294
- # @app.command(name="list-service-account-tokens-files")
295
- def list_sats_files() -> None:
296
- """
297
- List service account access token files in remotivelabs config directory
298
- """
299
- service_account_files = settings.list_service_account_token_files()
300
- for file in service_account_files:
301
- print(file)
302
-
303
-
304
- @app.command(name="list")
305
- def list_pats_files(
306
- accounts: bool = typer.Option(True, help="Lists all available accounts"),
307
- files: bool = typer.Option(False, help="Shows all token files in config directory"),
308
- ) -> None:
309
- """
310
- Lists available credential files on filesystem
311
- """
312
-
313
- if accounts:
314
- list_and_select_personal_token(skip_prompt=True, include_service_accounts=True, info_message="hello")
315
-
316
- if files:
317
- personal_files = settings.list_personal_token_files()
318
- service_account_files = settings.list_service_account_token_files()
319
- personal_files.extend(service_account_files)
320
- for file in personal_files:
321
- print(file)
322
-
323
-
324
- def _revoke_and_delete_personal_token(name: str, delete: bool) -> None:
325
- token_file = None
326
-
327
- # First we try to find the file and make sure its not the currently active
328
- try:
329
- token_file = settings.get_token_file(name)
330
- active_token = settings.get_active_token_file()
331
- if token_file.name == active_token.name:
332
- ErrorPrinter.print_hint("You cannot revoke the current active token")
333
- return
334
- except TokenNotFoundError:
335
- pass
336
-
337
- # The lets try to revoke from cloud
338
- res_revoke = tokens.revoke(name)
339
- if delete:
340
- res_delete = tokens.delete(name)
341
- if res_delete.is_success:
342
- ErrorPrinter.print_generic_message("Token successfully revoked and deleted")
343
- else:
344
- ErrorPrinter.print_hint(f"Failed to revoke and delete token in cloud: {res_delete.status_code}")
345
- elif res_revoke.is_success:
346
- ErrorPrinter.print_generic_message("Token successfully revoked")
347
- else:
348
- ErrorPrinter.print_hint("Failed to revoke and delete token in cloud")
349
-
350
- # Finally try to remove the file if exists
351
- if token_file is not None:
352
- settings.remove_token_file(token_file.name)
353
- console.print("Successfully deleted token on filesystem")
354
- else:
355
- ErrorPrinter.print_hint("Token not found on filesystem")
File without changes
@@ -0,0 +1,14 @@
1
+ import typer
2
+
3
+ from cli.typer import typer_utils
4
+ from cli.utils.rest_helper import RestHelper
5
+
6
+ app = typer_utils.create_typer()
7
+
8
+
9
+ @app.command(help="List licenses for an organization")
10
+ def licenses(
11
+ organization: str = typer.Option(..., help="Organization ID", envvar="REMOTIVE_CLOUD_ORGANIZATION"),
12
+ filter_option: str = typer.Option("all", help="all, valid, expired"),
13
+ ) -> None:
14
+ RestHelper.handle_get(f"/api/bu/{organization}/licenses", {"filter": filter_option})
@@ -26,10 +26,8 @@ class Organisation:
26
26
  def _prompt_choice(choices: List[Organisation]) -> Optional[Organisation]:
27
27
  table = Table("#", "Name", "Uid", "Default")
28
28
 
29
- token = settings.get_active_token_file()
30
- config = settings.get_cli_config()
31
-
32
- current_default_org = config.accounts[token.account.email].default_organization if token is not None else None
29
+ account = settings.get_active_account()
30
+ current_default_org = account.default_organization if account else None
33
31
 
34
32
  for idx, choice in enumerate(choices, start=1):
35
33
  table.add_row(
@@ -74,19 +72,18 @@ def do_select_default_org(organisation_uid: Optional[str] = None, get: bool = Fa
74
72
  Note that service-accounts does Not have permission to list organizations and will get a 403 Forbidden response so you must
75
73
  select the organization uid as argument
76
74
  """
75
+ active_account = settings.get_active_account()
77
76
  if get:
78
- default_organisation = settings.get_cli_config().get_active_default_organisation()
79
- if default_organisation:
80
- console.print(default_organisation)
77
+ if active_account and active_account.default_organization:
78
+ console.print(active_account.default_organization)
81
79
  else:
82
80
  console.print("No default organization set")
83
81
  elif organisation_uid is not None:
84
82
  settings.set_default_organisation(organisation_uid)
85
83
  else:
86
- account = settings.get_cli_config().get_active()
87
- if account:
88
- token = settings.get_token_file(account.credentials_file)
89
- if token.type != "authorized_user":
84
+ if active_account:
85
+ token = settings.get_token_file(active_account.credentials_file)
86
+ if token and token.type != "authorized_user":
90
87
  ErrorPrinter.print_hint(
91
88
  "You must supply the organization name as argument when using a service-account since the "
92
89
  "service-account is not allowed to list"
@@ -100,7 +97,6 @@ def do_select_default_org(organisation_uid: Optional[str] = None, get: bool = Fa
100
97
  selected = _prompt_choice(orgs)
101
98
 
102
99
  if selected is not None:
103
- settings.get_cli_config()
104
100
  typer.echo(f"Default organisation: {selected.display_name} (uid: {selected.uid})")
105
101
  settings.set_default_organisation(selected.uid)
106
102