(plan: MigrationPlan)
| 687 | } |
| 688 | |
| 689 | const collectSecretValues = async (plan: MigrationPlan): Promise<CollectedSecretValues> => { |
| 690 | const authPath = resolveFileAuthPath(); |
| 691 | const fileValues = flatAuthEntries(readAuthFile(authPath)); |
| 692 | const keychainValues: { id: string; value: string }[] = []; |
| 693 | const idOverrides = new Map<string, string>(); |
| 694 | const oauthClientIdValues = new Map<string, string>(); |
| 695 | const warnings: string[] = []; |
| 696 | |
| 697 | for (const op of plan.secretOps) { |
| 698 | if (op.targetProvider !== FILE_PROVIDER && op.targetProvider !== KEYCHAIN_PROVIDER) { |
| 699 | if (op.fromSecret) idOverrides.set(op.itemId, op.fromSecret.secretId); |
| 700 | continue; |
| 701 | } |
| 702 | |
| 703 | const value = |
| 704 | op.fromText ?? |
| 705 | (op.fromSecret |
| 706 | ? await providerGet(op.fromSecret.provider, op.fromSecret.scopeId, op.fromSecret.secretId) |
| 707 | : null); |
| 708 | if (value == null) { |
| 709 | warnings.push( |
| 710 | `Could not resolve local secret "${op.fromSecret?.secretId ?? op.itemId}" from provider "${op.fromSecret?.provider ?? op.targetProvider}".`, |
| 711 | ); |
| 712 | continue; |
| 713 | } |
| 714 | |
| 715 | if (op.targetProvider === FILE_PROVIDER) { |
| 716 | fileValues[op.itemId] = value; |
| 717 | } else { |
| 718 | keychainValues.push({ id: op.itemId, value }); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | for (const client of plan.oauthClients) { |
| 723 | if (client.clientId.length > 0 || !client.clientIdSecretRef) continue; |
| 724 | const value = await providerGet( |
| 725 | client.clientIdSecretRef.provider, |
| 726 | client.clientIdSecretRef.scopeId, |
| 727 | client.clientIdSecretRef.secretId, |
| 728 | ); |
| 729 | if (value == null) { |
| 730 | warnings.push( |
| 731 | `Could not resolve OAuth client id "${client.clientIdSecretRef.secretId}" from provider "${client.clientIdSecretRef.provider}".`, |
| 732 | ); |
| 733 | continue; |
| 734 | } |
| 735 | oauthClientIdValues.set(oauthClientPlanKey(client), value); |
| 736 | } |
| 737 | |
| 738 | return { fileValues, keychainValues, idOverrides, oauthClientIdValues, warnings }; |
| 739 | }; |
| 740 | |
| 741 | const mapId = (id: string | null, overrides: ReadonlyMap<string, string>): string | null => |
| 742 | id == null ? null : (overrides.get(id) ?? id); |
no test coverage detected