createMigrationServices creates old and new encryption services for migration
()
| 477 | |
| 478 | // createMigrationServices creates old and new encryption services for migration |
| 479 | func (cmd *MigrateKeysCommand) createMigrationServices() (oldService, newService encryption.Service, err error) { |
| 480 | // Create old encryption service (for decryption) based on parameters only |
| 481 | if cmd.fromKey != "" { |
| 482 | // Decrypt with specified key |
| 483 | oldService, err = encryption.NewService(cmd.fromKey) |
| 484 | if err != nil { |
| 485 | return nil, nil, fmt.Errorf("failed to create old encryption service: %w", err) |
| 486 | } |
| 487 | } else { |
| 488 | // Enable encryption scenario: data should be unencrypted |
| 489 | // Use noop service (empty key means no encryption) |
| 490 | oldService, err = encryption.NewService("") |
| 491 | if err != nil { |
| 492 | return nil, nil, fmt.Errorf("failed to create noop encryption service for source: %w", err) |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Create new encryption service (for encryption) based on parameters only |
| 497 | if cmd.toKey != "" { |
| 498 | // Encrypt with specified key |
| 499 | newService, err = encryption.NewService(cmd.toKey) |
| 500 | if err != nil { |
| 501 | return nil, nil, fmt.Errorf("failed to create new encryption service: %w", err) |
| 502 | } |
| 503 | } else { |
| 504 | // Disable encryption scenario: data should be unencrypted |
| 505 | // Use noop service (empty key means no encryption) |
| 506 | newService, err = encryption.NewService("") |
| 507 | if err != nil { |
| 508 | return nil, nil, fmt.Errorf("failed to create noop encryption service for target: %w", err) |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | return oldService, newService, nil |
| 513 | } |
| 514 | |
| 515 | // processBatchToTempTable processes a batch of keys and writes to temporary table |
| 516 | func (cmd *MigrateKeysCommand) processBatchToTempTable(keys []models.APIKey, oldService, newService encryption.Service) error { |
no test coverage detected