@rockcarver/frodo-cli 2.0.0-37 → 2.0.0-39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/esm/cli/_template/something-else-export.js +1 -1
- package/esm/cli/_template/something-else-export.js.map +1 -1
- package/esm/cli/_template/something-export.js +1 -1
- package/esm/cli/_template/something-export.js.map +1 -1
- package/esm/cli/_template/something-other-export.js +1 -1
- package/esm/cli/_template/something-other-export.js.map +1 -1
- package/esm/cli/admin/admin-federation-export.js +4 -4
- package/esm/cli/admin/admin-federation-export.js.map +1 -1
- package/esm/cli/agent/agent-export.js +4 -4
- package/esm/cli/agent/agent-export.js.map +1 -1
- package/esm/cli/agent/agent-gateway-export.js +4 -4
- package/esm/cli/agent/agent-gateway-export.js.map +1 -1
- package/esm/cli/agent/agent-java-export.js +4 -4
- package/esm/cli/agent/agent-java-export.js.map +1 -1
- package/esm/cli/agent/agent-web-export.js +4 -4
- package/esm/cli/agent/agent-web-export.js.map +1 -1
- package/esm/cli/app/app-export.js +4 -4
- package/esm/cli/app/app-export.js.map +1 -1
- package/esm/cli/authn/authn-export.js +2 -2
- package/esm/cli/authn/authn-export.js.map +1 -1
- package/esm/cli/authz/authz-policy-export.js +6 -6
- package/esm/cli/authz/authz-policy-export.js.map +1 -1
- package/esm/cli/authz/authz-set-export.js +4 -4
- package/esm/cli/authz/authz-set-export.js.map +1 -1
- package/esm/cli/authz/authz-type-export.js +5 -5
- package/esm/cli/authz/authz-type-export.js.map +1 -1
- package/esm/cli/config/config-export.js +3 -3
- package/esm/cli/config/config-export.js.map +1 -1
- package/esm/cli/email/email-template-export.js +4 -4
- package/esm/cli/email/email-template-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-export.js +4 -4
- package/esm/cli/esv/esv-secret-export.js.map +1 -1
- package/esm/cli/esv/esv-secret-list.js +2 -2
- package/esm/cli/esv/esv-secret-list.js.map +1 -1
- package/esm/cli/esv/esv-variable-export.js +4 -4
- package/esm/cli/esv/esv-variable-export.js.map +1 -1
- package/esm/cli/esv/esv-variable-list.js +2 -2
- package/esm/cli/esv/esv-variable-list.js.map +1 -1
- package/esm/cli/idp/idp-export.js +4 -4
- package/esm/cli/idp/idp-export.js.map +1 -1
- package/esm/cli/journey/journey-describe.js +3 -1
- package/esm/cli/journey/journey-describe.js.map +1 -1
- package/esm/cli/journey/journey-export.js +4 -4
- package/esm/cli/journey/journey-export.js.map +1 -1
- package/esm/cli/oauth/oauth-client-export.js +4 -4
- package/esm/cli/oauth/oauth-client-export.js.map +1 -1
- package/esm/cli/saml/saml-cot-export.js +4 -4
- package/esm/cli/saml/saml-cot-export.js.map +1 -1
- package/esm/cli/saml/saml-export.js +4 -4
- package/esm/cli/saml/saml-export.js.map +1 -1
- package/esm/cli/script/script-export.js +4 -4
- package/esm/cli/script/script-export.js.map +1 -1
- package/esm/cli/script/script-list.js +2 -2
- package/esm/cli/script/script-list.js.map +1 -1
- package/esm/cli/service/service-export.js +4 -4
- package/esm/cli/service/service-export.js.map +1 -1
- package/esm/cli/theme/theme-export.js +5 -5
- package/esm/cli/theme/theme-export.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +11 -7
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AgentOps.js +39 -25
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +11 -8
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/AuthenticationSettingsOps.js +4 -3
- package/esm/ops/AuthenticationSettingsOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +12 -7
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/ConfigOps.js +9 -7
- package/esm/ops/ConfigOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +11 -7
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +3 -2
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +14 -7
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +15 -6
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +10 -7
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +18 -11
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +12 -7
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +15 -9
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +10 -7
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +73 -36
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/SecretsOps.js +76 -48
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ServiceOps.js +10 -9
- package/esm/ops/ServiceOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +15 -9
- package/esm/ops/ThemeOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +49 -23
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/Config.js +147 -1
- package/esm/utils/Config.js.map +1 -1
- package/package.json +2 -2
- package/esm/utils/ExportImportUtils.js +0 -48
- package/esm/utils/ExportImportUtils.js.map +0 -1
package/esm/ops/PolicyOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolicyOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getTypedFilename","saveJsonToFile","titleCase","getRealmName","getFilePath","getWorkingDirectory","utils","readPolicies","readPoliciesByPolicySet","readPolicy","exportPolicy","exportPolicies","exportPoliciesByPolicySet","importPolicy","importFirstPolicy","importPolicies","deletePolicy","authz","policy","listPolicies","long","outcome","policies","sort","a","b","_id","localeCompare","table","push","description","active","toString","err","message","listPoliciesByPolicySet","policySetId","describePolicy","policyId","json","policySet","deletePolicyById","error","deletePolicies","errors","indicatorId","length","errorMessages","map","join","deletePoliciesByPolicySet","exportPolicyToFile","file","options","deps","prereqs","useStringArrays","fileName","filePath","exportData","exportPoliciesToFile","getRealm","exportPoliciesByPolicySetToFile","exportPoliciesToFiles","exportPoliciesByPolicySetToFiles","importPolicyFromFile","data","readFileSync","fileData","JSON","parse","importFirstPolicyFromFile","importPoliciesFromFile","policySetName","importPoliciesFromFiles","names","readdirSync","files","filter","name","toLowerCase","endsWith","total","count","Object","keys","policyset"],"sources":["../../src/ops/PolicyOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type PolicySkeleton } from '@rockcarver/frodo-lib/types/api/PoliciesApi';\nimport type {\n PolicyExportInterface,\n PolicyExportOptions,\n PolicyImportOptions,\n} from '@rockcarver/frodo-lib/types/ops/PolicyOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmName, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n readPolicies,\n readPoliciesByPolicySet,\n readPolicy,\n exportPolicy,\n exportPolicies,\n exportPoliciesByPolicySet,\n importPolicy,\n importFirstPolicy,\n importPolicies,\n deletePolicy,\n} = frodo.authz.policy;\n\n/**\n * List policies\n * @param {boolean} long list with details\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPolicies(long = false): Promise<boolean> {\n let outcome = false;\n try {\n const policies = await readPolicies();\n policies.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Id', 'Description', 'Status']);\n for (const policy of policies) {\n table.push([\n `${policy._id}`,\n `${policy.description}`,\n policy.active ? 'active'['brightGreen'] : 'inactive'['brightRed'],\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const policy of policies) {\n printMessage(`${policy._id}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicies ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * List policies by policy set\n * @param {string} policySetId policy set id/name\n * @param {boolean} long list with details\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPoliciesByPolicySet(\n policySetId: string,\n long = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const policies = await readPoliciesByPolicySet(policySetId);\n policies.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Id', 'Description', 'Status']);\n for (const policy of policies) {\n table.push([\n `${policy._id}`,\n `${policy.description}`,\n policy.active ? 'active'['brightGreen'] : 'inactive'['brightRed'],\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const policy of policies) {\n printMessage(`${policy._id}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicies ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe policy\n * @param {string} policyId policy id/name\n * @param {Object} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describePolicy(\n policyId: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n const policySet = await readPolicy(policyId);\n outcome = true;\n if (json) {\n printMessage(policySet, 'data');\n } else {\n const table = createObjectTable(policySet);\n printMessage(table.toString(), 'data');\n }\n return outcome;\n}\n\n/**\n * Delete policy\n * @param {string} policyId policy id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicyById(policyId: string): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePolicy: begin`);\n showSpinner(`Deleting ${policyId}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n succeedSpinner(`Deleted ${policyId}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error deleting policy ${policyId}: ${error}`);\n }\n debugMessage(`cli.PolicyOps.deletePolicy: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policies\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicies(): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePolicies: begin`);\n let outcome = false;\n const errors = [];\n let policies: PolicySkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all policies...`);\n try {\n policies = await readPolicies();\n succeedSpinner(`Found ${policies.length} policies.`);\n } catch (error) {\n error.message = `Error retrieving all policies: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (policies.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Deleting ${policies.length} policies...`\n );\n for (const policy of policies) {\n const policyId = policy._id;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n updateProgressIndicator(indicatorId, `Deleted ${policyId}`);\n } catch (error) {\n error.message = `Error deleting policy ${policyId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policies: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all policies: ${errorMessages}`\n );\n } else {\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${policies.length} policies.`\n );\n outcome = true;\n }\n }\n debugMessage(`cli.PolicyOps.deletePolicies: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policies in policy set\n * @param {string} policySetId policy set id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePoliciesByPolicySet(\n policySetId: string\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePoliciesByPolicySet: begin`);\n let outcome = false;\n const errors = [];\n let policies: PolicySkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all policies from policy set ${policySetId}...`);\n try {\n policies = await readPoliciesByPolicySet(policySetId);\n succeedSpinner(\n `Found ${policies.length} policies in policy set ${policySetId}.`\n );\n } catch (error) {\n error.message = `Error retrieving all policies from policy set ${policySetId}: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (policies.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Deleting ${policies.length} policies from policy set ${policySetId}...`\n );\n for (const policy of policies) {\n const policyId = policy._id;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n updateProgressIndicator(indicatorId, `Deleted ${policyId}`);\n } catch (error) {\n error.message = `Error deleting policy ${policyId} from policy set ${policySetId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policies from policy set ${policySetId}: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all policies from policy set ${policySetId}: ${errorMessages}`\n );\n } else {\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${policies.length} policies.`\n );\n outcome = true;\n }\n }\n debugMessage(\n `cli.PolicyOps.deletePoliciesByPolicySet: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Export policy to file\n * @param {string} policyId policy id/name\n * @param {string} file file name\n * @param {ApplicationExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicyToFile(\n policyId: string,\n file: string,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPolicyToFile: begin`);\n showSpinner(`Exporting ${policyId}...`);\n try {\n let fileName = getTypedFilename(policyId, 'policy.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicy(policyId, options);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported ${policyId} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${policyId}: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPolicyToFile: end`);\n return outcome;\n}\n\n/**\n * Export policies to file\n * @param {string} file file name\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesToFile(\n file: string,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: begin`);\n showSpinner(`Exporting all policy sets...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}Policies`,\n 'policy.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicies(options);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported all policy sets to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting policy sets: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: end`);\n return outcome;\n}\n\n/**\n * Export policies to file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesByPolicySetToFile(\n policySetId: string,\n file: string,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: begin`);\n showSpinner(`Exporting all policy sets...`);\n try {\n let fileName = getTypedFilename(\n `all${\n titleCase(getRealmName(state.getRealm())) + titleCase(policySetId)\n }Policies`,\n 'policy.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPoliciesByPolicySet(policySetId, options);\n saveJsonToFile(exportData, filePath);\n succeedSpinner(`Exported all policy sets to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting policy sets: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: end`);\n return outcome;\n}\n\n/**\n * Export all policies to separate files\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesToFiles(\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policies: PolicySkeleton[] = await readPolicies();\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n 'Exporting policy sets...'\n );\n for (const policy of policies) {\n const file = getTypedFilename(policy._id, 'policy.authz');\n try {\n const exportData: PolicyExportInterface = await exportPolicy(\n policy._id,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true));\n updateProgressIndicator(indicatorId, `Exported ${policy._id}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(indicatorId, `Error exporting ${policy._id}.`);\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Export all policies to separate files\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesByPolicySetToFiles(\n policySetId: string,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policies: PolicySkeleton[] =\n await readPoliciesByPolicySet(policySetId);\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Exporting policies in policy set ${policySetId}...`\n );\n for (const policy of policies) {\n const file = getTypedFilename(policy._id, 'policy.authz');\n try {\n const exportData: PolicyExportInterface = await exportPolicy(\n policy._id,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true));\n updateProgressIndicator(indicatorId, `Exported ${policy._id}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(indicatorId, `Error exporting ${policy._id}.`);\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import policy from file\n * @param {string} policyId policy id/name\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicyFromFile(\n policyId: string,\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.importPolicyFromFile: begin`);\n showSpinner(`Importing ${policyId}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importPolicy(policyId, fileData, options);\n outcome = true;\n succeedSpinner(`Imported ${policyId}.`);\n } catch (error) {\n failSpinner(`Error importing ${policyId}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPolicyFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first policy from file\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstPolicyFromFile(\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importFirstPolicyFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing first policy from ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const policy = await importFirstPolicy(fileData, options);\n outcome = true;\n succeedSpinner(\n `Imported first policy with id '${policy._id}' from ${filePath}.`\n );\n } catch (error) {\n failSpinner(`Error importing first policy from ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importFirstPolicyFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policies from file\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPoliciesFromFile(\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.importPoliciesFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importPolicies(fileData, options);\n outcome = true;\n succeedSpinner(\n `Imported ${filePath}${\n options.policySetName\n ? ' into policy set ' + options.policySetName\n : '.'\n }`\n );\n } catch (error) {\n failSpinner(\n `Error importing ${filePath}${\n options.policySetName\n ? ' into policy set ' + options.policySetName\n : '.'\n }`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPoliciesFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policies from files\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPoliciesFromFiles(\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.PolicyOps.importPoliciesFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.policy.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing policies...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: PolicyExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.policyset).length;\n total += count;\n await importPolicies(fileData, options);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} policies from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing policies from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} policies from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error importing policies from files.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPoliciesFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAOpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,SAAS,QACJ,4BAA4B;AAEnC,MAAM;EAAEC,YAAY;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACtE,MAAM;EACJC,YAAY;EACZC,uBAAuB;EACvBC,UAAU;EACVC,YAAY;EACZC,cAAc;EACdC,yBAAyB;EACzBC,YAAY;EACZC,iBAAiB;EACjBC,cAAc;EACdC;AACF,CAAC,GAAG7B,KAAK,CAAC8B,KAAK,CAACC,MAAM;;AAEtB;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,IAAI,GAAG,KAAK,EAAoB;EACjE,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAI;IACF,MAAMC,QAAQ,GAAG,MAAMf,YAAY,CAAC,CAAC;IACrCe,QAAQ,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,GAAG,CAACC,aAA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MAC9B;IACF;IACA7C,qBAAqB,CACnBgD,WAAW,EACV,sBAAqBqC,KAAM,kBAAiBL,KAAK,CAAC/B,MAAO,SAC5D,CAAC;EACH,CAAC,CAAC,OAAOJ,KAAK,EAAE;IACdE,MAAM,CAACf,IAAI,CAACa,KAAK,CAAC;IAClB7C,qBAAqB,CAACgD,WAAW,EAAG,sCAAqC,CAAC;IAC1ElD,YAAY,CAAC+C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACAjD,YAAY,CAAE,4CAA2C,CAAC;EAC1D,OAAO,CAAC,KAAKmD,MAAM,CAACE,MAAM;AAC5B"}
|
|
1
|
+
{"version":3,"file":"PolicyOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getRealmName","getTypedFilename","saveJsonToFile","titleCase","getFilePath","getWorkingDirectory","utils","readPolicies","readPoliciesByPolicySet","readPolicy","exportPolicy","exportPolicies","exportPoliciesByPolicySet","importPolicy","importFirstPolicy","importPolicies","deletePolicy","authz","policy","listPolicies","long","outcome","policies","sort","a","b","_id","localeCompare","table","push","description","active","toString","err","message","listPoliciesByPolicySet","policySetId","describePolicy","policyId","json","policySet","deletePolicyById","error","deletePolicies","errors","indicatorId","length","errorMessages","map","join","deletePoliciesByPolicySet","exportPolicyToFile","file","includeMeta","options","deps","prereqs","useStringArrays","fileName","filePath","exportData","exportPoliciesToFile","getRealm","exportPoliciesByPolicySetToFile","exportPoliciesToFiles","exportPoliciesByPolicySetToFiles","importPolicyFromFile","data","readFileSync","fileData","JSON","parse","importFirstPolicyFromFile","importPoliciesFromFile","policySetName","importPoliciesFromFiles","names","readdirSync","files","filter","name","toLowerCase","endsWith","total","count","Object","keys","policyset"],"sources":["../../src/ops/PolicyOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type PolicySkeleton } from '@rockcarver/frodo-lib/types/api/PoliciesApi';\nimport type {\n PolicyExportInterface,\n PolicyExportOptions,\n PolicyImportOptions,\n} from '@rockcarver/frodo-lib/types/ops/PolicyOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n getRealmName,\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst {\n readPolicies,\n readPoliciesByPolicySet,\n readPolicy,\n exportPolicy,\n exportPolicies,\n exportPoliciesByPolicySet,\n importPolicy,\n importFirstPolicy,\n importPolicies,\n deletePolicy,\n} = frodo.authz.policy;\n\n/**\n * List policies\n * @param {boolean} long list with details\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPolicies(long = false): Promise<boolean> {\n let outcome = false;\n try {\n const policies = await readPolicies();\n policies.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Id', 'Description', 'Status']);\n for (const policy of policies) {\n table.push([\n `${policy._id}`,\n `${policy.description}`,\n policy.active ? 'active'['brightGreen'] : 'inactive'['brightRed'],\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const policy of policies) {\n printMessage(`${policy._id}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicies ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * List policies by policy set\n * @param {string} policySetId policy set id/name\n * @param {boolean} long list with details\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPoliciesByPolicySet(\n policySetId: string,\n long = false\n): Promise<boolean> {\n let outcome = false;\n try {\n const policies = await readPoliciesByPolicySet(policySetId);\n policies.sort((a, b) => a._id.localeCompare(b._id));\n if (long) {\n const table = createTable(['Id', 'Description', 'Status']);\n for (const policy of policies) {\n table.push([\n `${policy._id}`,\n `${policy.description}`,\n policy.active ? 'active'['brightGreen'] : 'inactive'['brightRed'],\n ]);\n }\n printMessage(table.toString(), 'data');\n } else {\n for (const policy of policies) {\n printMessage(`${policy._id}`, 'data');\n }\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicies ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe policy\n * @param {string} policyId policy id/name\n * @param {Object} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describePolicy(\n policyId: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n const policySet = await readPolicy(policyId);\n outcome = true;\n if (json) {\n printMessage(policySet, 'data');\n } else {\n const table = createObjectTable(policySet);\n printMessage(table.toString(), 'data');\n }\n return outcome;\n}\n\n/**\n * Delete policy\n * @param {string} policyId policy id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicyById(policyId: string): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePolicy: begin`);\n showSpinner(`Deleting ${policyId}...`);\n let outcome = false;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n succeedSpinner(`Deleted ${policyId}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error deleting policy ${policyId}: ${error}`);\n }\n debugMessage(`cli.PolicyOps.deletePolicy: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policies\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicies(): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePolicies: begin`);\n let outcome = false;\n const errors = [];\n let policies: PolicySkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all policies...`);\n try {\n policies = await readPolicies();\n succeedSpinner(`Found ${policies.length} policies.`);\n } catch (error) {\n error.message = `Error retrieving all policies: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (policies.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Deleting ${policies.length} policies...`\n );\n for (const policy of policies) {\n const policyId = policy._id;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n updateProgressIndicator(indicatorId, `Deleted ${policyId}`);\n } catch (error) {\n error.message = `Error deleting policy ${policyId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policies: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all policies: ${errorMessages}`\n );\n } else {\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${policies.length} policies.`\n );\n outcome = true;\n }\n }\n debugMessage(`cli.PolicyOps.deletePolicies: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policies in policy set\n * @param {string} policySetId policy set id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePoliciesByPolicySet(\n policySetId: string\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.deletePoliciesByPolicySet: begin`);\n let outcome = false;\n const errors = [];\n let policies: PolicySkeleton[] = [];\n let indicatorId: string;\n try {\n showSpinner(`Retrieving all policies from policy set ${policySetId}...`);\n try {\n policies = await readPoliciesByPolicySet(policySetId);\n succeedSpinner(\n `Found ${policies.length} policies in policy set ${policySetId}.`\n );\n } catch (error) {\n error.message = `Error retrieving all policies from policy set ${policySetId}: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (policies.length)\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Deleting ${policies.length} policies from policy set ${policySetId}...`\n );\n for (const policy of policies) {\n const policyId = policy._id;\n try {\n debugMessage(`Deleting policy ${policyId}`);\n await deletePolicy(policyId);\n updateProgressIndicator(indicatorId, `Deleted ${policyId}`);\n } catch (error) {\n error.message = `Error deleting policy ${policyId} from policy set ${policySetId}: ${error}`;\n updateProgressIndicator(indicatorId, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policies from policy set ${policySetId}: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Error deleting all policies from policy set ${policySetId}: ${errorMessages}`\n );\n } else {\n if (policies.length)\n stopProgressIndicator(\n indicatorId,\n `Deleted ${policies.length} policies.`\n );\n outcome = true;\n }\n }\n debugMessage(\n `cli.PolicyOps.deletePoliciesByPolicySet: end [outcome=${outcome}]`\n );\n return outcome;\n}\n\n/**\n * Export policy to file\n * @param {string} policyId policy id/name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {ApplicationExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicyToFile(\n policyId: string,\n file: string,\n includeMeta = true,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPolicyToFile: begin`);\n showSpinner(`Exporting ${policyId}...`);\n try {\n let fileName = getTypedFilename(policyId, 'policy.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicy(policyId, options);\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported ${policyId} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${policyId}: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPolicyToFile: end`);\n return outcome;\n}\n\n/**\n * Export policies to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesToFile(\n file: string,\n includeMeta = true,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: begin`);\n showSpinner(`Exporting all policy sets...`);\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}Policies`,\n 'policy.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicies(options);\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported all policy sets to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting policy sets: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: end`);\n return outcome;\n}\n\n/**\n * Export policies to file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesByPolicySetToFile(\n policySetId: string,\n file: string,\n includeMeta = true,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: begin`);\n showSpinner(`Exporting all policy sets...`);\n try {\n let fileName = getTypedFilename(\n `all${\n titleCase(getRealmName(state.getRealm())) + titleCase(policySetId)\n }Policies`,\n 'policy.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPoliciesByPolicySet(policySetId, options);\n saveJsonToFile(exportData, filePath, includeMeta);\n succeedSpinner(`Exported all policy sets to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting policy sets: ${error.message}`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFile: end`);\n return outcome;\n}\n\n/**\n * Export all policies to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesToFiles(\n includeMeta = true,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policies: PolicySkeleton[] = await readPolicies();\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n 'Exporting policy sets...'\n );\n for (const policy of policies) {\n const file = getTypedFilename(policy._id, 'policy.authz');\n try {\n const exportData: PolicyExportInterface = await exportPolicy(\n policy._id,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true), includeMeta);\n updateProgressIndicator(indicatorId, `Exported ${policy._id}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(indicatorId, `Error exporting ${policy._id}.`);\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Export all policies to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicyExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPoliciesByPolicySetToFiles(\n policySetId: string,\n includeMeta = true,\n options: PolicyExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policies: PolicySkeleton[] =\n await readPoliciesByPolicySet(policySetId);\n indicatorId = createProgressIndicator(\n 'determinate',\n policies.length,\n `Exporting policies in policy set ${policySetId}...`\n );\n for (const policy of policies) {\n const file = getTypedFilename(policy._id, 'policy.authz');\n try {\n const exportData: PolicyExportInterface = await exportPolicy(\n policy._id,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true), includeMeta);\n updateProgressIndicator(indicatorId, `Exported ${policy._id}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(indicatorId, `Error exporting ${policy._id}.`);\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicyOps.exportPoliciesToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import policy from file\n * @param {string} policyId policy id/name\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicyFromFile(\n policyId: string,\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.importPolicyFromFile: begin`);\n showSpinner(`Importing ${policyId}...`);\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importPolicy(policyId, fileData, options);\n outcome = true;\n succeedSpinner(`Imported ${policyId}.`);\n } catch (error) {\n failSpinner(`Error importing ${policyId}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPolicyFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first policy from file\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstPolicyFromFile(\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importFirstPolicyFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing first policy from ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const policy = await importFirstPolicy(fileData, options);\n outcome = true;\n succeedSpinner(\n `Imported first policy with id '${policy._id}' from ${filePath}.`\n );\n } catch (error) {\n failSpinner(`Error importing first policy from ${filePath}.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importFirstPolicyFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policies from file\n * @param {string} file file name\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPoliciesFromFile(\n file: string,\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicyOps.importPoliciesFromFile: begin`);\n const filePath = getFilePath(file);\n showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importPolicies(fileData, options);\n outcome = true;\n succeedSpinner(\n `Imported ${filePath}${\n options.policySetName\n ? ' into policy set ' + options.policySetName\n : '.'\n }`\n );\n } catch (error) {\n failSpinner(\n `Error importing ${filePath}${\n options.policySetName\n ? ' into policy set ' + options.policySetName\n : '.'\n }`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPoliciesFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policies from files\n * @param {PolicyImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPoliciesFromFiles(\n options: PolicyImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.PolicyOps.importPoliciesFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.policy.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing policies...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: PolicyExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.policyset).length;\n total += count;\n await importPolicies(fileData, options);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} policies from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing policies from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} policies from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error importing policies from files.`);\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicyOps.importPoliciesFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAOpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AAEzB,MAAM;EACJC,YAAY;EACZC,gBAAgB;EAChBC,cAAc;EACdC,SAAS;EACTC,WAAW;EACXC;AACF,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACf,MAAM;EACJC,YAAY;EACZC,uBAAuB;EACvBC,UAAU;EACVC,YAAY;EACZC,cAAc;EACdC,yBAAyB;EACzBC,YAAY;EACZC,iBAAiB;EACjBC,cAAc;EACdC;AACF,CAAC,GAAG7B,KAAK,CAAC8B,KAAK,CAACC,MAAM;;AAEtB;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,IAAI,GAAG,KAAK,EAAoB;EACjE,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAI;IACF,MAAMC,QAAQ,GAAG,MAAMf,YAAY,CAAC,CAAC;IACrCe,QAAQ,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,GAAG,CAACC,aAAa,CAACF,CAAC,CAACC,GAAG,CAAC,CAAC;IACnD,IAAIN,IAAI,EAAE;MACR,MAAMQ,KAAK,GAAGpC,WAAW,CAAC,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;MAC1D,KAAK,MAAM0B,MAAM,IAAII,QAAQ,EAAE;QAC7BM,KAAK,CAACC,IAAI,CAAC,CACR,GAAEX,M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AqB,CACnBgD,WAAW,EACV,sBAAqBsC,KAAM,kBAAiBL,KAAK,CAAChC,MAAO,SAC5D,CAAC;EACH,CAAC,CAAC,OAAOJ,KAAK,EAAE;IACdE,MAAM,CAACf,IAAI,CAACa,KAAK,CAAC;IAClB7C,qBAAqB,CAACgD,WAAW,EAAG,sCAAqC,CAAC;IAC1ElD,YAAY,CAAC+C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACAjD,YAAY,CAAE,4CAA2C,CAAC;EAC1D,OAAO,CAAC,KAAKmD,MAAM,CAACE,MAAM;AAC5B"}
|
package/esm/ops/PolicySetOps.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { createObjectTable, createProgressIndicator, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
4
|
-
import { getTypedFilename, saveJsonToFile, titleCase } from '../utils/ExportImportUtils';
|
|
5
4
|
const {
|
|
6
5
|
getRealmName,
|
|
6
|
+
getTypedFilename,
|
|
7
|
+
saveJsonToFile,
|
|
8
|
+
titleCase,
|
|
7
9
|
getFilePath,
|
|
8
10
|
getWorkingDirectory
|
|
9
11
|
} = frodo.utils;
|
|
@@ -167,10 +169,11 @@ export async function deletePolicySets() {
|
|
|
167
169
|
* Export policy set to file
|
|
168
170
|
* @param {string} policySetId policy set id/name
|
|
169
171
|
* @param {string} file file name
|
|
172
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
170
173
|
* @param {PolicySetExportOptions} options export options
|
|
171
174
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
172
175
|
*/
|
|
173
|
-
export async function exportPolicySetToFile(policySetId, file, options = {
|
|
176
|
+
export async function exportPolicySetToFile(policySetId, file, includeMeta = true, options = {
|
|
174
177
|
deps: true,
|
|
175
178
|
prereqs: false,
|
|
176
179
|
useStringArrays: true
|
|
@@ -185,7 +188,7 @@ export async function exportPolicySetToFile(policySetId, file, options = {
|
|
|
185
188
|
}
|
|
186
189
|
const filePath = getFilePath(fileName, true);
|
|
187
190
|
const exportData = await exportPolicySet(policySetId, options);
|
|
188
|
-
saveJsonToFile(exportData, filePath);
|
|
191
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
189
192
|
stopProgressIndicator(indicatorId, `Exported ${policySetId} to ${filePath}.`, 'success');
|
|
190
193
|
outcome = true;
|
|
191
194
|
} catch (error) {
|
|
@@ -198,10 +201,11 @@ export async function exportPolicySetToFile(policySetId, file, options = {
|
|
|
198
201
|
/**
|
|
199
202
|
* Export policy sets to file
|
|
200
203
|
* @param {string} file file name
|
|
204
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
201
205
|
* @param {PolicySetExportOptions} options export options
|
|
202
206
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
203
207
|
*/
|
|
204
|
-
export async function exportPolicySetsToFile(file, options = {
|
|
208
|
+
export async function exportPolicySetsToFile(file, includeMeta = true, options = {
|
|
205
209
|
deps: true,
|
|
206
210
|
prereqs: false,
|
|
207
211
|
useStringArrays: true
|
|
@@ -216,7 +220,7 @@ export async function exportPolicySetsToFile(file, options = {
|
|
|
216
220
|
}
|
|
217
221
|
const filePath = getFilePath(fileName, true);
|
|
218
222
|
const exportData = await exportPolicySets(options);
|
|
219
|
-
saveJsonToFile(exportData, filePath);
|
|
223
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
220
224
|
stopProgressIndicator(indicatorId, `Exported all policy sets to ${filePath}.`, 'success');
|
|
221
225
|
outcome = true;
|
|
222
226
|
} catch (error) {
|
|
@@ -228,10 +232,11 @@ export async function exportPolicySetsToFile(file, options = {
|
|
|
228
232
|
|
|
229
233
|
/**
|
|
230
234
|
* Export all policy sets to separate files
|
|
235
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
231
236
|
* @param {PolicySetExportOptions} options export options
|
|
232
237
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
233
238
|
*/
|
|
234
|
-
export async function exportPolicySetsToFiles(options = {
|
|
239
|
+
export async function exportPolicySetsToFiles(includeMeta = true, options = {
|
|
235
240
|
deps: true,
|
|
236
241
|
prereqs: false,
|
|
237
242
|
useStringArrays: true
|
|
@@ -246,7 +251,7 @@ export async function exportPolicySetsToFiles(options = {
|
|
|
246
251
|
const file = getTypedFilename(policySet.name, 'policyset.authz');
|
|
247
252
|
try {
|
|
248
253
|
const exportData = await exportPolicySet(policySet.name, options);
|
|
249
|
-
saveJsonToFile(exportData, getFilePath(file, true));
|
|
254
|
+
saveJsonToFile(exportData, getFilePath(file, true), includeMeta);
|
|
250
255
|
updateProgressIndicator(indicatorId, `Exported ${policySet.name}.`);
|
|
251
256
|
} catch (error) {
|
|
252
257
|
errors.push(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolicySetOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getTypedFilename","saveJsonToFile","titleCase","getRealmName","getFilePath","getWorkingDirectory","utils","readPoliciesByPolicySet","deletePolicy","authz","policy","readPolicySets","readPolicySet","exportPolicySet","exportPolicySets","importPolicySet","importFirstPolicySet","importPolicySets","deletePolicySet","policySet","listPolicySets","outcome","policySets","sort","a","b","name","localeCompare","err","message","describePolicySet","policySetId","json","table","toString","deletePolicySetById","indicatorId","errors","policies","_id","error","push","length","errorMessages","map","join","deletePolicySets","indicatorId2","exportPolicySetToFile","file","options","deps","prereqs","useStringArrays","fileName","filePath","exportData","exportPolicySetsToFile","getRealm","exportPolicySetsToFiles","importPolicySetFromFile","data","readFileSync","fileData","JSON","parse","importFirstPolicySetFromFile","importPolicySetsFromFile","importPolicySetsFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","count","Object","keys","policyset"],"sources":["../../src/ops/PolicySetOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type PolicySkeleton } from '@rockcarver/frodo-lib/types/api/PoliciesApi';\nimport { type PolicySetSkeleton } from '@rockcarver/frodo-lib/types/api/PolicySetApi';\nimport {\n type PolicySetExportInterface,\n type PolicySetExportOptions,\n type PolicySetImportOptions,\n} from '@rockcarver/frodo-lib/types/ops/PolicySetOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n} from '../utils/ExportImportUtils';\n\nconst { getRealmName, getFilePath, getWorkingDirectory } = frodo.utils;\nconst { readPoliciesByPolicySet, deletePolicy } = frodo.authz.policy;\nconst {\n readPolicySets,\n readPolicySet,\n exportPolicySet,\n exportPolicySets,\n importPolicySet,\n importFirstPolicySet,\n importPolicySets,\n deletePolicySet,\n} = frodo.authz.policySet;\n\n/**\n * List policy sets\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPolicySets(): Promise<boolean> {\n let outcome = false;\n try {\n const policySets = await readPolicySets();\n policySets.sort((a, b) => a.name.localeCompare(b.name));\n for (const policySet of policySets) {\n printMessage(`${policySet.name}`, 'data');\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicySets ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe policy set\n * @param {string} policySetId policy set id/name\n * @param {Object} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describePolicySet(\n policySetId: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n const policySet = await readPolicySet(policySetId);\n outcome = true;\n if (json) {\n printMessage(policySet, 'data');\n } else {\n const table = createObjectTable(policySet);\n printMessage(table.toString(), 'data');\n }\n return outcome;\n}\n\n/**\n * Delete policy set\n * @param {string} policySetId policy set id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicySetById(\n policySetId: string\n): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.deletePolicySet: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Deleting ${policySetId}...`\n );\n let outcome = false;\n const errors = [];\n const policies: PolicySkeleton[] = await readPoliciesByPolicySet(policySetId);\n for (const policy of policies) {\n try {\n debugMessage(`Deleting policy ${policy._id}`);\n await deletePolicy(policy._id);\n } catch (error) {\n error.message = `Error deleting policy ${policy._id} in policy set ${policySetId}: ${error}`;\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n stopProgressIndicator(\n indicatorId,\n `Error deleting policies in policy set ${policySetId}: ${errorMessages}`,\n 'fail'\n );\n } else {\n try {\n debugMessage(`Deleting policy set ${policySetId}`);\n await deletePolicySet(policySetId);\n stopProgressIndicator(indicatorId, `Deleted ${policySetId}.`, 'success');\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error deleting policy set ${policySetId}: ${error}`,\n 'fail'\n );\n }\n }\n debugMessage(`cli.PolicySetOps.deletePolicySet: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policy sets\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicySets(): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.deletePolicySets: begin`);\n let outcome = false;\n const errors = [];\n let policySets: PolicySetSkeleton[] = [];\n let indicatorId: string;\n let indicatorId2: string;\n try {\n indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Retrieving all policy sets...`\n );\n try {\n policySets = await readPolicySets();\n stopProgressIndicator(\n indicatorId,\n `Found ${policySets.length} policy sets.`,\n 'success'\n );\n } catch (error) {\n error.message = `Error retrieving all policy sets: ${error.message}`;\n stopProgressIndicator(indicatorId, error.message, 'fail');\n throw error;\n }\n if (policySets.length)\n indicatorId2 = createProgressIndicator(\n 'determinate',\n policySets.length,\n `Deleting ${policySets.length} policy sets...`\n );\n for (const policySet of policySets) {\n const policySetId = policySet.name;\n try {\n const policies: PolicySkeleton[] =\n await readPoliciesByPolicySet(policySetId);\n for (const policy of policies) {\n try {\n debugMessage(`Deleting policy ${policy._id}`);\n await deletePolicy(policy._id);\n } catch (error) {\n error.message = `Error deleting policy ${policy._id} in policy set ${policySetId}: ${error}`;\n printMessage(error.message, 'error');\n errors.push(error);\n }\n }\n } catch (error) {\n errors.push(error);\n }\n try {\n debugMessage(`Deleting policy set ${policySetId}`);\n await deletePolicySet(policySetId);\n updateProgressIndicator(indicatorId2, `Deleted ${policySetId}`);\n } catch (error) {\n error.message = `Error deleting policy set ${policySetId}: ${error}`;\n updateProgressIndicator(indicatorId2, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policy sets: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policySets.length)\n stopProgressIndicator(\n indicatorId2,\n `Error deleting all policy sets: ${errorMessages}`\n );\n } else {\n if (policySets.length)\n stopProgressIndicator(\n indicatorId2,\n `Deleted ${policySets.length} policy sets.`\n );\n outcome = true;\n }\n }\n debugMessage(`cli.PolicySetOps.deletePolicySets: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Export policy set to file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetToFile(\n policySetId: string,\n file: string,\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.exportPolicySetToFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting ${policySetId}...`\n );\n try {\n let fileName = getTypedFilename(policySetId, 'policyset.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicySet(policySetId, options);\n saveJsonToFile(exportData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported ${policySetId} to ${filePath}.`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting ${policySetId}: ${error.message}`,\n 'fail'\n );\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetToFile: end`);\n return outcome;\n}\n\n/**\n * Export policy sets to file\n * @param {string} file file name\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetsToFile(\n file: string,\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting all policy sets...`\n );\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}PolicySets`,\n 'policyset.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicySets(options);\n saveJsonToFile(exportData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported all policy sets to ${filePath}.`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting policy sets: ${error.message}`,\n 'fail'\n );\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: end`);\n return outcome;\n}\n\n/**\n * Export all policy sets to separate files\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetsToFiles(\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policySets: PolicySetSkeleton[] = await readPolicySets();\n indicatorId = createProgressIndicator(\n 'determinate',\n policySets.length,\n 'Exporting policy sets...'\n );\n for (const policySet of policySets) {\n const file = getTypedFilename(policySet.name, 'policyset.authz');\n try {\n const exportData: PolicySetExportInterface = await exportPolicySet(\n policySet.name,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true));\n updateProgressIndicator(indicatorId, `Exported ${policySet.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error exporting ${policySet.name}.`\n );\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import policy set from file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetFromFile(\n policySetId: string,\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importPolicySetFromFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${policySetId}...`\n );\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importPolicySet(policySetId, fileData, options);\n outcome = true;\n stopProgressIndicator(indicatorId, `Imported ${policySetId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${policySetId}.`,\n 'fail'\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first policy set from file\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstPolicySetFromFile(\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: begin`);\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first policy set from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const policySet = await importFirstPolicySet(fileData, options);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Imported first policy set with name '${policySet.name}' from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first policy set from ${filePath}.`,\n 'fail'\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policy sets from file\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetsFromFile(\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: begin`);\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importPolicySets(fileData, options);\n outcome = true;\n stopProgressIndicator(indicatorId, `Imported ${filePath}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error importing ${filePath}.`, 'fail');\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policy sets from files\n * @param {OAuth2ClientImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetsFromFiles(\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.policyset.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing policy sets...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: PolicySetExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.policyset).length;\n total += count;\n await importPolicySets(fileData, options);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} policy sets from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing policy sets from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} policy sets from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error importing policy sets from files.`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAQpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,SAAS,QACJ,4BAA4B;AAEnC,MAAM;EAAEC,YAAY;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGd,KAAK,CAACe,KAAK;AACtE,MAAM;EAAEC,uBAAuB;EAAEC;AAAa,CAAC,GAAGjB,KAAK,CAACkB,KAAK,CAACC,MAAM;AACpE,MAAM;EACJC,cAAc;EACdC,aAAa;EACbC,eAAe;EACfC,gBAAgB;EAChBC,eAAe;EACfC,oBAAoB;EACpBC,gBAAgB;EAChBC;AACF,CAAC,GAAG3B,KAAK,CAACkB,KAAK,CAACU,SAAS;;AAEzB;AACA;AACA;AACA;AACA,OAAO,eAAeC,cAAcA,CAAA,EAAqB;EACvD,IAAIC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EAAE;IACdH,MAAM,CAACI,IAAI,CAACD,KAAK,CAAC;IAClB1C,qBAAqB,CACnBsC,WAAW,EACV,yCACH,CAAC;IACDvC,YAAY,CAAC2C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACA5C,YAAY,CAAE,iDAAgD,CAAC;EAC/D,OAAO,CAAC,KAAKyC,MAAM,CAACK,MAAM;AAC5B"}
|
|
1
|
+
{"version":3,"file":"PolicySetOps.js","names":["frodo","state","fs","createObjectTable","createProgressIndicator","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getRealmName","getTypedFilename","saveJsonToFile","titleCase","getFilePath","getWorkingDirectory","utils","readPoliciesByPolicySet","deletePolicy","authz","policy","readPolicySets","readPolicySet","exportPolicySet","exportPolicySets","importPolicySet","importFirstPolicySet","importPolicySets","deletePolicySet","policySet","listPolicySets","outcome","policySets","sort","a","b","name","localeCompare","err","message","describePolicySet","policySetId","json","table","toString","deletePolicySetById","indicatorId","errors","policies","_id","error","push","length","errorMessages","map","join","deletePolicySets","indicatorId2","exportPolicySetToFile","file","includeMeta","options","deps","prereqs","useStringArrays","fileName","filePath","exportData","exportPolicySetsToFile","getRealm","exportPolicySetsToFiles","importPolicySetFromFile","data","readFileSync","fileData","JSON","parse","importFirstPolicySetFromFile","importPolicySetsFromFile","importPolicySetsFromFiles","names","readdirSync","files","filter","toLowerCase","endsWith","total","count","Object","keys","policyset"],"sources":["../../src/ops/PolicySetOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport { type PolicySkeleton } from '@rockcarver/frodo-lib/types/api/PoliciesApi';\nimport { type PolicySetSkeleton } from '@rockcarver/frodo-lib/types/api/PolicySetApi';\nimport {\n type PolicySetExportInterface,\n type PolicySetExportOptions,\n type PolicySetImportOptions,\n} from '@rockcarver/frodo-lib/types/ops/PolicySetOps';\nimport fs from 'fs';\n\nimport {\n createObjectTable,\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n getRealmName,\n getTypedFilename,\n saveJsonToFile,\n titleCase,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\nconst { readPoliciesByPolicySet, deletePolicy } = frodo.authz.policy;\nconst {\n readPolicySets,\n readPolicySet,\n exportPolicySet,\n exportPolicySets,\n importPolicySet,\n importFirstPolicySet,\n importPolicySets,\n deletePolicySet,\n} = frodo.authz.policySet;\n\n/**\n * List policy sets\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function listPolicySets(): Promise<boolean> {\n let outcome = false;\n try {\n const policySets = await readPolicySets();\n policySets.sort((a, b) => a.name.localeCompare(b.name));\n for (const policySet of policySets) {\n printMessage(`${policySet.name}`, 'data');\n }\n outcome = true;\n } catch (err) {\n printMessage(`listPolicySets ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n return outcome;\n}\n\n/**\n * Describe policy set\n * @param {string} policySetId policy set id/name\n * @param {Object} json JSON output\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function describePolicySet(\n policySetId: string,\n json = false\n): Promise<boolean> {\n let outcome = false;\n const policySet = await readPolicySet(policySetId);\n outcome = true;\n if (json) {\n printMessage(policySet, 'data');\n } else {\n const table = createObjectTable(policySet);\n printMessage(table.toString(), 'data');\n }\n return outcome;\n}\n\n/**\n * Delete policy set\n * @param {string} policySetId policy set id/name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicySetById(\n policySetId: string\n): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.deletePolicySet: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Deleting ${policySetId}...`\n );\n let outcome = false;\n const errors = [];\n const policies: PolicySkeleton[] = await readPoliciesByPolicySet(policySetId);\n for (const policy of policies) {\n try {\n debugMessage(`Deleting policy ${policy._id}`);\n await deletePolicy(policy._id);\n } catch (error) {\n error.message = `Error deleting policy ${policy._id} in policy set ${policySetId}: ${error}`;\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n stopProgressIndicator(\n indicatorId,\n `Error deleting policies in policy set ${policySetId}: ${errorMessages}`,\n 'fail'\n );\n } else {\n try {\n debugMessage(`Deleting policy set ${policySetId}`);\n await deletePolicySet(policySetId);\n stopProgressIndicator(indicatorId, `Deleted ${policySetId}.`, 'success');\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error deleting policy set ${policySetId}: ${error}`,\n 'fail'\n );\n }\n }\n debugMessage(`cli.PolicySetOps.deletePolicySet: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Delete all policy sets\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function deletePolicySets(): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.deletePolicySets: begin`);\n let outcome = false;\n const errors = [];\n let policySets: PolicySetSkeleton[] = [];\n let indicatorId: string;\n let indicatorId2: string;\n try {\n indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Retrieving all policy sets...`\n );\n try {\n policySets = await readPolicySets();\n stopProgressIndicator(\n indicatorId,\n `Found ${policySets.length} policy sets.`,\n 'success'\n );\n } catch (error) {\n error.message = `Error retrieving all policy sets: ${error.message}`;\n stopProgressIndicator(indicatorId, error.message, 'fail');\n throw error;\n }\n if (policySets.length)\n indicatorId2 = createProgressIndicator(\n 'determinate',\n policySets.length,\n `Deleting ${policySets.length} policy sets...`\n );\n for (const policySet of policySets) {\n const policySetId = policySet.name;\n try {\n const policies: PolicySkeleton[] =\n await readPoliciesByPolicySet(policySetId);\n for (const policy of policies) {\n try {\n debugMessage(`Deleting policy ${policy._id}`);\n await deletePolicy(policy._id);\n } catch (error) {\n error.message = `Error deleting policy ${policy._id} in policy set ${policySetId}: ${error}`;\n printMessage(error.message, 'error');\n errors.push(error);\n }\n }\n } catch (error) {\n errors.push(error);\n }\n try {\n debugMessage(`Deleting policy set ${policySetId}`);\n await deletePolicySet(policySetId);\n updateProgressIndicator(indicatorId2, `Deleted ${policySetId}`);\n } catch (error) {\n error.message = `Error deleting policy set ${policySetId}: ${error}`;\n updateProgressIndicator(indicatorId2, error.message);\n errors.push(error);\n }\n }\n } catch (error) {\n error.message = `Error deleting policy sets: ${error}`;\n errors.push(error);\n } finally {\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n if (policySets.length)\n stopProgressIndicator(\n indicatorId2,\n `Error deleting all policy sets: ${errorMessages}`\n );\n } else {\n if (policySets.length)\n stopProgressIndicator(\n indicatorId2,\n `Deleted ${policySets.length} policy sets.`\n );\n outcome = true;\n }\n }\n debugMessage(`cli.PolicySetOps.deletePolicySets: end [outcome=${outcome}]`);\n return outcome;\n}\n\n/**\n * Export policy set to file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetToFile(\n policySetId: string,\n file: string,\n includeMeta = true,\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.exportPolicySetToFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting ${policySetId}...`\n );\n try {\n let fileName = getTypedFilename(policySetId, 'policyset.authz');\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicySet(policySetId, options);\n saveJsonToFile(exportData, filePath, includeMeta);\n stopProgressIndicator(\n indicatorId,\n `Exported ${policySetId} to ${filePath}.`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting ${policySetId}: ${error.message}`,\n 'fail'\n );\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetToFile: end`);\n return outcome;\n}\n\n/**\n * Export policy sets to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetsToFile(\n file: string,\n includeMeta = true,\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Exporting all policy sets...`\n );\n try {\n let fileName = getTypedFilename(\n `all${titleCase(getRealmName(state.getRealm()))}PolicySets`,\n 'policyset.authz'\n );\n if (file) {\n fileName = file;\n }\n const filePath = getFilePath(fileName, true);\n const exportData = await exportPolicySets(options);\n saveJsonToFile(exportData, filePath, includeMeta);\n stopProgressIndicator(\n indicatorId,\n `Exported all policy sets to ${filePath}.`,\n 'success'\n );\n outcome = true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting policy sets: ${error.message}`,\n 'fail'\n );\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: end`);\n return outcome;\n}\n\n/**\n * Export all policy sets to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @param {PolicySetExportOptions} options export options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportPolicySetsToFiles(\n includeMeta = true,\n options: PolicySetExportOptions = {\n deps: true,\n prereqs: false,\n useStringArrays: true,\n }\n): Promise<boolean> {\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: begin`);\n const errors = [];\n let indicatorId: string;\n try {\n const policySets: PolicySetSkeleton[] = await readPolicySets();\n indicatorId = createProgressIndicator(\n 'determinate',\n policySets.length,\n 'Exporting policy sets...'\n );\n for (const policySet of policySets) {\n const file = getTypedFilename(policySet.name, 'policyset.authz');\n try {\n const exportData: PolicySetExportInterface = await exportPolicySet(\n policySet.name,\n options\n );\n saveJsonToFile(exportData, getFilePath(file, true), includeMeta);\n updateProgressIndicator(indicatorId, `Exported ${policySet.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error exporting ${policySet.name}.`\n );\n }\n }\n stopProgressIndicator(indicatorId, `Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);\n }\n debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: end`);\n return 0 === errors.length;\n}\n\n/**\n * Import policy set from file\n * @param {string} policySetId policy set id/name\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetFromFile(\n policySetId: string,\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importPolicySetFromFile: begin`);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${policySetId}...`\n );\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n await importPolicySet(policySetId, fileData, options);\n outcome = true;\n stopProgressIndicator(indicatorId, `Imported ${policySetId}.`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing ${policySetId}.`,\n 'fail'\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetFromFile: end`);\n return outcome;\n}\n\n/**\n * Import first policy set from file\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importFirstPolicySetFromFile(\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: begin`);\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first policy set from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const policySet = await importFirstPolicySet(fileData, options);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Imported first policy set with name '${policySet.name}' from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first policy set from ${filePath}.`,\n 'fail'\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policy sets from file\n * @param {string} file file name\n * @param {PolicySetImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetsFromFile(\n file: string,\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n let outcome = false;\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: begin`);\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importPolicySets(fileData, options);\n outcome = true;\n stopProgressIndicator(indicatorId, `Imported ${filePath}.`, 'success');\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error importing ${filePath}.`, 'fail');\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: end`);\n return outcome;\n}\n\n/**\n * Import policy sets from files\n * @param {OAuth2ClientImportOptions} options import options\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importPolicySetsFromFiles(\n options: PolicySetImportOptions = { deps: true, prereqs: false }\n): Promise<boolean> {\n const errors = [];\n let indicatorId: string;\n try {\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: begin`);\n const names = fs.readdirSync(getWorkingDirectory());\n const files = names\n .filter((name) => name.toLowerCase().endsWith('.policyset.authz.json'))\n .map((name) => getFilePath(name));\n indicatorId = createProgressIndicator(\n 'determinate',\n files.length,\n 'Importing policy sets...'\n );\n let total = 0;\n for (const file of files) {\n try {\n const data = fs.readFileSync(file, 'utf8');\n const fileData: PolicySetExportInterface = JSON.parse(data);\n const count = Object.keys(fileData.policyset).length;\n total += count;\n await importPolicySets(fileData, options);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} policy sets from ${file}`\n );\n } catch (error) {\n errors.push(error);\n updateProgressIndicator(\n indicatorId,\n `Error importing policy sets from ${file}`\n );\n printMessage(error, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} policy sets from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressIndicator(\n indicatorId,\n `Error importing policy sets from files.`\n );\n printMessage(error, 'error');\n }\n debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: end`);\n return 0 === errors.length;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AAQpD,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,uBAAuB,EACvBC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AAEzB,MAAM;EACJC,YAAY;EACZC,gBAAgB;EAChBC,cAAc;EACdC,SAAS;EACTC,WAAW;EACXC;AACF,CAAC,GAAGd,KAAK,CAACe,KAAK;AACf,MAAM;EAAEC,uBAAuB;EAAEC;AAAa,CAAC,GAAGjB,KAAK,CAACkB,KAAK,CAACC,MAAM;AACpE,MAAM;EACJC,cAAc;EACdC,aAAa;EACbC,eAAe;EACfC,gBAAgB;EAChBC,eAAe;EACfC,oBAAoB;EACpBC,gBAAgB;EAChBC;AACF,CAAC,GAAG3B,KAAK,CAACkB,KAAK,CAACU,SAAS;;AAEzB;AACA;AACA;AACA;AACA,OAAO,eAAeC,cAAcA,CAAA,EAAqB;EACvD,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAI;IACF,MAAMC,UAAU,GAAG,MAAMX,cAAc,CAAC,CAAC;IACzCW,UAAU,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,IAAI,CAACC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AAK,CAAC;IAClB1C,qBAAqB,CACnBsC,WAAW,EACV,yCACH,CAAC;IACDvC,YAAY,CAAC2C,KAAK,EAAE,OAAO,CAAC;EAC9B;EACA5C,YAAY,CAAE,iDAAgD,CAAC;EAC/D,OAAO,CAAC,KAAKyC,MAAM,CAACK,MAAM;AAC5B"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { createObjectTable, createProgressIndicator, createTable, debugMessage, failSpinner, printMessage, showSpinner, stopProgressIndicator, succeedSpinner, updateProgressIndicator } from '../utils/Console';
|
|
4
|
-
import { getTypedFilename, saveJsonToFile, titleCase } from '../utils/ExportImportUtils';
|
|
5
4
|
const {
|
|
6
5
|
getRealmName,
|
|
6
|
+
getTypedFilename,
|
|
7
|
+
saveJsonToFile,
|
|
8
|
+
titleCase,
|
|
7
9
|
getFilePath,
|
|
8
10
|
getWorkingDirectory
|
|
9
11
|
} = frodo.utils;
|
|
@@ -206,9 +208,10 @@ export async function deleteResourceTypes() {
|
|
|
206
208
|
* Export resource type to file
|
|
207
209
|
* @param {string} resourceTypeUuid resource type uuid
|
|
208
210
|
* @param {string} file file name
|
|
211
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
209
212
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
210
213
|
*/
|
|
211
|
-
export async function exportResourceTypeToFile(resourceTypeUuid, file) {
|
|
214
|
+
export async function exportResourceTypeToFile(resourceTypeUuid, file, includeMeta = true) {
|
|
212
215
|
let outcome = false;
|
|
213
216
|
debugMessage(`cli.ResourceTypeOps.exportResourceTypeToFile: begin`);
|
|
214
217
|
showSpinner(`Exporting ${resourceTypeUuid}...`);
|
|
@@ -219,7 +222,7 @@ export async function exportResourceTypeToFile(resourceTypeUuid, file) {
|
|
|
219
222
|
}
|
|
220
223
|
const filePath = getFilePath(fileName, true);
|
|
221
224
|
const exportData = await exportResourceType(resourceTypeUuid);
|
|
222
|
-
saveJsonToFile(exportData, filePath);
|
|
225
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
223
226
|
succeedSpinner(`Exported ${resourceTypeUuid} to ${filePath}.`);
|
|
224
227
|
outcome = true;
|
|
225
228
|
} catch (error) {
|
|
@@ -233,9 +236,10 @@ export async function exportResourceTypeToFile(resourceTypeUuid, file) {
|
|
|
233
236
|
* Export resource type by name to file
|
|
234
237
|
* @param {string} resourceTypeName resource type name
|
|
235
238
|
* @param {string} file file name
|
|
239
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
236
240
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
237
241
|
*/
|
|
238
|
-
export async function exportResourceTypeByNameToFile(resourceTypeName, file) {
|
|
242
|
+
export async function exportResourceTypeByNameToFile(resourceTypeName, file, includeMeta = true) {
|
|
239
243
|
let outcome = false;
|
|
240
244
|
debugMessage(`cli.ResourceTypeOps.exportResourceTypeByNameToFile: begin`);
|
|
241
245
|
showSpinner(`Exporting ${resourceTypeName}...`);
|
|
@@ -246,7 +250,7 @@ export async function exportResourceTypeByNameToFile(resourceTypeName, file) {
|
|
|
246
250
|
}
|
|
247
251
|
const filePath = getFilePath(fileName, true);
|
|
248
252
|
const exportData = await exportResourceTypeByName(resourceTypeName);
|
|
249
|
-
saveJsonToFile(exportData, filePath);
|
|
253
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
250
254
|
succeedSpinner(`Exported ${resourceTypeName} to ${filePath}.`);
|
|
251
255
|
outcome = true;
|
|
252
256
|
} catch (error) {
|
|
@@ -259,9 +263,10 @@ export async function exportResourceTypeByNameToFile(resourceTypeName, file) {
|
|
|
259
263
|
/**
|
|
260
264
|
* Export resource types to file
|
|
261
265
|
* @param {string} file file name
|
|
266
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
262
267
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
263
268
|
*/
|
|
264
|
-
export async function exportResourceTypesToFile(file) {
|
|
269
|
+
export async function exportResourceTypesToFile(file, includeMeta = true) {
|
|
265
270
|
let outcome = false;
|
|
266
271
|
debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFile: begin`);
|
|
267
272
|
showSpinner(`Exporting all resource types...`);
|
|
@@ -272,7 +277,7 @@ export async function exportResourceTypesToFile(file) {
|
|
|
272
277
|
}
|
|
273
278
|
const filePath = getFilePath(fileName, true);
|
|
274
279
|
const exportData = await exportResourceTypes();
|
|
275
|
-
saveJsonToFile(exportData, filePath);
|
|
280
|
+
saveJsonToFile(exportData, filePath, includeMeta);
|
|
276
281
|
succeedSpinner(`Exported all resource types to ${filePath}.`);
|
|
277
282
|
outcome = true;
|
|
278
283
|
} catch (error) {
|
|
@@ -284,9 +289,10 @@ export async function exportResourceTypesToFile(file) {
|
|
|
284
289
|
|
|
285
290
|
/**
|
|
286
291
|
* Export all resource types to separate files
|
|
292
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
287
293
|
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
288
294
|
*/
|
|
289
|
-
export async function exportResourceTypesToFiles() {
|
|
295
|
+
export async function exportResourceTypesToFiles(includeMeta = true) {
|
|
290
296
|
debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: begin`);
|
|
291
297
|
const errors = [];
|
|
292
298
|
let indicatorId;
|
|
@@ -297,7 +303,7 @@ export async function exportResourceTypesToFiles() {
|
|
|
297
303
|
const file = getTypedFilename(resourceType.name, 'resourcetype.authz');
|
|
298
304
|
try {
|
|
299
305
|
const exportData = await exportResourceType(resourceType.uuid);
|
|
300
|
-
saveJsonToFile(exportData, getFilePath(file, true));
|
|
306
|
+
saveJsonToFile(exportData, getFilePath(file, true), includeMeta);
|
|
301
307
|
updateProgressIndicator(indicatorId, `Exported ${resourceType.name}.`);
|
|
302
308
|
} catch (error) {
|
|
303
309
|
errors.push(error);
|