-
Notifications
You must be signed in to change notification settings - Fork 820
Expand file tree
/
Copy pathgen1ResourceDetailsFetcher.ts
More file actions
35 lines (31 loc) · 1.61 KB
/
gen1ResourceDetailsFetcher.ts
File metadata and controls
35 lines (31 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import path from 'path';
import { RefactorCategory } from './templategen';
import { getProjectMeta } from '@aws-amplify/amplify-e2e-core';
import { assertIdentityPool, assertStorage, assertUserPool, assertUserPoolClients } from './assertions';
async function getGen1AuthResourceDetails(projRoot: string) {
const gen1ProjRoot = path.join(projRoot, '.amplify', 'migration');
const gen1Meta = getProjectMeta(gen1ProjRoot);
const gen1Region = gen1Meta.providers.awscloudformation.Region;
const { gen1UserPoolId } = await assertUserPool(gen1Meta, gen1Region);
const { gen1IdentityPoolId } = await assertIdentityPool(gen1Meta, gen1Region);
const { gen1ClientIds } = await assertUserPoolClients(gen1Meta, gen1Region);
const gen1ClientIdWeb = gen1ClientIds[0];
const gen1ResourceIds = [gen1UserPoolId, gen1IdentityPoolId, gen1ClientIdWeb];
return { gen1ResourceIds };
}
async function getGen1StorageResourceDetails(projRoot: string) {
const gen1ProjRoot = path.join(projRoot, '.amplify', 'migration');
const gen1Meta = getProjectMeta(gen1ProjRoot);
const gen1Region = gen1Meta.providers.awscloudformation.Region;
const { gen1BucketName } = await assertStorage(gen1Meta, gen1Region);
const gen1ResourceIds = [gen1BucketName];
return { gen1ResourceIds };
}
export async function getGen1ResourceDetails(projRoot: string, category: RefactorCategory) {
if (category === 'auth') {
return await getGen1AuthResourceDetails(projRoot);
} else if (category === 'storage') {
return await getGen1StorageResourceDetails(projRoot);
}
throw new Error(`Invalid category for getting Gen 1 resource details ${category}`);
}