Skip to content

Commit

Permalink
Merge branch 'develop' into onemacmmdl
Browse files Browse the repository at this point in the history
  • Loading branch information
bflynn-cms committed Oct 20, 2024
2 parents 5293cd0 + 60f619a commit fd1923d
Show file tree
Hide file tree
Showing 59 changed files with 1,969 additions and 262 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tests/cypress/videos
tests/cypress/screenshots
tests/cypress/fixtures/packageDashboardSPAIDs.json
tests/cypress/fixtures/packageDashboardWaiverNumbers.json
tests/cypress/fixtures/savedID.json
tests/cypress/fixtures/savedID.json
/services/layers/aws-sdk-v2-layer/.serverless
15 changes: 15 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
stage=${1:-dev}

install_deps() {
local islayer=false # Flag to track whether we navigated into the nodejs folder

# Check if we're inside a layer directory (layers have a 'nodejs' folder)
if [ -d "nodejs" ]; then
# If we're in a Lambda layer, navigate to the 'nodejs' folder
cd nodejs
islayer=true # Set the flag to true since we navigated into nodejs
fi

if [ "$CI" == "true" ]; then # If we're in a CI system
if [ ! -d "node_modules" ]; then # If we don't have any node_modules (CircleCI cache miss scenario), run npm ci. Otherwise, we're all set, do nothing.
npm ci --legacy-peer-deps
fi
else # We're not in a CI system, let's npm install
npm install --legacy-peer-deps
fi

# If we navigated to the nodejs folder (i.e., for a layer), go back to the root folder
if [ "$islayer" = true ]; then
cd ..
fi
}

