Skip to content
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

Fix script for requesting phone number on staging / production #1551

Merged
merged 9 commits into from
Oct 1, 2024

Conversation

sastels
Copy link
Contributor

@sastels sastels commented Sep 23, 2024

Summary | Résumé

Need to tweak the request_long_codes.sh script because on staging and production we have custom keywords for the pools. :/

Fixing this simplifies the code substantially though 🎉

Also cleaned up the drain script slightly and incorporated some AI suggestions! 🤖

Related Issues | Cartes liées

Before merging this PR

Read code suggestions left by the
cds-ai-codereviewer bot. Address
valid suggestions and shortly write down reasons to not address others. To help
with the classification of the comments, please use these reactions on each of the
comments made by the AI review:

Classification Reaction Emoticon
Useful +1 👍
Noisy eyes 👀
Hallucination confused 😕
Wrong but teachable rocket 🚀
Wrong and incorrect -1 👎

The classifications will be extracted and summarized into an analysis of how helpful
or not the AI code review really is.

Test instructions | Instructions pour tester la modification

Add some numbers to staging and production.
(Note: currently we are at the limit of numbers on staging so the script will fail. Delete a few and then try)

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

@@ -17,7 +17,7 @@ printf " WARNING!!!!\n"
printf " This will delete all but one long code from a Pinpoint pool!\n"
printf " You do not want to run this or production!\n"
printf "\n------------------------------------------------------------\n"
printf "Are you sure you want to continue?"
printf "Are you sure you want to continue?\n"
echo -n "If so, type 'drain'> "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using read -p to combine the prompt and read into a single line for better readability:

read -p "If so, type 'drain'> " check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one is nice, if true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is definitely where the AI review is useful!

Slightly odd that it didn't flag the same code in the other file

@@ -26,15 +26,15 @@ if [ "$check" != "drain" ]; then
exit 1
fi

if aws pinpoint-sms-voice-v2 describe-pools --pool-ids $1; then
if aws pinpoint-sms-voice-v2 describe-pools --pool-ids $1 > /dev/null 2>&1; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirecting both stdout and stderr to /dev/null can make debugging difficult if something goes wrong. Consider logging errors to a file or displaying them conditionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of that but figured 🤷 but tbh I just want to hide the output when it's successful, so we can do that (but not hide the errors) by getting rid of the 2>&1.

numbers=$(aws pinpoint-sms-voice-v2 list-pool-origination-identities --pool-id $1 | jq -r ".OriginationIdentities[].OriginationIdentity")
read -ra numbersArray <<< $numbers # Split the string into an array

echo "Found ${#numbersArray[@]} numbers in pool $1. Releasing all but one."
for number in ${numbersArray[@]:1}; do # Skip the first number - have to keep at least one number in the pool
echo "Releasing $number..."
aws pinpoint-sms-voice-v2 disassociate-origination-identity --iso-country-code CA --pool-id $1 --origination-identity $number
aws pinpoint-sms-voice-v2 release-phone-number --phone-number-id $number
aws pinpoint-sms-voice-v2 disassociate-origination-identity --iso-country-code CA --pool-id $1 --origination-identity $number > /dev/null 2>&1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirecting both stdout and stderr to /dev/null can make debugging difficult if something goes wrong. Consider logging errors to a file or displaying them conditionally.

aws pinpoint-sms-voice-v2 disassociate-origination-identity --iso-country-code CA --pool-id $1 --origination-identity $number
aws pinpoint-sms-voice-v2 release-phone-number --phone-number-id $number
aws pinpoint-sms-voice-v2 disassociate-origination-identity --iso-country-code CA --pool-id $1 --origination-identity $number > /dev/null 2>&1
aws pinpoint-sms-voice-v2 release-phone-number --phone-number-id $number > /dev/null 2>&1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirecting both stdout and stderr to /dev/null can make debugging difficult if something goes wrong. Consider logging errors to a file or displaying them conditionally.

echo "Pool $2 does not exist"
exit 1
fi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for the existence of the pool has been removed. This might lead to issues if the pool ID provided does not exist. Consider re-adding the validation for the pool ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I moved it below but commented it out and forgot to uncomment.

printf "\n------------------------------------------------------------\n"
printf " WARNING!!!!\n"
printf " This will add new phone numbers to a Pinpoint pool\n"
printf " You might not want to run this in production!\n"
printf "\n------------------------------------------------------------\n"
printf "Are you sure you want to continue?"
printf "Are you sure you want to continue?\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newline character \n added at the end of the printf statement is a good change for formatting. Ensure that this change is consistent across all similar printf statements in the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is consistent...

@@ -41,24 +37,17 @@ if [ "$check" != "request" ]; then
exit 1
fi

# if ! aws pinpoint-sms-voice-v2 describe-pools --pool-ids $poolId > /dev/null 2>&1; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code if it is no longer needed. Keeping commented-out code can clutter the script and reduce readability.

--pool-id $poolId \
--origination-identity $number \
--iso-country-code CA
echo "Requested $number"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a check to ensure that the phone number request was successful before printing the requested number. This can help in identifying issues early if the request fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a good idea.

@sastels sastels marked this pull request as ready for review September 25, 2024 15:50
@sastels sastels requested a review from jimleroyer September 25, 2024 15:50
@sastels sastels requested a review from a team October 1, 2024 18:11
Copy link
Contributor

@ben851 ben851 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sastels sastels merged commit a13c4c9 into main Oct 1, 2024
3 checks passed
@sastels sastels deleted the tweak-longcode-scripts branch October 1, 2024 20:10
@P0NDER0SA P0NDER0SA mentioned this pull request Oct 7, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants