Skip to content

Commit

Permalink
added logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit267 committed Jan 17, 2024
1 parent 691c4f1 commit 7b5e759
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ node_modules
pnpm-lock.yaml
yarn.lock
package-lock.json

config.json
.env
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async function getRecord(zoneIdentifier, recordName, v = "A") {
}
return response.data.result[0];
} catch (error) {
console.error("Failed to get record", error);
console.error("Failed to get record", error.message);
console.error(JSON.stringify(error?.response?.data, null, 2));
return null;
}
}
Expand Down Expand Up @@ -75,7 +76,8 @@ async function updateRecord(
);
return true;
} catch (error) {
console.error("Failed to update record", error);
console.error("Failed to update record", error.message);
console.error(JSON.stringify(error?.response?.data, null, 2));
return false;
}
}
Expand All @@ -86,21 +88,30 @@ async function startUpdate() {

for (let i = 0; i < records.length; i++) {
const { name, proxied, type, zoneId } = records[i];
console.log("Updating record", name);

console.log("Fetching public IP...");
const ip = await getPublicIp(type == "AAAA" ? 6 : 4);
if (!ip) {
console.error("Failed to get public IP");
continue;
}
console.log("Public IP is", ip);

console.log("Fetching record...");
const recordData = await getRecord(zoneId, name, type);
if (!recordData) {
console.error("Failed to get record for record", name);
continue;
}
console.log("Record IP is", recordData.content);
if (recordData.content == ip) {
console.log("IP has not changed for record", name);
continue;
}
console.log("IP has changed for record", name);

console.log("Updating record...");
const result = await updateRecord(zoneId, recordData.id, ip, proxied);
if (!result) {
console.error("Failed to update record for record", records[i]);
Expand Down

0 comments on commit 7b5e759

Please sign in to comment.