remotivelabs-cli 0.1.1__py3-none-any.whl → 0.2.0a1__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/errors.py CHANGED
@@ -41,4 +41,4 @@ class ErrorPrinter:
41
41
 
42
42
  @staticmethod
43
43
  def print_generic_message(message: str) -> None:
44
- err_console.print(f"[bold]{message}[/bold]:")
44
+ err_console.print(f"[bold]{message}[/bold]")
cli/remotive.py CHANGED
@@ -9,14 +9,14 @@ from rich.console import Console
9
9
  from trogon import Trogon # type: ignore
10
10
  from typer.main import get_group
11
11
 
12
+ from cli.broker.brokers import app as broker_app
13
+ from cli.cloud.cloud_cli import app as cloud_app
14
+ from cli.connect.connect import app as connect_app
15
+ from cli.settings import settings
12
16
  from cli.settings.migrate_all_token_files import migrate_any_legacy_tokens
13
-
14
- from .broker.brokers import app as broker_app
15
- from .cloud.cloud_cli import app as cloud_app
16
- from .connect.connect import app as connect_app
17
- from .settings import settings
18
- from .tools.tools import app as tools_app
19
- from .typer import typer_utils
17
+ from cli.tools.tools import app as tools_app
18
+ from cli.topology.cmd import app as topology_app
19
+ from cli.typer import typer_utils
20
20
 
21
21
  err_console = Console(stderr=True)
22
22
 
@@ -90,5 +90,14 @@ app.add_typer(
90
90
  name="cloud",
91
91
  help="Manage resources in RemotiveCloud",
92
92
  )
93
+ app.add_typer(
94
+ topology_app,
95
+ name="topology",
96
+ help="""
97
+ RemotiveTopology actions
98
+
99
+ Read more at https://docs.remotivelabs.com/docs/remotive-topology
100
+ """,
101
+ )
93
102
  app.add_typer(connect_app, name="connect", help="Integrations with other systems")
94
103
  app.add_typer(tools_app, name="tools")
cli/topology/cmd.py ADDED
@@ -0,0 +1,98 @@
1
+ import dataclasses
2
+ import datetime
3
+ from typing import Any
4
+
5
+ import typer
6
+ from rich.console import Console
7
+
8
+ from cli.errors import ErrorPrinter
9
+ from cli.settings import TokenNotFoundError, settings
10
+ from cli.typer import typer_utils
11
+ from cli.utils.rest_helper import RestHelper
12
+
13
+ HELP = """
14
+ RemotiveTopology commands
15
+ """
16
+ console = Console()
17
+ app = typer_utils.create_typer(help=HELP)
18
+
19
+
20
+ @dataclasses.dataclass
21
+ class Subscription:
22
+ type: str
23
+ display_name: str
24
+ feature: str
25
+ start_date: str
26
+ end_date: str
27
+
28
+
29
+ def _print_current_subscription(subscription_info: dict[str, Any]) -> None:
30
+ subscription_type = subscription_info["subscriptionType"]
31
+
32
+ if subscription_type == "trial":
33
+ expires = datetime.datetime.fromisoformat(subscription_info["endDate"])
34
+ if expires < datetime.datetime.now():
35
+ console.print(f"Topology trial already ended, expired {subscription_info['endDate']}, please contact support@remotivelabs.com")
36
+ else:
37
+ console.print(f"Topology trial already started, expires {subscription_info['endDate']}")
38
+ # A paid subscription might not have an endDate
39
+ elif subscription_type == "paid":
40
+ if "endDate" in subscription_type:
41
+ expires = datetime.datetime.fromisoformat(subscription_info["endDate"])
42
+ else:
43
+ expires = None
44
+
45
+ if expires is not None and expires < datetime.datetime.now():
46
+ console.print(f"Topology subscription has ended, expired {subscription_info['endDate']}")
47
+ else:
48
+ console.print(f"Topology subscription already exists, expires {expires if expires is not None else 'Never'}")
49
+
50
+ else:
51
+ ErrorPrinter.print_generic_error("Unexpected exception, please contact support@remotivelabs.com")
52
+ raise typer.Exit(1)
53
+
54
+
55
+ @app.command("start-trial")
56
+ def start_trial(
57
+ organization: str = typer.Option(None, help="Organization to start trial for", envvar="REMOTIVE_CLOUD_ORGANIZATION"),
58
+ ) -> None:
59
+ """
60
+ Allows you ta start a 30 day trial subscription for running RemotiveTopology, you can read more at https://docs.remotivelabs.com/docs/remotive-topology.
61
+
62
+ """
63
+ RestHelper.use_progress("Checking access tokens...", transient=True)
64
+ try:
65
+ _ = settings.get_active_token_file()
66
+ except TokenNotFoundError:
67
+ if len(settings.list_personal_token_files()) == 0:
68
+ console.print(
69
+ "You must first sign in to RemotiveCloud, please use [bold]remotive cloud auth login[/bold] to sign-in"
70
+ "This requires a RemotiveCloud account, if you do not have an account you can sign-up at https://cloud.remotivelabs.com"
71
+ )
72
+ else:
73
+ console.print(
74
+ "You have not active account, please run [bold]remotive cloud auth activate[/bold] to choose an account"
75
+ "or [bold]remotive cloud auth login[/bold] to sign-in"
76
+ )
77
+ return
78
+
79
+ has_access = RestHelper.has_access("/api/whoami")
80
+ if not has_access:
81
+ ErrorPrinter.print_generic_message("Your current active credentials are not valid")
82
+ raise typer.Exit(1)
83
+
84
+ if organization is None and settings.get_cli_config().get_active_default_organisation() is None:
85
+ ErrorPrinter.print_hint("You have not specified any organization and no default organization is set")
86
+ raise typer.Exit(1)
87
+
88
+ sub = RestHelper.handle_get(f"/api/bu/{organization}/features/topology", return_response=True, allow_status_codes=[404, 403])
89
+ if sub.status_code == 404:
90
+ created = RestHelper.handle_post(f"/api/bu/{organization}/features/topology", return_response=True)
91
+ console.print(f"Topology trial started, expires {created.json()['endDate']}")
92
+ elif sub.status_code == 403:
93
+ ErrorPrinter.print_generic_error(f"You are not allowed to start-trial topology in organization {organization}")
94
+ raise typer.Exit(1)
95
+ else:
96
+ subscription_info = sub.json()
97
+ _print_current_subscription(subscription_info)
98
+ return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: remotivelabs-cli
3
- Version: 0.1.1
3
+ Version: 0.2.0a1
4
4
  Summary: CLI for operating RemotiveCloud and RemotiveBroker
