MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Delete

Method Delete

module/ai-key/iml.go:210–253  ·  view source on GitHub ↗
(ctx context.Context, providerId string, id string)

Source from the content-addressed store, hash-verified

208}
209
210func (i *imlKeyModule) Delete(ctx context.Context, providerId string, id string) error {
211 _, err := i.providerService.Get(ctx, providerId)
212 if err != nil {
213 return fmt.Errorf("provider not found: %w", err)
214 }
215 return i.transaction.Transaction(ctx, func(ctx context.Context) error {
216 info, err := i.aiKeyService.Get(ctx, id)
217 if err != nil {
218 if errors.Is(err, gorm.ErrRecordNotFound) {
219 return nil
220 }
221 return err
222 }
223 if info.Default {
224 return fmt.Errorf("default key can't be deleted: %s", id)
225 }
226 keys, err := i.aiKeyService.KeysAfterPriority(ctx, providerId, info.Priority)
227 if err != nil {
228 return err
229 }
230 for _, key := range keys {
231 key.Priority--
232 err = i.aiKeyService.Save(ctx, key.ID, &ai_key.Edit{
233 Priority: &key.Priority,
234 })
235 if err != nil {
236 return err
237 }
238 }
239
240 err = i.aiKeyService.Delete(ctx, id)
241 if err != nil {
242 return err
243 }
244 return i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{{
245 BasicItem: &gateway.BasicItem{
246 ID: fmt.Sprintf("%s-%s", providerId, id),
247 Resource: "ai-key",
248 },
249 Attr: nil,
250 },
251 }, false)
252 })
253}
254
255func (i *imlKeyModule) Get(ctx context.Context, providerId string, id string) (*ai_key_dto.Key, error) {
256 p, has := model_runtime.GetProvider(providerId)

Callers

nothing calls this directly

Calls 5

syncGatewayMethod · 0.95
GetMethod · 0.65
KeysAfterPriorityMethod · 0.65
SaveMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected