32
32
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." ,
33
33
)
34
34
def 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
+
37
39
# Validate organization
38
40
validate_organization (session , creds_in .organization_id )
39
41
40
42
# Validate project if provided
41
43
if creds_in .project_id :
42
44
project = validate_project (session , creds_in .project_id )
43
45
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
+ )
45
49
raise HTTPException (
46
50
status_code = 400 ,
47
51
detail = "Project does not belong to the specified organization" ,
@@ -56,7 +60,9 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
56
60
project_id = creds_in .project_id ,
57
61
)
58
62
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
+ )
60
66
raise HTTPException (
61
67
status_code = 400 ,
62
68
detail = (
@@ -68,10 +74,14 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
68
74
# Create credentials
69
75
new_creds = set_creds_for_org (session = session , creds_add = creds_in )
70
76
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
+ )
72
80
raise Exception (status_code = 500 , detail = "Failed to create credentials" )
73
81
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
+ )
75
85
return APIResponse .success_response ([cred .to_public () for cred in new_creds ])
76
86
77
87
@@ -83,13 +93,19 @@ def create_new_credential(*, session: SessionDep, creds_in: CredsCreate):
83
93
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." ,
84
94
)
85
95
def 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
+ )
87
99
creds = get_creds_by_org (session = session , org_id = org_id , project_id = project_id )
88
100
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
+ )
90
104
raise HTTPException (status_code = 404 , detail = "Credentials not found" )
91
105
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
+ )
93
109
return APIResponse .success_response ([cred .to_public () for cred in creds ])
94
110
95
111
@@ -103,7 +119,9 @@ def read_credential(*, session: SessionDep, org_id: int, project_id: int | None
103
119
def read_provider_credential (
104
120
* , session : SessionDep , org_id : int , provider : str , project_id : int | None = None
105
121
):
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
+ )
107
125
provider_enum = validate_provider (provider )
108
126
provider_creds = get_provider_credential (
109
127
session = session ,
@@ -112,10 +130,14 @@ def read_provider_credential(
112
130
project_id = project_id ,
113
131
)
114
132
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
+ )
116
136
raise HTTPException (status_code = 404 , detail = "Provider credentials not found" )
117
137
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
+ )
119
141
return APIResponse .success_response (provider_creds )
120
142
121
143
@@ -127,7 +149,9 @@ def read_provider_credential(
127
149
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." ,
128
150
)
129
151
def 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
+ )
131
155
validate_organization (session , org_id )
132
156
if not creds_in or not creds_in .provider or not creds_in .credential :
133
157
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
139
163
session = session , org_id = org_id , creds_in = creds_in
140
164
)
141
165
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
+ )
143
169
return APIResponse .success_response ([cred .to_public () for cred in updated_creds ])
144
170
145
171
@@ -152,10 +178,14 @@ def update_credential(*, session: SessionDep, org_id: int, creds_in: CredsUpdate
152
178
def delete_provider_credential (
153
179
* , session : SessionDep , org_id : int , provider : str , project_id : int | None = None
154
180
):
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
+ )
156
184
provider_enum = validate_provider (provider )
157
185
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
+ )
159
189
raise HTTPException (status_code = 400 , detail = "Invalid provider" )
160
190
161
191
provider_creds = get_provider_credential (
@@ -165,14 +195,18 @@ def delete_provider_credential(
165
195
project_id = project_id ,
166
196
)
167
197
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
+ )
169
201
raise HTTPException (status_code = 404 , detail = "Provider credentials not found" )
170
202
171
203
updated_creds = remove_provider_credential (
172
204
session = session , org_id = org_id , provider = provider_enum , project_id = project_id
173
205
)
174
206
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
+ )
176
210
return APIResponse .success_response (
177
211
{"message" : "Provider credentials removed successfully" }
178
212
)
@@ -188,13 +222,19 @@ def delete_provider_credential(
188
222
def delete_all_credentials (
189
223
* , session : SessionDep , org_id : int , project_id : int | None = None
190
224
):
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
+ )
192
228
creds = remove_creds_for_org (session = session , org_id = org_id , project_id = project_id )
193
229
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
+ )
195
233
raise HTTPException (
196
234
status_code = 404 , detail = "Credentials for organization not found"
197
235
)
198
236
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
+ )
200
240
return APIResponse .success_response ({"message" : "Credentials deleted successfully" })
0 commit comments