5
5
  Author: Johan Rask
6
6
  Author-email: johan.rask@remotivelabs.com
@@ -36,8 +36,8 @@ cli/cloud/uri.py,sha256=QZCus--KJQlVwGCOzZqiglvj8VvSRKxfVvN33Pilgyg,3616
36
36
  cli/connect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  cli/connect/connect.py,sha256=SH2DNTTVLu2dNpk6xIah1-KJZAqrK_7Skt8RKp8Mjh8,4231
38
38
  cli/connect/protopie/protopie.py,sha256=ElmrGaV0ivb85wo0gLzCAXZhmSmIDASaCVlF1iQblLI,6532
39
- cli/errors.py,sha256=_P-qpayY06qgLA7wvoDFsyMaTfo_zjNY--fgHPAuhrs,1658
40
- cli/remotive.py,sha256=PsxR3Hhp3zhj-A06sqvtSkmXwv9moWHT_ify8Vg5xQA,2756
39
+ cli/errors.py,sha256=djODw6sdMJXzOsuAUOP3N13nfmm1sIP3Pe6tllGdozM,1657
40
+ cli/remotive.py,sha256=5Qt9jayyj1wGSyj2eyLzeJaZ1F8UrtznFzrPPcDqZnY,2988
41
41
  cli/settings/__init__.py,sha256=5ZRq04PHp3WU_5e7mGwWUoFYUPWfnnS16yF45wUv7mY,248
42
42
  cli/settings/config_file.py,sha256=6WHlJT74aQvqc5elcW1FDafcG0NttYvPawmArN5H2MQ,2869
43
43
  cli/settings/core.py,sha256=vRS_3JZDKRMGMa65C3LT178BCUcZ2RAlp2knn158CA4,15669
@@ -48,12 +48,13 @@ cli/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  cli/tools/can/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  cli/tools/can/can.py,sha256=TtP5w8vb0QG4ObNhkWIDpRMdNelirFffoc_lFZy8ePM,2260
50
50
  cli/tools/tools.py,sha256=jhLfrFDqkmWV3eBAzNwBf6WgDGrz7sOhgVCia36Twn8,232
51
+ cli/topology/cmd.py,sha256=loy_G6ZxYqUNsI3NaBaB4blk6Waq9HXoeKC51xLD2ME,4011
51
52
  cli/typer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
53
  cli/typer/typer_utils.py,sha256=8SkvG9aKkfK9fTRsLD9pOBtWn9XSwtOXWg2RAk9FhOI,708
53
54
  cli/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
55
  cli/utils/rest_helper.py,sha256=b_FJY6MxnFSqo11qaHxkBFHfVlKf7Zj28Uxv9Oj7XY4,14141
55
- remotivelabs_cli-0.1.1.dist-info/LICENSE,sha256=qDPP_yfuv1fF-u7EfexN-cN3M8aFgGVndGhGLovLKz0,608
56
- remotivelabs_cli-0.1.1.dist-info/METADATA,sha256=S0EkVqlAXfJQT2chMamWtl5mMgkIhX80eX4LNEgblN8,1428
57
- remotivelabs_cli-0.1.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
58
- remotivelabs_cli-0.1.1.dist-info/entry_points.txt,sha256=lvDhPgagLqW_KTnLPCwKSqfYlEp-1uYVosRiPjsVj10,45
59
- remotivelabs_cli-0.1.1.dist-info/RECORD,,
56
+ remotivelabs_cli-0.2.0a1.dist-info/LICENSE,sha256=qDPP_yfuv1fF-u7EfexN-cN3M8aFgGVndGhGLovLKz0,608
57
+ remotivelabs_cli-0.2.0a1.dist-info/METADATA,sha256=ssHc_nrlwEnVyt4315rqep3Jw4dbIH9oCawDUWmLx94,1430
58
+ remotivelabs_cli-0.2.0a1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
59
+ remotivelabs_cli-0.2.0a1.dist-info/entry_points.txt,sha256=lvDhPgagLqW_KTnLPCwKSqfYlEp-1uYVosRiPjsVj10,45
60
+ remotivelabs_cli-0.2.0a1.dist-info/RECORD,,