1313app = typer .Typer ()
1414
1515app .add_typer (commands .config_app , name = "config" , help = "Manage the configuration" )
16+ app .add_typer (commands .devices_app , name = "devices" , help = "Manage vpn devices" )
1617
1718@app .callback ()
1819def callback ():
@@ -39,7 +40,7 @@ def me(
3940 Print the current status of the fastonboard-api account
4041 """
4142 api_driver = APIDriver ()
42- data = api_driver .get ("/me" )
43+ data = api_driver .get ("/me" ). json ()
4344 if json :
4445 print (dumps (data ))
4546 return
@@ -66,12 +67,12 @@ def sync():
6667 Ask FastOnBoard-API to sync your account onto the vpn and openstack services
6768 """
6869 api = APIDriver ()
69- me = api .get ("/me" )
70- task_id = api .get ("/users/" + me ['username' ] + "/sync" )
70+ me = api .get ("/me" ). json ()
71+ task_id = api .get ("/users/" + me ['username' ] + "/sync" ). json ()
7172 typer .echo (f"Syncing account for user { me ['username' ]} this may take a while..." )
7273 typer .echo ("Task ID: " + task_id .get ("id" ))
7374 while True :
74- task = api .get ("/users/" + me ['username' ] + "/sync/" + task_id .get ("id" ))
75+ task = api .get ("/users/" + me ['username' ] + "/sync/" + task_id .get ("id" )). json ()
7576 if task .get ("status" ) == "SUCCESS" :
7677 typer .echo ("Sync successful" )
7778 break
@@ -81,11 +82,16 @@ def sync():
8182 sleep (1 )
8283
8384@app .command ()
84- def login (username : Annotated [ str , typer .Argument ( help = "The username to authenticate with" )] ):
85+ def login (username : str = typer .Option ( None , help = "The username to login with" )):
8586 """
8687 Login to the FastOnBoard-API server
8788 Enter your password when prompted or set LABCTL_API_ENDPOINT_PASSWORD
8889 """
90+ env_user = environ .get ("LABCTL_API_ENDPOINT_USERNAME" )
91+ username = Config ().username or username or env_user
92+ if not username :
93+ username = typer .prompt ("Enter your username" )
94+
8995 env_pass = environ .get ("LABCTL_API_ENDPOINT_PASSWORD" )
9096 if env_pass :
9197 password = env_pass
@@ -103,7 +109,7 @@ def login(username: Annotated[str, typer.Argument(help="The username to authenti
103109 'password' : password ,
104110 }, additional_headers = {
105111 'Content-Type' : 'application/x-www-form-urlencoded' ,
106- })
112+ }). json ()
107113 if 'detail' in data :
108114 if "Method Not Allowed" in data ['detail' ]:
109115 console .print ("[red]Error: Invalid endpoint or path to api[/red]" )
@@ -112,6 +118,7 @@ def login(username: Annotated[str, typer.Argument(help="The username to authenti
112118 return
113119 if 'access_token' in data :
114120 config = Config ()
121+ config .username = username
115122 config .api_token = data ['access_token' ]
116123 config .token_type = data ["token_type" ]
117124 config .save ()
0 commit comments