Skip to content

Commit 376abd6

Browse files
fix auth commands
1 parent e3b2da3 commit 376abd6

File tree

5 files changed

+493
-19
lines changed

5 files changed

+493
-19
lines changed

src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/user.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import TYPE_CHECKING, Optional
2-
2+
from threading import Thread
33
from .basic import Basic
44

55
from pieces._vendor.pieces_os_client.models.allocation_status_enum import AllocationStatusEnum
@@ -53,19 +53,19 @@ def _on_login_connect(self):
5353
thread: The thread handling the login process.
5454
timeout: The maximum time to wait for the login process.
5555
"""
56-
self.connect(True)
57-
56+
self.connect()
5857
def login(self, connect_after_login=True, timeout=120):
5958
"""
6059
Logs the user into the OS and optionally connects to the cloud.
6160
6261
Args:
63-
connect_after_login: A flag indicating if the user should connect to the cloud after login (default is True).
64-
timeout: The maximum time to wait for the login process (default is 120 seconds).
62+
connect_after_login: A flag indicating if the user should connect to the cloud after login (default is True).
63+
timeout: The maximum time to wait for the login process (default is 120 seconds).
6564
"""
66-
thread = self.pieces_client.os_api.sign_into_os(async_req=True)
65+
thread = Thread(target=self.pieces_client.os_api.sign_into_os)
66+
thread.start()
6767
if connect_after_login:
68-
user = thread.get(timeout)
68+
user = thread.join(timeout)
6969
self.user_profile = user
7070
self._on_login_connect()
7171

@@ -84,8 +84,20 @@ def connect(self, async_req = False):
8484
"""
8585
if not self.user_profile:
8686
raise PermissionError("You must be logged in to use this feature")
87-
self.on_user_callback(self.user_profile, True) # Set the connecting to cloud bool to true
88-
self.pieces_client.allocations_api.allocations_connect_new_cloud(self.user_profile,async_req=async_req)
87+
self.on_user_callback(
88+
self.user_profile, True
89+
) # Set the connecting to cloud bool to true
90+
if async_req:
91+
thread = Thread(
92+
target=self.pieces_client.allocations_api.allocations_connect_new_cloud,
93+
args=(self.user_profile,),
94+
)
95+
thread.start()
96+
else:
97+
self.pieces_client.allocations_api.allocations_connect_new_cloud(
98+
self.user_profile
99+
)
100+
89101

90102
def disconnect(self):
91103
"""

src/pieces/_vendor/pieces_os_client/wrapper/client.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,6 @@ def pieces_os_installer(self, callback: Callable[[DownloadModel], None]) -> PosI
282282
"""
283283
return PosInstaller(callback, self.app_name)
284284

285-
def pool(self, api_call, args):
286-
"""
287-
call the api async without stopping the main thread
288-
Create thread pool on first request
289-
avoids instantiating unused threadpool for blocking clients.
290-
return the ThreadPool created
291-
"""
292-
return self.api_client.pool.apply_async(api_call, args)
293-
294285

295286
# Register the function to be called on exit
296287
atexit.register(PiecesClient.close)

src/pieces/command_interface/auth_commands.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import argparse
2+
from pieces._vendor.pieces_os_client.models.allocation_status_enum import (
3+
AllocationStatusEnum,
4+
)
25
from pieces.base_command import BaseCommand
36
from pieces.urls import URLs
47
from pieces.settings import Settings
@@ -40,9 +43,16 @@ def execute(self, **kwargs) -> int:
4043
Settings.pieces_client.user_api.user_snapshot().user
4144
)
4245
if Settings.pieces_client.user.user_profile:
46+
status = Settings.pieces_client.user.cloud_status or AllocationStatusEnum.DISCONNECTED
4347
Settings.logger.print(
44-
f"Signed in as {Settings.pieces_client.user.name}\nemail: {Settings.pieces_client.user.email}"
48+
f"Signed in as {Settings.pieces_client.user.name}\nEmail: {Settings.pieces_client.user.email}\nCloud status: {status.value.title()}"
4549
)
50+
if (
51+
Settings.pieces_client.user.cloud_status
52+
== AllocationStatusEnum.DISCONNECTED
53+
):
54+
Settings.logger.print("Connecting to the Pieces Cloud...")
55+
Settings.pieces_client.user.connect()
4656
return 0
4757
try:
4858
Settings.pieces_client.user.login(True)

src/pieces/core/assets_command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def wrapper(*args, **kwargs):
5050
AssetsCommands.current_asset.asset # Check if the current asset is vaild
5151
except (ValueError, NotFoundException):
5252
ListCommand.list_assets()
53+
if AssetsCommands.current_asset is None:
54+
return
5355
return func(asset=AssetsCommands.current_asset, *args, **kwargs)
5456

5557
return wrapper

0 commit comments

Comments
 (0)