3232 description = "Creates new credentials for a specific organization and project combination. This endpoint requires superuser privileges. Each organization can have different credentials for different providers and projects. Only one credential per provider is allowed per organization-project combination." ,
3333)
3434def create_new_credential (* , session : SessionDep , creds_in : CredsCreate ):
35- logger .info (f"[credential.create] Creating credentials | org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } " )
36-
35+ logger .info (
36+ f"[credential.create] Creating credentials | org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } "
37+ )
38+
3739 # Validate organization
3840 validate_organization (session , creds_in .organization_id )
3941
4042 # Validate project if provided
4143 if creds_in .project_id :
4244 project = validate_project (session , creds_in .project_id )
4345 if project .organization_id != creds_in .organization_id :
44- logger .warning (f"[credential.create] Project does not belong to organization | org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } " )
46+ logger .warning (
47+ f"[credential.create] Project does not belong to organization | org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } "
48+ )
4549 raise HTTPException (
4650 status_code = 400 ,
4751 detail = "Project does not belong to the specified organization" ,
@@ -56,7 +60,9 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
5660 project_id = creds_in .project_id ,
5761 )
5862 if existing_cred :
59- logger .warning (f"[credential.create] Credential exists | provider={ provider } , org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } " )
63+ logger .warning (
64+ f"[credential.create] Credential exists | provider={ provider } , org_id={ creds_in .organization_id } , project_id={ creds_in .project_id } "
65+ )
6066 raise HTTPException (
6167 status_code = 400 ,
6268 detail = (
@@ -68,10 +74,14 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
6874 # Create credentials
6975 new_creds = set_creds_for_org (session = session , creds_add = creds_in )
7076 if not new_creds :
71- logger .error (f"[credential.create] Failed to create credentials | org_id={ creds_in .organization_id } " )
77+ logger .error (
78+ f"[credential.create] Failed to create credentials | org_id={ creds_in .organization_id } "
79+ )
7280 raise Exception (status_code = 500 , detail = "Failed to create credentials" )
7381
74- logger .info (f"[credential.create] Credentials created | count={ len (new_creds )} , org_id={ creds_in .organization_id } " )
82+ logger .info (
83+ f"[credential.create] Credentials created | count={ len (new_creds )} , org_id={ creds_in .organization_id } "
84+ )
7585 return APIResponse .success_response ([cred .to_public () for cred in new_creds ])
7686
7787
@@ -83,13 +93,19 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
8393 description = "Retrieves all provider credentials associated with a specific organization and project combination. If project_id is not provided, returns credentials for the organization level. This endpoint requires superuser privileges." ,
8494)
8595def read_credential (* , session : SessionDep , org_id : int , project_id : int | None = None ):
86- logger .info (f"[credential.read] Fetching credentials | org_id={ org_id } , project_id={ project_id } " )
96+ logger .info (
97+ f"[credential.read] Fetching credentials | org_id={ org_id } , project_id={ project_id } "
98+ )
8799 creds = get_creds_by_org (session = session , org_id = org_id , project_id = project_id )
88100 if not creds :
89- logger .warning (f"[credential.read] No credentials found | org_id={ org_id } , project_id={ project_id } " )
101+ logger .warning (
102+ f"[credential.read] No credentials found | org_id={ org_id } , project_id={ project_id } "
103+ )
90104 raise HTTPException (status_code = 404 , detail = "Credentials not found" )
91105
92- logger .info (f"[credential.read] Retrieved { len (creds )} credentials | org_id={ org_id } , project_id={ project_id } " )
106+ logger .info (
107+ f"[credential.read] Retrieved { len (creds )} credentials | org_id={ org_id } , project_id={ project_id } "
108+ )
93109 return APIResponse .success_response ([cred .to_public () for cred in creds ])
94110
95111
@@ -103,7 +119,9 @@ def read_credential(*, session: SessionDep, org_id: int, project_id: int | None
103119def read_provider_credential (
104120 * , session : SessionDep , org_id : int , provider : str , project_id : int | None = None
105121):
106- logger .info (f"[credential.read_provider] Fetching provider credential | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
122+ logger .info (
123+ f"[credential.read_provider] Fetching provider credential | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
124+ )
107125 provider_enum = validate_provider (provider )
108126 provider_creds = get_provider_credential (
109127 session = session ,
@@ -112,10 +130,14 @@ def read_provider_credential(
112130 project_id = project_id ,
113131 )
114132 if provider_creds is None :
115- logger .warning (f"[credential.read_provider] Credential not found | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
133+ logger .warning (
134+ f"[credential.read_provider] Credential not found | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
135+ )
116136 raise HTTPException (status_code = 404 , detail = "Provider credentials not found" )
117137
118- logger .info (f"[credential.read_provider] Credential found | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
138+ logger .info (
139+ f"[credential.read_provider] Credential found | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
140+ )
119141 return APIResponse .success_response (provider_creds )
120142
121143
@@ -127,7 +149,9 @@ def read_provider_credential(
127149 description = "Updates credentials for a specific organization and project combination. Can update specific provider credentials or add new providers. If project_id is provided in the update, credentials will be moved to that project. This endpoint requires superuser privileges." ,
128150)
129151def update_credential (* , session : SessionDep , org_id : int , creds_in : CredsUpdate ):
130- logger .info (f"[credential.update] Updating credentials | org_id={ org_id } , provider={ creds_in .provider } , project_id={ creds_in .project_id } " )
152+ logger .info (
153+ f"[credential.update] Updating credentials | org_id={ org_id } , provider={ creds_in .provider } , project_id={ creds_in .project_id } "
154+ )
131155 validate_organization (session , org_id )
132156 if not creds_in or not creds_in .provider or not creds_in .credential :
133157 logger .warning (f"[credential.update] Invalid update payload | org_id={ org_id } " )
@@ -139,7 +163,9 @@ def update_credential(*, session: SessionDep, org_id: int, creds_in: CredsUpdate
139163 session = session , org_id = org_id , creds_in = creds_in
140164 )
141165
142- logger .info (f"[credential.update] Credentials updated | count={ len (updated_creds )} , org_id={ org_id } , provider={ creds_in .provider } " )
166+ logger .info (
167+ f"[credential.update] Credentials updated | count={ len (updated_creds )} , org_id={ org_id } , provider={ creds_in .provider } "
168+ )
143169 return APIResponse .success_response ([cred .to_public () for cred in updated_creds ])
144170
145171
@@ -152,10 +178,14 @@ def update_credential(*, session: SessionDep, org_id: int, creds_in: CredsUpdate
152178def delete_provider_credential (
153179 * , session : SessionDep , org_id : int , provider : str , project_id : int | None = None
154180):
155- logger .info (f"[credential.delete_provider] Deleting provider credential | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
181+ logger .info (
182+ f"[credential.delete_provider] Deleting provider credential | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
183+ )
156184 provider_enum = validate_provider (provider )
157185 if not provider_enum :
158- logger .warning (f"[credential.delete_provider] Invalid provider | provider={ provider } " )
186+ logger .warning (
187+ f"[credential.delete_provider] Invalid provider | provider={ provider } "
188+ )
159189 raise HTTPException (status_code = 400 , detail = "Invalid provider" )
160190
161191 provider_creds = get_provider_credential (
@@ -165,14 +195,18 @@ def delete_provider_credential(
165195 project_id = project_id ,
166196 )
167197 if provider_creds is None :
168- logger .warning (f"[credential.delete_provider] Credential not found | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
198+ logger .warning (
199+ f"[credential.delete_provider] Credential not found | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
200+ )
169201 raise HTTPException (status_code = 404 , detail = "Provider credentials not found" )
170202
171203 updated_creds = remove_provider_credential (
172204 session = session , org_id = org_id , provider = provider_enum , project_id = project_id
173205 )
174206
175- logger .info (f"[credential.delete_provider] Credential deleted | org_id={ org_id } , provider={ provider } , project_id={ project_id } " )
207+ logger .info (
208+ f"[credential.delete_provider] Credential deleted | org_id={ org_id } , provider={ provider } , project_id={ project_id } "
209+ )
176210 return APIResponse .success_response (
177211 {"message" : "Provider credentials removed successfully" }
178212 )
@@ -188,13 +222,19 @@ def delete_provider_credential(
188222def delete_all_credentials (
189223 * , session : SessionDep , org_id : int , project_id : int | None = None
190224):
191- logger .info (f"[credential.delete_all] Deleting all credentials | org_id={ org_id } , project_id={ project_id } " )
225+ logger .info (
226+ f"[credential.delete_all] Deleting all credentials | org_id={ org_id } , project_id={ project_id } "
227+ )
192228 creds = remove_creds_for_org (session = session , org_id = org_id , project_id = project_id )
193229 if not creds :
194- logger .warning (f"[credential.delete_all] No credentials found to delete | org_id={ org_id } , project_id={ project_id } " )
230+ logger .warning (
231+ f"[credential.delete_all] No credentials found to delete | org_id={ org_id } , project_id={ project_id } "
232+ )
195233 raise HTTPException (
196234 status_code = 404 , detail = "Credentials for organization not found"
197235 )
198236
199- logger .info (f"[credential.delete_all] All credentials deleted | org_id={ org_id } , project_id={ project_id } " )
237+ logger .info (
238+ f"[credential.delete_all] All credentials deleted | org_id={ org_id } , project_id={ project_id } "
239+ )
200240 return APIResponse .success_response ({"message" : "Credentials deleted successfully" })
0 commit comments