From 506b8f6a3250770a7e463664aef1b17d8cfd6436 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Tue, 2 May 2023 18:15:12 +0200 Subject: [PATCH] improve CI privacy features --- cf_gateway_rule_create.js | 2 +- cf_gateway_rule_delete.js | 2 +- cf_list_create.js | 8 ++++---- cf_list_delete.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cf_gateway_rule_create.js b/cf_gateway_rule_create.js index c25ff17..9b70f75 100644 --- a/cf_gateway_rule_create.js +++ b/cf_gateway_rule_create.js @@ -37,7 +37,7 @@ async function getZeroTrustLists() { wirefilter_expression = wirefilter_expression.slice(0, -4); } wirefilter_expression = wirefilter_expression.trim().replace('\n', ''); - console.log(`Firewall expression contains ${wirefilter_expression.length} characters, and checks against ${filtered_lists.length} filter lists.`) + if (!process.env.CI) console.log(`Firewall expression contains ${wirefilter_expression.length} characters, and checks against ${filtered_lists.length} filter lists.`) const resp = await axios.request({ method: 'POST', diff --git a/cf_gateway_rule_delete.js b/cf_gateway_rule_delete.js index 88fd09e..f41813d 100644 --- a/cf_gateway_rule_delete.js +++ b/cf_gateway_rule_delete.js @@ -28,7 +28,7 @@ async function getZeroTrustRules() { if (!filtered_rule) return console.warn("No rule with matching name found - this is not an issue if you haven't run the create script yet. Exiting."); - console.log(`Deleting rule ` + process.env.CI ? "(redacted, running in CI)" : `${filtered_rule.name} with ID ${filtered_rule.id}`); + console.log(`Deleting rule`, process.env.CI ? "(redacted, running in CI)" : `${filtered_rule.name} with ID ${filtered_rule.id}`); const resp = await axios.request({ method: 'DELETE', diff --git a/cf_list_create.js b/cf_list_create.js index f8d71cb..64535e6 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -7,7 +7,7 @@ const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID; const ACCOUNT_EMAIL = process.env.CLOUDFLARE_ACCOUNT_EMAIL; const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT)) ? Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT) : 300000; -console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); +if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); // Read input.csv and parse domains fs.readFile('input.csv', 'utf8', async (err, data) => { @@ -56,7 +56,7 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { const listsToCreate = Math.ceil(domains.length / 1000); - console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`); + if (!process.env.CI) console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`); // Separate domains into chunks of 1000 (Cloudflare list cap) const chunks = chunkArray(domains, 1000); @@ -75,7 +75,7 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { await createZeroTrustList(listName, properList, (index+1), listsToCreate); await sleep(350); // Sleep for 350ms between list additions } catch (error) { - console.error(`Error creating list ` + process.env.CI ? "(redacted on CI)" : `"${listName}": ${error.response.data}`); + console.error(`Error creating list `, process.env.CI ? "(redacted on CI)" : `"${listName}": ${error.response.data}`); } } }); @@ -119,7 +119,7 @@ async function createZeroTrustList(name, items, currentItem, totalItems) { ); const listId = response.data.result.id; - console.log(`Created Zero Trust list ` + process.env.CI ? "(redacted on CI)" : `"${name}" with ID ${listId} - ${totalItems - currentItem} left`); + console.log(`Created Zero Trust list`, process.env.CI ? "(redacted on CI)" : `"${name}" with ID ${listId} - ${totalItems - currentItem} left`); } function percentage(percent, total) { diff --git a/cf_list_delete.js b/cf_list_delete.js index a99d7bb..18c93de 100644 --- a/cf_list_delete.js +++ b/cf_list_delete.js @@ -28,10 +28,10 @@ async function getZeroTrustLists() { const cgps_lists = lists.filter(list => list.name.startsWith('CGPS List')); if (!cgps_lists.length) return console.warn("No lists with matching name found - this is not an issue if you haven't created any filter lists before. Exiting."); - console.log(`Got ${lists.length} lists, ${cgps_lists.length} of which are CGPS lists that will be deleted.`); + if (!process.env.CI) console.log(`Got ${lists.length} lists, ${cgps_lists.length} of which are CGPS lists that will be deleted.`); for (const list of cgps_lists) { - console.log(`Deleting list ` + process.env.CI ? "(redacted, running in CI)" : `${list.name} with ID ${list.id}`); + console.log(`Deleting list`, process.env.CI ? "(redacted, running in CI)" : `${list.name} with ID ${list.id}`); const resp = await axios.request({ method: 'DELETE', url: `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/gateway/lists/${list.id}`,