-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/add email and group creation to cognito helper script #42
Closed
kalleeh
wants to merge
4
commits into
master
from
feat/add-email-and-group-creation-to-cognito-helper-script
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo -e "Checking if the platform has been setup..\n" | ||
|
||
## Retreive Cognito Details | ||
USER_POOL_ID=$(aws cognito-idp list-user-pools --max-results 20 | jq -r '.UserPools[] | select(.Name == "gurum_users") | .Id') | ||
if [ -z $USER_POOL_ID ]; then | ||
echo "No user pool found. Ensure the platform has been setup first." | ||
exit 1 | ||
fi | ||
|
||
##App client id | ||
IDENTITY_POOL_ID=$(aws cognito-identity list-identity-pools --max-results 20 | jq -r '.IdentityPools[] | select(.IdentityPoolName == "gurum_idp") | .IdentityPoolId') | ||
if [ -z $IDENTITY_POOL_ID ]; then | ||
echo "No identity pool found. Ensure the platform has been setup first." | ||
exit 1 | ||
fi | ||
|
||
# MODIFY TRUST POLICY JSON | ||
MYDIR="$(dirname "$(which "$0")")" | ||
sed -i.bak "s/###REPLACEIDENTITYPOOLID###/$IDENTITY_POOL_ID/g" $MYDIR/group_trust_policy.json | ||
|
||
# USER CREATION | ||
echo "Enter a group name:" | ||
read GROUP_NAME | ||
|
||
## Create the IAM Role | ||
ROLE_NAME="gurum-$GROUP_NAME-role" | ||
ROLE_ARN=$(aws iam create-role \ | ||
--path '/gurum/groups/' \ | ||
--role-name $ROLE_NAME \ | ||
--assume-role-policy-document file://$MYDIR/group_trust_policy.json \ | ||
--description "Gurum Cognito Group Assume Role for $GROUP_NAME" \ | ||
--tags Key=gurum-groups,Value=$GROUP_NAME | jq -r '.Role.Arn') | ||
|
||
## Attach IAM role policy | ||
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account') | ||
aws iam attach-role-policy \ | ||
--role-name $ROLE_NAME \ | ||
--policy-arn "arn:aws:iam::$ACCOUNT_ID:policy/gurum/gurum-group-policy" | ||
|
||
## Create the Cognito Group | ||
aws cognito-idp create-group \ | ||
--group-name $GROUP_NAME \ | ||
--user-pool-id $USER_POOL_ID \ | ||
--role-arn $ROLE_ARN > /dev/null | ||
|
||
echo -e "\n\nSuccess! Group created and mapped to an IAM role." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Federated": "cognito-identity.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRoleWithWebIdentity", | ||
"Condition": { | ||
"StringEquals": { | ||
"cognito-identity.amazonaws.com:aud": "###REPLACEIDENTITYPOOLID###" | ||
} | ||
} | ||
} | ||
] | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename "REPLACEIDENTITYPOOLID" to "RESERVED_FOR_QUICK_GROUP_SCRIPT"
Restore original file after.