Skip to content

Commit b461dbf

Browse files
m-salaudeenchris-elliott-nhsd
authored andcommitted
CCM-10429: Templates and S3 migration
1 parent 54c147d commit b461dbf

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

data-migration/user-transfer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"@aws-sdk/client-dynamodb": "^3.864.0",
55
"@aws-sdk/client-s3": "^3.864.0",
66
"@aws-sdk/client-sts": "^3.864.0",
7+
"@aws-sdk/credential-providers": "^3.888.0",
78
"yargs": "^17.7.2"
89
},
910
"description": "Transfers template ownership from one user to another",

data-migration/user-transfer/src/user-transfer.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
} from '@/src/utils/ddb-utils';
1010
import { backupData } from '@/src/utils/backup-utils';
1111
import { Parameters } from '@/src/utils/constants';
12-
import { findCognitoUser, getUserGroup } from './utils/cognito-utils';
12+
import {
13+
findCognitoUser,
14+
getUserGroup,
15+
listCognitoUsers,
16+
} from './utils/cognito-utils';
1317
import {
1418
backupObject,
1519
copyObjects,
@@ -103,7 +107,10 @@ async function updateItems(
103107
export async function performTransfer() {
104108
const parameters = getParameters();
105109
const items = await retrieveAllTemplates(parameters);
106-
await backupData(items, parameters);
107-
await backupObject(parameters);
108-
await updateItems(items, parameters);
110+
console.log({ items });
111+
console.log(await listCognitoUsers());
112+
// retrieve all user (id and clientId) in cognito and save to a JSON file
113+
// await backupData(items, parameters);
114+
// await backupObject(parameters);
115+
// await updateItems(items, parameters);
109116
}

data-migration/user-transfer/src/utils/cognito-utils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import {
66
UserType,
77
GroupType,
88
} from '@aws-sdk/client-cognito-identity-provider';
9+
import { ListBackupsCommandOutput } from '@aws-sdk/client-dynamodb';
10+
import { fromIni } from '@aws-sdk/credential-providers';
911

12+
const COGNITO_PROFILE = process.env.COGNITO_ACCOUNT;
1013
const cognito = new CognitoIdentityProviderClient({
11-
region: 'eu-west-2',
14+
region: process.env.REGION,
15+
credentials: fromIni({ profile: COGNITO_PROFILE }),
1216
});
13-
const USER_POOL_ID = 'eu-west-2_OX5mAA0VI';
17+
const USER_POOL_ID = process.env.USER_POOL_ID;
1418

1519
interface CognitoUserBasics {
1620
username: string;
@@ -20,6 +24,17 @@ interface CognitoUserBasics {
2024
user?: UserType;
2125
}
2226

27+
export async function listCognitoUsers(): Promise<
28+
ListBackupsCommandOutput | undefined
29+
> {
30+
const command = new ListUsersCommand({
31+
UserPoolId: 'eu-west-2_lGFnZO7vx',
32+
});
33+
34+
const response = await cognito.send(command);
35+
return response;
36+
}
37+
2338
export async function findCognitoUser(
2439
ownerId: string
2540
): Promise<CognitoUserBasics | undefined> {
@@ -39,7 +54,7 @@ export async function findCognitoUser(
3954
username: user.Username!,
4055
sub,
4156
clientIdAttr,
42-
poolId: USER_POOL_ID,
57+
poolId: USER_POOL_ID as string,
4358
user,
4459
};
4560
}

0 commit comments

Comments
 (0)