This repository was archived by the owner on Jun 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,6 +128,32 @@ async def add_provider_endpoint(
128128 return provend
129129
130130
131+ @v1 .put (
132+ "/provider-endpoints/{provider_id}/auth-material" ,
133+ tags = ["Providers" ],
134+ generate_unique_id_function = uniq_name ,
135+ status_code = 204 ,
136+ )
137+ async def configure_auth_material (
138+ provider_id : UUID ,
139+ request : v1_models .ConfigureAuthMaterial ,
140+ ):
141+ """Add an API key to a provider endpoint.
142+
143+ Note that explicitly pushing an API key to a provider will change
144+ the authentication type to API key. To remove the API key, you must
145+ explicitly update the provider endpoint to remove the API key.
146+ """
147+ try :
148+ await pcrud .configure_auth_material (provider_id , request )
149+ except provendcrud .ProviderNotFoundError :
150+ raise HTTPException (status_code = 404 , detail = "Provider endpoint not found" )
151+ except Exception :
152+ raise HTTPException (status_code = 500 , detail = "Internal server error" )
153+
154+ return Response (status_code = 204 )
155+
156+
131157@v1 .put (
132158 "/provider-endpoints/{provider_id}" , tags = ["Providers" ], generate_unique_id_function = uniq_name
133159)
Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ class ProviderEndpoint(pydantic.BaseModel):
201201 description : str = ""
202202 provider_type : ProviderType
203203 endpoint : str
204- auth_type : ProviderAuthType
204+ auth_type : Optional [ ProviderAuthType ] = ProviderAuthType . none
205205
206206 @staticmethod
207207 def from_db_model (db_model : db_models .ProviderEndpoint ) -> "ProviderEndpoint" :
@@ -227,6 +227,14 @@ def to_db_model(self) -> db_models.ProviderEndpoint:
227227 def get_from_registry (self , registry : ProviderRegistry ) -> Optional [BaseProvider ]:
228228 return registry .get_provider (self .provider_type )
229229
230+ class ConfigureAuthMaterial (pydantic .BaseModel ):
231+ """
232+ Represents a request to configure auth material for a provider.
233+ """
234+
235+ auth_type : ProviderAuthType
236+ api_key : Optional [str ] = None
237+
230238
231239class ModelByProvider (pydantic .BaseModel ):
232240 """
Original file line number Diff line number Diff line change @@ -81,6 +81,23 @@ async def update_endpoint(
8181 dbendpoint = await self ._db_writer .update_provider_endpoint (endpoint .to_db_model ())
8282 return apimodelsv1 .ProviderEndpoint .from_db_model (dbendpoint )
8383
84+ async def configure_auth_material (self , provider_id : UUID , config : apimodelsv1 .ConfigureAuthMaterial ):
85+ """Add an API key."""
86+ if config .auth_type == apimodelsv1 .ProviderAuthType .api_key and not config .api_key :
87+ raise ValueError ("API key must be provided for API auth type" )
88+ elif config .auth_type != apimodelsv1 .ProviderAuthType .api_key and config .api_key :
89+ raise ValueError ("API key provided for non-API auth type" )
90+
91+ dbendpoint = await self ._db_reader .get_provider_endpoint_by_id (str (provider_id ))
92+ if dbendpoint is None :
93+ raise ProviderNotFoundError ("Provider not found" )
94+
95+ await self ._db_writer .push_provider_auth_material (dbmodels .ProviderAuthMaterial (
96+ provider_endpoint_id = dbendpoint .id ,
97+ auth_type = config .auth_type ,
98+ auth_blob = config .api_key if config .api_key else "" ,
99+ ))
100+
84101 async def delete_endpoint (self , provider_id : UUID ):
85102 """Delete an endpoint."""
86103
You can’t perform that action at this time.
0 commit comments