From 797fb0372cadb7477f6fe25582aea618d8acbe60 Mon Sep 17 00:00:00 2001 From: chenbishop Date: Tue, 2 Jan 2024 19:10:40 +0000 Subject: [PATCH] Adding more functionality relating to security policy --- cliCmd/exportCmd.mjs | 2 ++ cliCmd/importCmd.mjs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cliCmd/exportCmd.mjs b/cliCmd/exportCmd.mjs index 6f3c3e3..b146431 100644 --- a/cliCmd/exportCmd.mjs +++ b/cliCmd/exportCmd.mjs @@ -231,6 +231,7 @@ export const exportCmd = new Command() .option("-n, --remote-networks [boolean]", "Include Remote Networks") .option("-r, --resources [boolean]", "Include Resources") .option("-g, --groups [boolean]", "Include Groups") + .option("-p, --security-policies [boolean]", "Include Security Policies") .option("-u, --users [boolean]", "Include Users") .option("-d, --devices [boolean]", "Include Devices (trust)") .description("Export from account to various formats") @@ -244,6 +245,7 @@ export const exportCmd = new Command() if ( options.groups === true ) options.typesToFetch.push("Group") if ( options.users === true ) options.typesToFetch.push("User") if ( options.devices === true ) options.typesToFetch.push("Device") + if ( options.securityPolicies === true ) options.typesToFetch.push("SecurityPolicy") let outputFn = outputFnMap[options.format]; if (outputFn == null) { diff --git a/cliCmd/importCmd.mjs b/cliCmd/importCmd.mjs index bfd3a97..409daa4 100644 --- a/cliCmd/importCmd.mjs +++ b/cliCmd/importCmd.mjs @@ -64,11 +64,13 @@ async function fetchDataForImport(client, options, wb) { // If we're importing resources we prob need Groups and Remote Networks too if ( !typesToFetch.includes("Group") ) typesToFetch.push("Group"); if ( !typesToFetch.includes("RemoteNetwork") ) typesToFetch.push("RemoteNetwork"); + if ( !typesToFetch.includes("SecurityPolicy") ) typesToFetch.push("SecurityPolicy"); } else if ( typesToFetch.includes("Group") ) { // note 'else' is intentional // If we're importing groups we prob need Resources and Users too if ( !typesToFetch.includes("Resource") ) typesToFetch.push("Resource"); if ( !typesToFetch.includes("User") ) typesToFetch.push("User"); + if ( !typesToFetch.includes("SecurityPolicy") ) typesToFetch.push("SecurityPolicy"); } const allNodes = await client.fetchAll({ @@ -148,6 +150,7 @@ export const importCmd = new Command() .option("-g, --groups [boolean]", "Include Groups") //.option("-u, --users [boolean]", "Include Users") .option("-d, --devices [boolean]", "Include Devices (trust)") + .option("-p, --security-policies [boolean]", "Include Security Policies") .option("-s, --sync [boolean]", "Attempt to synchronise entities with the same natural identifier") .option("-y, --assume-yes [boolean]", "Automatic yes to prompts; assume 'yes' as answer to all prompts") .description("Import from excel file to a Twingate account") @@ -494,6 +497,23 @@ export const importCmd = new Command() importCount++; } break; + case "SecurityPolicy": + for ( let securityPolicyRow of sheetData) { + // 1. Check if network exists + let existingId = nodeLabelIdMap.SecurityPolicy[securityPolicyRow.name]; + if ( existingId != null ) { + Log.info(`Security Policy with same name already exists, will skip: '${securityPolicyRow.name}'`); + securityPolicyRow["importAction"] = ImportAction.IGNORE; + securityPolicyRow["importId"] = existingId; + continue; + } + + Log.info(`Remote Network will be created: '${securityPolicyRow.name}'`); + securityPolicyRow["importAction"] = ImportAction.CREATE; + securityPolicyRow["importId"] = null; + importCount++; + } + break; default: // NoOp break;