1414
1515
1616class StaxAuth :
17- def __init__ (self , config_branch , max_retries : int = 3 ):
18- config = StaxConfig . api_config
19-
20- self .identity_pool = config .get (config_branch ).get ("identityPoolId" )
21- self .user_pool = config .get (config_branch ).get ("userPoolId" )
22- self .client_id = config .get (config_branch ).get ("userPoolWebClientId" )
23- self .aws_region = config .get (config_branch ).get ("region" )
17+ def __init__ (self , config_branch : str , config : StaxConfig , max_retries : int = 3 ):
18+ self . config = config
19+ api_config = self . config . api_config
20+ self .identity_pool = api_config .get (config_branch ).get ("identityPoolId" )
21+ self .user_pool = api_config .get (config_branch ).get ("userPoolId" )
22+ self .client_id = api_config .get (config_branch ).get ("userPoolWebClientId" )
23+ self .aws_region = api_config .get (config_branch ).get ("region" )
2424 self .max_retries = max_retries
2525
26- def requests_auth (self , username , password , ** kwargs ):
26+ def requests_auth (self , ** kwargs ):
27+ username = self .config .access_key
28+ password = self .config .secret_key
2729 if username is None :
2830 raise InvalidCredentialsException (
2931 "Please provide an Access Key to your config"
@@ -37,10 +39,10 @@ def requests_auth(self, username, password, **kwargs):
3739 id_creds = self .sts_from_cognito_identity_pool (id_token , ** kwargs )
3840 auth = self .sigv4_signed_auth_headers (id_creds )
3941
40- StaxConfig .expiration = id_creds .get ("Credentials" ).get ("Expiration" )
41- StaxConfig .auth = auth
42+ self . config .expiration = id_creds .get ("Credentials" ).get ("Expiration" )
43+ self . config .auth = auth
4244
43- return StaxConfig .auth
45+ return self . config .auth
4446
4547 def id_token_from_cognito (
4648 self , username = None , password = None , srp_client = None , ** kwargs
@@ -69,7 +71,7 @@ def id_token_from_cognito(
6971 elif e .response ["Error" ]["Code" ] == "UserNotFoundException" :
7072 raise InvalidCredentialsException (
7173 message = str (e ),
72- detail = "Please check your Access Key, that you have created your Api Token and that you are using the right STAX REGION" ,
74+ detail = f "Please check your Access Key { username } { password } , that you have created your Api Token and that you are using the right STAX REGION { self . config . hostname } { self . aws_region } " ,
7375 )
7476 else :
7577 raise InvalidCredentialsException (
@@ -121,7 +123,7 @@ def sigv4_signed_auth_headers(self, id_creds):
121123 aws_access_key = id_creds .get ("Credentials" ).get ("AccessKeyId" ),
122124 aws_secret_access_key = id_creds .get ("Credentials" ).get ("SecretKey" ),
123125 aws_token = id_creds .get ("Credentials" ).get ("SessionToken" ),
124- aws_host = f"{ StaxConfig .hostname } " ,
126+ aws_host = f"{ self . config .hostname } " ,
125127 aws_region = self .aws_region ,
126128 aws_service = "execute-api" ,
127129 )
@@ -139,11 +141,11 @@ def requests_auth(username, password, **kwargs):
139141
140142class ApiTokenAuth :
141143 @staticmethod
142- def requests_auth (username , password , ** kwargs ):
144+ def requests_auth (config : StaxConfig , ** kwargs ):
143145 # Minimize the potentical for token to expire while still being used for auth (say within a lambda function)
144- if StaxConfig .expiration and StaxConfig .expiration - timedelta (
146+ if config .expiration and config .expiration - timedelta (
145147 minutes = int (environ .get ("TOKEN_EXPIRY_THRESHOLD_IN_MINS" , 1 ))
146148 ) > datetime .now (timezone .utc ):
147- return StaxConfig .auth
149+ return config .auth
148150
149- return StaxAuth ("ApiAuth" ).requests_auth (username , password , ** kwargs )
151+ return StaxAuth ("ApiAuth" , config ).requests_auth (** kwargs )
0 commit comments