Skip to content

Commit

Permalink
Adding more functionality relating to security policy
Browse files Browse the repository at this point in the history
  • Loading branch information
chenbishop committed Jan 2, 2024
1 parent 0419015 commit 797fb03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cliCmd/exportCmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions cliCmd/importCmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 797fb03

Please sign in to comment.