(ctx context.Context, providerId string, id string)
| 208 | } |
| 209 | |
| 210 | func (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 | |
| 255 | func (i *imlKeyModule) Get(ctx context.Context, providerId string, id string) (*ai_key_dto.Key, error) { |
| 256 | p, has := model_runtime.GetProvider(providerId) |
nothing calls this directly
no test coverage detected