diff --git a/utils/checkRecords.js b/utils/checkRecords.js index 548523b..a9dc68a 100644 --- a/utils/checkRecords.js +++ b/utils/checkRecords.js @@ -2,13 +2,16 @@ const { checkIfValidIP, checkIfValidFQDN, checkInvalidDomain } = require('./uti function checkRecords(data) { const recordType = Object.keys(data.target)[0]; - + + // Check if the domain is invalid if (checkInvalidDomain(data.target[recordType].name) === true) return false; - + + // Check A record if (recordType.toLowerCase() === 'a') { return checkIfValidIP(data.target[recordType].value); } + // Check CNAME record if (recordType.toLowerCase() === 'cname') { return checkIfValidFQDN(data.target[recordType].value); } diff --git a/utils/utils.js b/utils/utils.js index f9a6879..79b4c22 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -3,20 +3,20 @@ const fs = require('fs'); const core = require('@actions/core'); function getFiles(path) { - //get all files in path, returns arr + // Get all files in path: returns array const allFiles = fs.readdirSync(path); - return allFiles + return allFiles; } function getFileExtension(filename) { - //get file ext + // Get file extension return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename) : undefined; } function stripExt(filename) { - //remove file ext - return filename.substr(0, filename.lastIndexOf('.')) + // Remove file extension + return filename.substr(0, filename.lastIndexOf('.')); } function checkIfValidIP(str) { @@ -34,17 +34,20 @@ function checkIfValidFQDN(str) { } function checkInvalidDomain(str) { - //check invalid domains + // Check invalid domains if (invalidDomains.includes(str)) { - core.setOutput("recordInfo", "This subdomain has been blocked for register by the is-a-good.dev team.") + core.setOutput("recordInfo", "This subdomain has been blocked.") return true; } - //check reserved domains + + // Check reserved domains const files = getFiles("./reserved/").map(file => stripExt(file)); + if (files.includes(str)) { core.setOutput("recordInfo", "This subdomain has been reserved by the is-a-good.dev team.") return true; } + return false; }