deploy() {
Expand All @@ -25,6 +39,7 @@ install_deps
services=(
'ui'
'uploads'
'layers/aws-sdk-v2-layer'
'app-api'
'email'
'one-stream'
Expand Down
2 changes: 1 addition & 1 deletion services/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"version": "1.0.0",
"devDependencies": {
"aws-sdk-client-mock": "^0.5.6",
"aws-sdk": "^2.752.0",
"esbuild": "^0.19.4",
"serverless-dotenv-plugin": "^3.12.2",
"serverless-esbuild": "^1.48.4",
"serverless-offline": "^13.5.0"
},
"dependencies": {
"aws-sdk": "^2.752.0",
"@aws-sdk/client-dynamodb": "^3.43.0",
"@aws-sdk/lib-dynamodb": "^3.454.0",
"cmscommonlib": "file:../common",
Expand Down
7 changes: 7 additions & 0 deletions services/admin/scripts/READ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This /scripts Folder simply contains scripts that are not used in the application or deployed via lambda but are useful for admin type functions.

#####

generate_packages - creates new records in Under Review status by inserting both a OneMAC record and a SEATool record
rebuildPackagesbyPK - force a rebuild of the package record for all packages listed in pk_values.json
setPOCs - set the action_officers (srt) and lead_analyst (cpoc) for all packages listed in pk_values.json
82 changes: 82 additions & 0 deletions services/admin/scripts/createUsers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

# Variables
USER_POOL_ID="us-east-1_9NXuk7ucb"
INPUT_FILE="users.json"
DYNAMODB_TABLE="onemac-masterclone-one"
DATE=$(date +%s%3N) # Current timestamp in milliseconds

# Read the JSON file and loop through each user
jq -c '.users[]' $INPUT_FILE | while read -r user; do
PASSWORD=$(echo $user | jq -r '.password')
EMAIL=$(echo $user | jq -r '.email')
FAMILY_NAME=$(echo $user | jq -r '.family_name')
GIVEN_NAME=$(echo $user | jq -r '.given_name')
ROLE=$(echo $user | jq -r '.role')

# Concatenate given name and family name to form full name
FULL_NAME="$GIVEN_NAME $FAMILY_NAME"

# Determine territory and GSI fields based on role
if [ "$ROLE" = "systemadmin" ]; then
TERRITORY="N/A"
GSI1SK="Boss"
GSI1PK="systemadmin#N/A"
else
TERRITORY=$(echo $user | jq -r '.territory')
GSI1SK="statesystemadmin#$TERRITORY"
GSI1PK="USER"
fi

echo "Creating user with email: $EMAIL"

# Use the email as the username in Cognito
aws cognito-idp admin-create-user \
--user-pool-id "$USER_POOL_ID" \
--username "$EMAIL" \
--user-attributes Name="email",Value="$EMAIL" \
Name="family_name",Value="$FAMILY_NAME" \
Name="given_name",Value="$GIVEN_NAME" \
Name="email_verified",Value="true" \
--message-action SUPPRESS

# Set the password and mark the user as confirmed
aws cognito-idp admin-set-user-password \
--user-pool-id "$USER_POOL_ID" \
--username "$EMAIL" \
--password "$PASSWORD" \
--permanent

echo "User created with email (used as username): $EMAIL"

# Insert ContactInfo record into DynamoDB
aws dynamodb put-item --table-name "$DYNAMODB_TABLE" --item \
'{"pk": {"S": "'"$EMAIL"'"},
"sk": {"S": "ContactInfo"},
"email": {"S": "'"$EMAIL"'"},
"fullName": {"S": "'"$FULL_NAME"'"},
"GSI1pk": {"S": "'"$GSI1PK"'"},
"GSI1sk": {"S": "'"$EMAIL"'"} }'

echo "ContactInfo record created for user: $EMAIL"

# Insert Roles record into DynamoDB
aws dynamodb put-item --table-name "$DYNAMODB_TABLE" --item \
'{"pk": {"S": "'"$EMAIL"'"},
"sk": {"S": "v0#'"$ROLE"'#'"$TERRITORY"'"},
"date": {"N": "'"$DATE"'"},
"doneByEmail": {"S": "'"$EMAIL"'"},
"doneByName": {"S": "'"$FULL_NAME"'"},
"email": {"S": "'"$EMAIL"'"},
"fullName": {"S": "'"$FULL_NAME"'"},
"GSI1pk": {"S": "'"$GSI1PK"'"},
"GSI1sk": {"S": "'"$GSI1SK"'"},
"GSI2pk": {"S": "'"$ROLE"'#'"$TERRITORY"'"},
"GSI2sk": {"S": "active"},
"Latest": {"S": "1"},
"role": {"S": "'"$ROLE"'"},
"status": {"S": "active"},
"territory": {"S": "'"$TERRITORY"'"} }'

echo "Roles record created for user: $EMAIL"
done
41 changes: 41 additions & 0 deletions services/admin/scripts/delete_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Variables
DYNAMODB_TABLE="onemac-masterclone-one"
PK_VALUES=("NY-24-9356" "NY-24-6035" "NY-24-3865" "NY-24-1282" "NY-24-1036" "NY-24-9253" "NY-24-9972" "NY-24-1717" "NY-24-5342" "NY-24-8523" "NY-24-1571" "NY-24-7203" "NY-80815.R01.02" "NY-66338.R01.02" "NY-84734.R01.00" "NY-23214.R01.02" "NY-94872.R00.00" "NY-93400.R00.00" "NY-72598.R01.02" "NY-84074.R01.00" "NY-49584.R00.01" "NY-52227.R00.00" "NY-27845.R01.00" "NY-95809.R00.01" "NY-53801.R01.02" "NY-38783.R00.01" "NY-75550.R00.01" "NY-92181.R01.00" "NY-18445.R00.00" "NY-57782.R01.00" "NY-52513.R00.00" "NY-99845.R00.01" "NY-76823.R00.01" "NY-42146.R01.02" "NY-52725.R00.00" "NY-14938.R01.00")

# Counter for deleted items
DELETED_COUNT=0

# Loop through each pk value
for PK in "${PK_VALUES[@]}"; do
# Query DynamoDB for items with the specified pk
ITEMS=$(aws dynamodb query \
--table-name "$DYNAMODB_TABLE" \
--key-condition-expression "pk = :pk" \
--expression-attribute-values '{":pk": {"S": "'"$PK"'"}}' \
--projection-expression "pk, sk" \
--output json | jq -c '.Items[]')

# Loop through the found items and delete them
echo "$ITEMS" | while read -r item; do
pk=$(echo "$item" | jq -r '.pk.S')
sk=$(echo "$item" | jq -r '.sk.S')

# Skip if pk or sk is empty
if [[ -z "$pk" || -z "$sk" ]]; then
continue
fi

# Delete the record
aws dynamodb delete-item \
--table-name "$DYNAMODB_TABLE" \
--key "{\"pk\": {\"S\": \"$pk\"}, \"sk\": {\"S\": \"$sk\"}}"

echo "Deleted record with pk: $pk and sk: $sk"
((DELETED_COUNT++))
done
done

# Output the total number of deleted items
echo "Total number of deleted items: $DELETED_COUNT"
Loading

0 comments on commit fd1923d

Please sign in to comment.