-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring in other pentest branch to test batch function
- Loading branch information
Showing
19 changed files
with
339 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import AWS from "aws-sdk"; | ||
const cognito = new AWS.CognitoIdentityServiceProvider(); | ||
import { getUser } from "../../app-api/getUser"; | ||
|
||
async function updateUserAttribute(userPoolId, username, roles) { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
Username: username, | ||
UserAttributes: [ | ||
{ | ||
Name: 'custom:user_roles', | ||
Value: JSON.stringify(roles) | ||
} | ||
] | ||
}; | ||
|
||
await cognito.adminUpdateUserAttributes(params).promise(); | ||
} | ||
|
||
async function processCognitoUsers() { | ||
const userPoolId = process.env.USER_POOL_ID; | ||
console.log("user pool id: ", userPoolId) | ||
let paginationToken = null; | ||
let counter = 0; | ||
let hasRolesCounter = 0; | ||
let noRolesCounter =0; | ||
do { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
AttributesToGet: ['email'], | ||
PaginationToken: paginationToken | ||
}; | ||
|
||
const listUsersResponse = await cognito.listUsers(params).promise(); | ||
console.log(listUsersResponse.Users.length + " users found") | ||
|
||
for (const user of listUsersResponse.Users) { | ||
const emailAttribute = user.Attributes.find(attr => attr.Name === 'email'); | ||
if (emailAttribute) { | ||
const userEmail = emailAttribute.Value; | ||
|
||
try { | ||
const externalUser = await getUser(userEmail); | ||
let roles = [""]; | ||
if (externalUser.roleList) { | ||
roles = externalUser.roleList.map(role => role.role); | ||
hasRolesCounter ++; | ||
} else { | ||
noRolesCounter ++ | ||
} | ||
|
||
await updateUserAttribute(userPoolId, user.Username, roles); | ||
} catch (error) { | ||
console.error(`Error processing user ${userEmail}:`, error); | ||
} | ||
} | ||
counter++; | ||
} | ||
|
||
paginationToken = listUsersResponse.PaginationToken; | ||
} while (paginationToken); | ||
console.log(counter+ "users modified, "+ hasRolesCounter + "users had roles and "+ noRolesCounter + " users had no roles") | ||
} | ||
|
||
|
||
export const main = async () => { | ||
await processCognitoUsers().catch(console.error); | ||
console.log("function complete") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.