Skip to content

Commit

Permalink
Messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
wilson1000 committed Oct 15, 2024
1 parent a6d0236 commit c7423aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 12 additions & 5 deletions bin/local-key-gen-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
ACTION_TRACKER="/tmp/intranet_action_tracker"
FILE_PRIVATE="/tmp/intranet_private_key.pem"
FILE_PUBLIC="/tmp/intranet_public_key.pem"
touch $ACTION_TRACKER

ENV_FILE=".env"
FILE_OUTPUT="/tmp/intranet_secrets_string"

# Create outputs files
touch $FILE_OUTPUT
{
echo -e "\n# # # # # # # # # # # # # # # # # #"
echo "# --> auto-gen secrets keys <-- #"
echo "# # # # # # # # # # # # # # # # # #"
} > $FILE_OUTPUT

env_var_exists(){
VAR=$(< "$ENV_FILE" grep -w "$1")
Expand All @@ -18,6 +28,7 @@ env_var_exists(){
fi
}

touch $ACTION_TRACKER
action_track(){
TRACKER_SIZE=$(sed -n '$=' "$ACTION_TRACKER")
if [[ "$TRACKER_SIZE" -gt 1 ]] ; then
Expand Down Expand Up @@ -68,12 +79,8 @@ clean_up(){
unset AWS_CLOUDFRONT_PUBLIC_KEY
unset AWS_CLOUDFRONT_PUBLIC_KEY_SHORT_HASH

[[ "$1" != "quiet" ]] && echo "Deleting temporary files"

[[ -f "$ACTION_TRACKER" ]] && rm "$ACTION_TRACKER"
[[ -f "$FILE_PRIVATE" ]] && rm "$FILE_PRIVATE"
[[ -f "$FILE_PUBLIC" ]] && rm "$FILE_PUBLIC"
[[ -f "$FILE_OUTPUT" ]] && rm "$FILE_OUTPUT"
}


17 changes: 4 additions & 13 deletions bin/local-key-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,23 @@
# The script follows the instructions from the AWS 'Creating key pairs for your signers' documentation:
# https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs

echo "Key Generation: detection..."
source bin/local-key-gen-functions.sh

ENV_FILE=".env"
FILE_OUTPUT="/tmp/intranet_secrets_string"

# Create outputs file
touch $FILE_OUTPUT
{
echo -e "\n# # # # # # # # # # # # # # # # # #"
echo "# --> auto-gen secrets keys <-- #"
echo "# # # # # # # # # # # # # # # # # #"
} > $FILE_OUTPUT

[[ "$(env_var_exists JWT_SECRET)" == "0" ]] && make_secret JWT
[[ "$(env_var_exists AWS_CLOUDFRONT_PRIVATE_KEY)" == "0" ]] && make_secret PRIVATE_KEY
[[ "$(env_var_exists AWS_CLOUDFRONT_PUBLIC_KEY)" == "0" ]] && make_secret PUBLIC_KEY
[[ "$(env_var_exists AWS_CLOUDFRONT_PUBLIC_KEYS_OBJECT)" == "0" ]] && make_secret PUBLIC_KEYS_OBJECT

if [[ "$(action_track)" == "0" ]]; then
echo "No new secrets were created."
echo "Key Generation: no new keys were created."
clean_up quiet
exit 0
fi

# Append secrets to the .env file
cat $FILE_OUTPUT >> $ENV_FILE
cat "$FILE_OUTPUT" >> "$ENV_FILE"
echo "Key Generation: new keys were created."

# Clear the variables.
clean_up

0 comments on commit c7423aa

Please sign in to comment.