@@ -59,7 +59,7 @@ def validate_environment(self) -> Self:
5959 self .authenticate ()
6060 return self
6161
62- def check_credentials (self ) -> bool :
62+ def credentials_available (self ) -> bool :
6363 """Check if all required credentials are present."""
6464 return (
6565 self .access_token is not None
@@ -68,28 +68,29 @@ def check_credentials(self) -> bool:
6868 and self .organization_id is not None
6969 )
7070
71- def authenticate (self ) -> None :
71+ def load_credentials (self ) -> None :
72+ """Load credentials from environment variables."""
73+ load_dotenv (override = True )
74+ self .access_token = SecretStr (os .getenv ("UIPATH_ACCESS_TOKEN" , "" ))
75+ self .base_url = os .getenv ("UIPATH_URL" )
76+ self .tenant_id = os .getenv ("UIPATH_TENANT_ID" )
77+ self .organization_id = os .getenv ("UIPATH_ORGANIZATION_ID" )
78+
79+ def authenticate (self , force : bool = False ) -> None :
7280 """Authenticate with UiPath using the configured credentials."""
73- if not self .check_credentials ():
74- auth_service = AuthService (
75- environment = self .environment ,
76- force = True ,
77- client_id = self .client_id .get_secret_value () if self .client_id is not None else None ,
78- client_secret = self .client_secret .get_secret_value ()
79- if self .client_secret is not None
80- else None ,
81- base_url = self .base_url ,
82- tenant = self .tenant_id ,
83- scope = self .client_scope ,
84- )
85- auth_service .authenticate ()
86- load_dotenv (override = True )
87- self .access_token = SecretStr (os .getenv ("UIPATH_ACCESS_TOKEN" , "" ))
88- self .base_url = os .getenv ("UIPATH_URL" )
89- self .tenant_id = os .getenv ("UIPATH_TENANT_ID" )
90- self .organization_id = os .getenv ("UIPATH_ORGANIZATION_ID" )
91- if not self .check_credentials ():
92- raise ValueError ("Could not authenticate with UiPath" )
81+ auth_service = AuthService (
82+ environment = self .environment ,
83+ force = force or not self .credentials_available (),
84+ client_id = self .client_id .get_secret_value () if self .client_id is not None else None ,
85+ client_secret = self .client_secret .get_secret_value ()
86+ if self .client_secret is not None
87+ else None ,
88+ base_url = self .base_url ,
89+ tenant = self .tenant_id ,
90+ scope = self .client_scope ,
91+ )
92+ auth_service .authenticate ()
93+ self .load_credentials ()
9394
9495 @override
9596 def build_base_url (
0 commit comments