Skip to content

Instantly share code, notes, and snippets.

@corkupine
Last active March 7, 2024 21:08
Show Gist options
  • Save corkupine/e77924195c8bd394ede9bd68b8dd0588 to your computer and use it in GitHub Desktop.
Save corkupine/e77924195c8bd394ede9bd68b8dd0588 to your computer and use it in GitHub Desktop.
Updating ETE tenant config with Cloudflare DNS record IDs
#Get cloudflare dns record IDs for cnames in zescrow.com - redirect to a file
API_KEY="xxxxxxxxxxxxxxxxxx"
ZONE_ID="xxxxxxxxxxxxxxxxxx"
API_URL="https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?type=CNAME"
#Change page as necessary
curl -s -X GET "${API_URL}&page=4" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json"
# Process the files that we got from above
# Path to the main JSON file
mainJson="cname4.json"
# Directory containing the folders
baseDir="./"
# Iterate over each folder in the base directory
for folder in "$baseDir"/*; do
if [ -d "$folder" ]; then
# Extract the folder name
folderName=$(basename "$folder")
# Attempt to find a matching result in the main JSON file
# Adjusting the match to include "-mydomain.com"
match=$(jq -r --arg name "$folderName-mydomain.com" '.result[] | select(.name==$name) | @base64' "$mainJson")
if [ ! -z "$match" ]; then
# Decode the base64-encoded JSON to extract the id
id=$(echo "$match" | base64 --decode | jq -r '.id')
configFile="$folder/config.json"
if [ -f "$configFile" ]; then
# Add the id to the options object in the config.json file
jq --arg id "$id" '.options.CNAME_RECORD_ID = $id' "$configFile" > "$folder/temp.json" && mv "$folder/temp.json" "$configFile"
echo "Updated $configFile with id $id"
else
echo "Config file not found in $folder"
fi
else
echo "No matching result found for folder $folderName"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment