Skip to content

Manual DNS Cleanup

Manual DNS Cleanup #1

name: "Manual DNS Cleanup"
on:
workflow_dispatch
jobs:
Update-Wildcard-Cert:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v4"
- name: "Run Cleanup via Bash"
shell: "bash"
run: |
date=$(date)
authemail="${{ secrets.LF_DNS_AUTH_EMAIL }}"
apitoken="${{ secrets.LF_DNS_API }}"
#Get DNS Record IDs
DNSIDs=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/08be24924fc30f320e7329020986bad2/dns_records" -H "X-Auth-Email: $authemail" -H "Authorization: Bearer $apitoken" -H "Content-Type: application/json" | jq -r '.result[] | .id')
printf "\nFound $(echo -n "$DNSIDs" | grep -c '^') IDs to process\n"
for id in $DNSIDs
do
#printf "\nChecking DNS Record with ID:$id\n"
DNSRecord=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/08be24924fc30f320e7329020986bad2/dns_records/$id" -H "X-Auth-Email: $authemail" -H "Authorization: Bearer $apitoken" -H "Content-Type: application/json")
DNSContent=$(echo $DNSRecord | jq -r '.result | .content')
#Logic for Naming Convention goes here. We want to leave our other DNS records alone. Crazy {^^} converts to upper. It's a happy thing.
if [[ "${DNSContent}" == *".instruqt.io"* ]]; then
#printf "Record Matches Training Naming Convention\n"
DNSDateExp=$(date -d "$(echo $DNSRecord | jq -r '.result | .created_on')+7days")
#printf "DNS Name:$DNSContent \nDNS Expiry Date:$DNSDateExp\nCurrent Date:$date"
#Compare Dates
if [ $(date -d "$date" +%s) -gt $(date -d "$DNSDateExp" +%s) ]; then
printf "\nRecord $DNSContent is older than 7 days. Deleting record.\n"
DeleteRecord=$(curl -s -X DELETE "https://api.cloudflare.com/client/v4/zones/08be24924fc30f320e7329020986bad2/dns_records/$id" -H "X-Auth-Email: $authemail" -H "Authorization: Bearer $apitoken" -H "Content-Type: application/json")
fi
fi
done