1- from typing import Optional , Dict , Any , List
1+ from typing import Optional , Dict , Any , List , Union
22from sqlmodel import Session , select
33from sqlalchemy .exc import IntegrityError
44from datetime import datetime , timezone
@@ -88,29 +88,20 @@ def get_creds_by_org(
8888
8989
9090def get_provider_credential (
91- * , session : Session , org_id : int , provider : str , project_id : Optional [int ] = None
92- ) -> Optional [Dict [str , Any ]]:
93- """Fetches credentials for a specific provider of an organization."""
94- validate_provider (provider )
95-
96- statement = select (Credential ).where (
97- Credential .organization_id == org_id ,
98- Credential .provider == provider ,
99- Credential .is_active == True ,
100- Credential .project_id == project_id if project_id is not None else True ,
101- )
102- creds = session .exec (statement ).first ()
103-
104- if creds and creds .credential :
105- # Decrypt entire credentials object
106- return decrypt_credentials (creds .credential )
107- return None
108-
109-
110- def get_full_provider_credential (
111- * , session : Session , org_id : int , provider : str , project_id : Optional [int ] = None
112- ) -> Optional [Credential ]:
113- """Fetches credentials for a specific provider of an organization."""
91+ * ,
92+ session : Session ,
93+ org_id : int ,
94+ provider : str ,
95+ project_id : Optional [int ] = None ,
96+ full : bool = False ,
97+ ) -> Optional [Union [Dict [str , Any ], Credential ]]:
98+ """
99+ Fetches credentials for a specific provider of a project.
100+
101+ Returns:
102+ Optional[Union[Dict[str, Any], Credential]]: If full is True, returns full Credential object.
103+ Otherwise returns just the decrypted credentials dict.
104+ """
114105 validate_provider (provider )
115106
116107 statement = select (Credential ).where (
@@ -122,8 +113,7 @@ def get_full_provider_credential(
122113 creds = session .exec (statement ).first ()
123114
124115 if creds and creds .credential :
125- # Return the full Credential object
126- return creds
116+ return creds if full else decrypt_credentials (creds .credential )
127117 return None
128118
129119
0 commit comments