@@ -47,7 +47,7 @@ class CloudEndureAPI:
4747
4848 TOP_LEVEL : List [str ] = ["projects" , "blueprints" ]
4949
50- def __init__ (self , * args , ** kwargs ) -> None :
50+ def __init__ (self , config : CloudEndureConfig , * args , ** kwargs ) -> None :
5151 """Initialize the CloudEndure API client.
5252
5353 Attributes:
@@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs) -> None:
5757 time_now : datetime .datetime = datetime .datetime .utcnow ()
5858
5959 self .api_endpoint : str = f"{ HOST } /api/{ API_VERSION } "
60- self .config : CloudEndureConfig = CloudEndureConfig ()
60+ self .config : CloudEndureConfig = config
6161
6262 self .projects : List [str ] = []
6363 self .session : Session = requests .Session ()
@@ -75,27 +75,44 @@ def __init__(self, *args, **kwargs) -> None:
7575 if _xsrf_token :
7676 self .session .headers .update ({"X-XSRF-TOKEN" : _xsrf_token })
7777
78- def login (self , username : str = "" , password : str = "" ) -> bool :
78+ def login (self , username : str = "" , password : str = "" , token : str = "" ) -> bool :
7979 """Login to the CloudEndure API console.
8080
8181 Args:
8282 username (str): The CloudEndure username to be used.
8383 Defaults to the environment specific default.
8484 password (str): The CloudEndure password to be used.
8585 Defaults to the environment specific default.
86+ token (str): The CloudEndure token to be used. This argument takes precedence.
87+ If provided, username and password will not be used.
88+ Defaults to the environment specific default.
8689
8790 Attributes:
8891 endpoint (str): The CloudEndure API endpoint to be used.
8992 _username (str): The CloudEndure API username.
9093 _password (str): The CloudEndure API password.
94+ _token (str): The CloudEndure API token.
9195 _auth (dict): The CloudEndure API username/password dictionary map.
9296 response (requests.Response): The CloudEndure API login request response object.
9397 _xsrf_token (str): The XSRF token to be used for subsequent API requests.
9498
99+ TODO:
100+ * Verify default XSRF-Token TTL and check validity before performing
101+ subsequent authentication requests.
102+
95103 """
96104 _username : str = self .config .active_config ["username" ] or username
97105 _password : str = self .config .active_config ["password" ] or password
98- _auth : Dict [str , str ] = {"username" : _username , "password" : _password }
106+ _token : str = self .config .active_config ["user_api_token" ] or token
107+ _auth : Dict [str , str ] = {}
108+
109+ if _token :
110+ _auth ["userApiToken" ] = _token
111+ elif _username and _password :
112+ _auth = {"username" : _username , "password" : _password }
113+ else :
114+ print ("You must configure your authentication credentials!" )
115+ return False
99116
100117 # Attempt to login to the CloudEndure API via a POST request.
101118 response : requests .Response = self .api_call (
0 commit comments