33
44Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti.
556- Last updated: 01 /08/2024
6+ Last updated: 19 /08/2024
77"""
88
99import grpc
1010import jwt
1111import datetime
1212import logging
13- import cs3 .gateway .v1beta1 .gateway_api_pb2 as gw
13+ from cs3 .gateway .v1beta1 .gateway_api_pb2 import AuthenticateRequest
1414from cs3 .auth .registry .v1beta1 .registry_api_pb2 import ListAuthProvidersRequest
1515from cs3 .gateway .v1beta1 .gateway_api_pb2_grpc import GatewayAPIStub
1616from cs3 .rpc .v1beta1 .code_pb2 import CODE_OK
@@ -67,8 +67,8 @@ def get_token(self) -> tuple[str, str]:
6767 the credentials have expired.
6868
6969 :return tuple: A tuple containing the header key and the token.
70- May throw AuthenticationException (token expired, or failed to authenticate)
71- or SecretNotSetException (neither token or client secret was set).
70+ :raises: AuthenticationException (token expired, or failed to authenticate)
71+ :raises: SecretNotSetException (neither token or client secret was set)
7272 """
7373
7474 if not Auth ._check_token (self ._token ):
@@ -81,7 +81,7 @@ def get_token(self) -> tuple[str, str]:
8181 self ._log .error ("The provided token have expired" )
8282 raise AuthenticationException ("The credentials have expired" )
8383 # Create an authentication request
84- req = gw . AuthenticateRequest (
84+ req = AuthenticateRequest (
8585 type = self ._config .auth_login_type ,
8686 client_id = self ._config .auth_client_id ,
8787 client_secret = self ._client_secret ,
@@ -90,26 +90,25 @@ def get_token(self) -> tuple[str, str]:
9090 res = self ._gateway .Authenticate (req )
9191
9292 if res .status .code != CODE_OK :
93- self ._log .error (
94- f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status .message } "
95- )
93+ self ._log .error (f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status } " )
9694 raise AuthenticationException (
97- f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status . message } "
95+ f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status } "
9896 )
9997 self ._token = res .token
98+ self ._log .debug (f'msg="Authenticated user" user="{ self ._config .auth_client_id } "' )
10099 return ("x-access-token" , self ._token )
101100
102101 def list_auth_providers (self ) -> list [str ]:
103102 """
104103 list authentication providers
105104
106105 :return: a list of the supported authentication types
107- May return ConnectionError (Could not connect to host)
106+ :raises: ConnectionError (Could not connect to host)
108107 """
109108 try :
110109 res = self ._gateway .ListAuthProviders (request = ListAuthProvidersRequest ())
111110 if res .status .code != CODE_OK :
112- self ._log .error (f"List auth providers request failed, error: { res .status . message } " )
111+ self ._log .error (f"List auth providers request failed, error: { res .status } " )
113112 raise Exception (res .status .message )
114113 except grpc .RpcError as e :
115114 self ._log .error ("List auth providers request failed" )
0 commit comments