@rockcarver/frodo-cli 2.0.0-32 → 2.0.0-34

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/esm/cli/FrodoCommand.js +8 -1
  3. package/esm/cli/FrodoCommand.js.map +1 -1
  4. package/esm/cli/admin/admin-execute-rfc7523-authz-grant-flow.js +41 -0
  5. package/esm/cli/admin/admin-execute-rfc7523-authz-grant-flow.js.map +1 -0
  6. package/esm/cli/admin/admin-export-full-cloud-config.js +44 -0
  7. package/esm/cli/admin/admin-export-full-cloud-config.js.map +1 -0
  8. package/esm/cli/admin/admin-generate-rfc7523-authz-grant-artifacts.js +43 -0
  9. package/esm/cli/admin/admin-generate-rfc7523-authz-grant-artifacts.js.map +1 -0
  10. package/esm/cli/admin/admin.js +3 -0
  11. package/esm/cli/admin/admin.js.map +1 -1
  12. package/esm/cli/authz/authz-policy-export.js +1 -1
  13. package/esm/cli/authz/authz-policy-export.js.map +1 -1
  14. package/esm/cli/authz/authz-policy-import.js +1 -1
  15. package/esm/cli/authz/authz-policy-import.js.map +1 -1
  16. package/esm/cli/authz/authz-policy-list.js +2 -2
  17. package/esm/cli/authz/authz-policy-list.js.map +1 -1
  18. package/esm/cli/authz/authz-set-delete.js +2 -2
  19. package/esm/cli/authz/authz-set-delete.js.map +1 -1
  20. package/esm/cli/authz/authz-set-export.js +1 -1
  21. package/esm/cli/authz/authz-set-export.js.map +1 -1
  22. package/esm/cli/authz/authz-set-import.js +1 -1
  23. package/esm/cli/authz/authz-set-import.js.map +1 -1
  24. package/esm/cli/authz/authz-set-list.js +1 -1
  25. package/esm/cli/authz/authz-set-list.js.map +1 -1
  26. package/esm/cli/authz/authz-type-delete.js +3 -3
  27. package/esm/cli/authz/authz-type-delete.js.map +1 -1
  28. package/esm/cli/authz/authz-type-export.js +2 -2
  29. package/esm/cli/authz/authz-type-export.js.map +1 -1
  30. package/esm/cli/authz/authz-type-import.js +2 -2
  31. package/esm/cli/authz/authz-type-import.js.map +1 -1
  32. package/esm/cli/authz/authz-type-list.js +1 -1
  33. package/esm/cli/authz/authz-type-list.js.map +1 -1
  34. package/esm/cli/email/email-template-export.js +3 -3
  35. package/esm/cli/email/email-template-export.js.map +1 -1
  36. package/esm/cli/email/email-template-import.js +4 -4
  37. package/esm/cli/email/email-template-import.js.map +1 -1
  38. package/esm/cli/email/email-template-list.js +1 -1
  39. package/esm/cli/email/email-template-list.js.map +1 -1
  40. package/esm/cli/esv/esv-secret-create.js +2 -1
  41. package/esm/cli/esv/esv-secret-create.js.map +1 -1
  42. package/esm/cli/esv/esv-secret-delete.js +4 -3
  43. package/esm/cli/esv/esv-secret-delete.js.map +1 -1
  44. package/esm/cli/esv/esv-secret-describe.js +2 -1
  45. package/esm/cli/esv/esv-secret-describe.js.map +1 -1
  46. package/esm/cli/esv/esv-secret-export.js +6 -4
  47. package/esm/cli/esv/esv-secret-export.js.map +1 -1
  48. package/esm/cli/esv/esv-secret-list.js +2 -1
  49. package/esm/cli/esv/esv-secret-list.js.map +1 -1
  50. package/esm/cli/esv/esv-secret-set.js +2 -1
  51. package/esm/cli/esv/esv-secret-set.js.map +1 -1
  52. package/esm/cli/esv/esv-secret-version-activate.js +2 -2
  53. package/esm/cli/esv/esv-secret-version-activate.js.map +1 -1
  54. package/esm/cli/esv/esv-secret-version-create.js +2 -1
  55. package/esm/cli/esv/esv-secret-version-create.js.map +1 -1
  56. package/esm/cli/esv/esv-secret-version-deactivate.js +2 -2
  57. package/esm/cli/esv/esv-secret-version-deactivate.js.map +1 -1
  58. package/esm/cli/esv/esv-secret-version-delete.js +4 -3
  59. package/esm/cli/esv/esv-secret-version-delete.js.map +1 -1
  60. package/esm/cli/esv/esv-secret-version-list.js +2 -1
  61. package/esm/cli/esv/esv-secret-version-list.js.map +1 -1
  62. package/esm/cli/esv/esv-variable-create.js +2 -1
  63. package/esm/cli/esv/esv-variable-create.js.map +1 -1
  64. package/esm/cli/esv/esv-variable-delete.js +4 -2
  65. package/esm/cli/esv/esv-variable-delete.js.map +1 -1
  66. package/esm/cli/esv/esv-variable-describe.js +2 -1
  67. package/esm/cli/esv/esv-variable-describe.js.map +1 -1
  68. package/esm/cli/esv/esv-variable-export.js +6 -3
  69. package/esm/cli/esv/esv-variable-export.js.map +1 -1
  70. package/esm/cli/esv/esv-variable-list.js +2 -1
  71. package/esm/cli/esv/esv-variable-list.js.map +1 -1
  72. package/esm/cli/esv/esv-variable-set.js +4 -2
  73. package/esm/cli/esv/esv-variable-set.js.map +1 -1
  74. package/esm/cli/idm/idm-count.js +1 -1
  75. package/esm/cli/idm/idm-count.js.map +1 -1
  76. package/esm/cli/idm/idm-export.js +3 -3
  77. package/esm/cli/idm/idm-export.js.map +1 -1
  78. package/esm/cli/idm/idm-list.js +2 -2
  79. package/esm/cli/idm/idm-list.js.map +1 -1
  80. package/esm/cli/idp/idp-export.js +3 -3
  81. package/esm/cli/idp/idp-export.js.map +1 -1
  82. package/esm/cli/idp/idp-import.js +4 -4
  83. package/esm/cli/idp/idp-import.js.map +1 -1
  84. package/esm/cli/idp/idp-list.js +1 -1
  85. package/esm/cli/idp/idp-list.js.map +1 -1
  86. package/esm/cli/journey/journey-delete.js +6 -2
  87. package/esm/cli/journey/journey-delete.js.map +1 -1
  88. package/esm/cli/journey/journey-disable.js +4 -10
  89. package/esm/cli/journey/journey-disable.js.map +1 -1
  90. package/esm/cli/journey/journey-enable.js +4 -10
  91. package/esm/cli/journey/journey-enable.js.map +1 -1
  92. package/esm/cli/journey/journey-import.js +4 -4
  93. package/esm/cli/journey/journey-import.js.map +1 -1
  94. package/esm/cli/journey/journey-list.js +1 -1
  95. package/esm/cli/journey/journey-list.js.map +1 -1
  96. package/esm/cli/saml/saml-cot-export.js +3 -3
  97. package/esm/cli/saml/saml-cot-export.js.map +1 -1
  98. package/esm/cli/saml/saml-cot-list.js +1 -1
  99. package/esm/cli/saml/saml-cot-list.js.map +1 -1
  100. package/esm/cli/saml/saml-describe.js +1 -1
  101. package/esm/cli/saml/saml-describe.js.map +1 -1
  102. package/esm/cli/saml/saml-import.js +4 -4
  103. package/esm/cli/saml/saml-import.js.map +1 -1
  104. package/esm/cli/saml/saml-list.js +1 -1
  105. package/esm/cli/saml/saml-list.js.map +1 -1
  106. package/esm/cli/saml/saml-metadata-export.js +1 -1
  107. package/esm/cli/saml/saml-metadata-export.js.map +1 -1
  108. package/esm/cli/script/script-export.js +2 -6
  109. package/esm/cli/script/script-export.js.map +1 -1
  110. package/esm/cli/theme/theme-delete.js +3 -3
  111. package/esm/cli/theme/theme-delete.js.map +1 -1
  112. package/esm/cli/theme/theme-export.js +4 -4
  113. package/esm/cli/theme/theme-export.js.map +1 -1
  114. package/esm/cli/theme/theme-import.js +4 -4
  115. package/esm/cli/theme/theme-import.js.map +1 -1
  116. package/esm/cli/theme/theme-list.js +1 -1
  117. package/esm/cli/theme/theme-list.js.map +1 -1
  118. package/esm/ops/AdminFederationOps.js +28 -26
  119. package/esm/ops/AdminFederationOps.js.map +1 -1
  120. package/esm/ops/AdminOps.js +241 -0
  121. package/esm/ops/AdminOps.js.map +1 -0
  122. package/esm/ops/AgentOps.js +59 -51
  123. package/esm/ops/AgentOps.js.map +1 -1
  124. package/esm/ops/ApplicationOps.js +19 -13
  125. package/esm/ops/ApplicationOps.js.map +1 -1
  126. package/esm/ops/CirclesOfTrustOps.js +28 -26
  127. package/esm/ops/CirclesOfTrustOps.js.map +1 -1
  128. package/esm/ops/EmailTemplateOps.js +78 -94
  129. package/esm/ops/EmailTemplateOps.js.map +1 -1
  130. package/esm/ops/IdmOps.js +8 -31
  131. package/esm/ops/IdmOps.js.map +1 -1
  132. package/esm/ops/IdpOps.js +49 -54
  133. package/esm/ops/IdpOps.js.map +1 -1
  134. package/esm/ops/JourneyOps.js +91 -70
  135. package/esm/ops/JourneyOps.js.map +1 -1
  136. package/esm/ops/OAuth2ClientOps.js +13 -11
  137. package/esm/ops/OAuth2ClientOps.js.map +1 -1
  138. package/esm/ops/PolicyOps.js +31 -26
  139. package/esm/ops/PolicyOps.js.map +1 -1
  140. package/esm/ops/PolicySetOps.js +42 -39
  141. package/esm/ops/PolicySetOps.js.map +1 -1
  142. package/esm/ops/ResourceTypeOps.js +19 -16
  143. package/esm/ops/ResourceTypeOps.js.map +1 -1
  144. package/esm/ops/Saml2Ops.js +49 -45
  145. package/esm/ops/Saml2Ops.js.map +1 -1
  146. package/esm/ops/ScriptOps.js +36 -55
  147. package/esm/ops/ScriptOps.js.map +1 -1
  148. package/esm/ops/SecretsOps.js +159 -60
  149. package/esm/ops/SecretsOps.js.map +1 -1
  150. package/esm/ops/ThemeOps.js +111 -130
  151. package/esm/ops/ThemeOps.js.map +1 -1
  152. package/esm/ops/VariablesOps.js +126 -56
  153. package/esm/ops/VariablesOps.js.map +1 -1
  154. package/esm/utils/Console.js +69 -30
  155. package/esm/utils/Console.js.map +1 -1
  156. package/esm/utils/ExportImportUtils.js +4 -12
  157. package/esm/utils/ExportImportUtils.js.map +1 -1
  158. package/package.json +10 -2
@@ -1,6 +1,6 @@
1
1
  import { frodo, state } from '@rockcarver/frodo-lib';
2
2
  import fs from 'fs';
3
- import { createObjectTable, createProgressBar, debugMessage, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
3
+ import { createObjectTable, createProgressIndicator, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
4
4
  import { getTypedFilename, saveJsonToFile, titleCase } from '../utils/ExportImportUtils';
5
5
  const {
6
6
  getRealmName,
@@ -68,7 +68,7 @@ export async function describePolicySet(policySetId, json = false) {
68
68
  */
69
69
  export async function deletePolicySetById(policySetId) {
70
70
  debugMessage(`cli.PolicySetOps.deletePolicySet: begin`);
71
- showSpinner(`Deleting ${policySetId}...`);
71
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Deleting ${policySetId}...`);
72
72
  let outcome = false;
73
73
  const errors = [];
74
74
  const policies = await readPoliciesByPolicySet(policySetId);
@@ -78,21 +78,20 @@ export async function deletePolicySetById(policySetId) {
78
78
  await deletePolicy(policy._id);
79
79
  } catch (error) {
80
80
  error.message = `Error deleting policy ${policy._id} in policy set ${policySetId}: ${error}`;
81
- printMessage(error.message, 'error');
82
81
  errors.push(error);
83
82
  }
84
83
  }
85
84
  if (errors.length) {
86
85
  const errorMessages = errors.map(error => error.message).join('\n');
87
- failSpinner(`Error deleting ${policySetId}: ${errorMessages}`);
86
+ stopProgressIndicator(indicatorId, `Error deleting policies in policy set ${policySetId}: ${errorMessages}`, 'fail');
88
87
  } else {
89
88
  try {
90
89
  debugMessage(`Deleting policy set ${policySetId}`);
91
90
  await deletePolicySet(policySetId);
92
- succeedSpinner(`Deleted ${policySetId}.`);
91
+ stopProgressIndicator(indicatorId, `Deleted ${policySetId}.`, 'success');
93
92
  outcome = true;
94
93
  } catch (error) {
95
- printMessage(`Error deleting policy set ${policySetId}: ${error}`, 'error');
94
+ stopProgressIndicator(indicatorId, `Error deleting policy set ${policySetId}: ${error}`, 'fail');
96
95
  }
97
96
  }
98
97
  debugMessage(`cli.PolicySetOps.deletePolicySet: end [outcome=${outcome}]`);
@@ -108,17 +107,19 @@ export async function deletePolicySets() {
108
107
  let outcome = false;
109
108
  const errors = [];
110
109
  let policySets = [];
110
+ let indicatorId;
111
+ let indicatorId2;
111
112
  try {
112
- showSpinner(`Retrieving all policy sets...`);
113
+ indicatorId = createProgressIndicator('indeterminate', 0, `Retrieving all policy sets...`);
113
114
  try {
114
115
  policySets = await readPolicySets();
115
- succeedSpinner(`Found ${policySets.length} policy sets.`);
116
+ stopProgressIndicator(indicatorId, `Found ${policySets.length} policy sets.`, 'success');
116
117
  } catch (error) {
117
118
  error.message = `Error retrieving all policy sets: ${error.message}`;
118
- failSpinner(error.message);
119
+ stopProgressIndicator(indicatorId, error.message, 'fail');
119
120
  throw error;
120
121
  }
121
- if (policySets.length) createProgressBar(policySets.length, `Deleting ${policySets.length} policy sets...`);
122
+ if (policySets.length) indicatorId2 = createProgressIndicator('determinate', policySets.length, `Deleting ${policySets.length} policy sets...`);
122
123
  for (const policySet of policySets) {
123
124
  const policySetId = policySet.name;
124
125
  try {
@@ -139,10 +140,10 @@ export async function deletePolicySets() {
139
140
  try {
140
141
  debugMessage(`Deleting policy set ${policySetId}`);
141
142
  await deletePolicySet(policySetId);
142
- updateProgressBar(`Deleted ${policySetId}`);
143
+ updateProgressIndicator(indicatorId2, `Deleted ${policySetId}`);
143
144
  } catch (error) {
144
145
  error.message = `Error deleting policy set ${policySetId}: ${error}`;
145
- updateProgressBar(error.message);
146
+ updateProgressIndicator(indicatorId2, error.message);
146
147
  errors.push(error);
147
148
  }
148
149
  }
@@ -152,9 +153,9 @@ export async function deletePolicySets() {
152
153
  } finally {
153
154
  if (errors.length) {
154
155
  const errorMessages = errors.map(error => error.message).join('\n');
155
- if (policySets.length) stopProgressBar(`Error deleting all policy sets: ${errorMessages}`);
156
+ if (policySets.length) stopProgressIndicator(indicatorId2, `Error deleting all policy sets: ${errorMessages}`);
156
157
  } else {
157
- if (policySets.length) stopProgressBar(`Deleted ${policySets.length} policy sets.`);
158
+ if (policySets.length) stopProgressIndicator(indicatorId2, `Deleted ${policySets.length} policy sets.`);
158
159
  outcome = true;
159
160
  }
160
161
  }
@@ -176,7 +177,7 @@ export async function exportPolicySetToFile(policySetId, file, options = {
176
177
  }) {
177
178
  let outcome = false;
178
179
  debugMessage(`cli.PolicySetOps.exportPolicySetToFile: begin`);
179
- showSpinner(`Exporting ${policySetId}...`);
180
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Exporting ${policySetId}...`);
180
181
  try {
181
182
  let fileName = getTypedFilename(policySetId, 'policyset.authz');
182
183
  if (file) {
@@ -185,10 +186,10 @@ export async function exportPolicySetToFile(policySetId, file, options = {
185
186
  const filePath = getFilePath(fileName, true);
186
187
  const exportData = await exportPolicySet(policySetId, options);
187
188
  saveJsonToFile(exportData, filePath);
188
- succeedSpinner(`Exported ${policySetId} to ${filePath}.`);
189
+ stopProgressIndicator(indicatorId, `Exported ${policySetId} to ${filePath}.`, 'success');
189
190
  outcome = true;
190
191
  } catch (error) {
191
- failSpinner(`Error exporting ${policySetId}: ${error.message}`);
192
+ stopProgressIndicator(indicatorId, `Error exporting ${policySetId}: ${error.message}`, 'fail');
192
193
  }
193
194
  debugMessage(`cli.PolicySetOps.exportPolicySetToFile: end`);
194
195
  return outcome;
@@ -207,7 +208,7 @@ export async function exportPolicySetsToFile(file, options = {
207
208
  }) {
208
209
  let outcome = false;
209
210
  debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: begin`);
210
- showSpinner(`Exporting all policy sets...`);
211
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Exporting all policy sets...`);
211
212
  try {
212
213
  let fileName = getTypedFilename(`all${titleCase(getRealmName(state.getRealm()))}PolicySets`, 'policyset.authz');
213
214
  if (file) {
@@ -216,10 +217,10 @@ export async function exportPolicySetsToFile(file, options = {
216
217
  const filePath = getFilePath(fileName, true);
217
218
  const exportData = await exportPolicySets(options);
218
219
  saveJsonToFile(exportData, filePath);
219
- succeedSpinner(`Exported all policy sets to ${filePath}.`);
220
+ stopProgressIndicator(indicatorId, `Exported all policy sets to ${filePath}.`, 'success');
220
221
  outcome = true;
221
222
  } catch (error) {
222
- failSpinner(`Error exporting policy sets: ${error.message}`);
223
+ stopProgressIndicator(indicatorId, `Error exporting policy sets: ${error.message}`, 'fail');
223
224
  }
224
225
  debugMessage(`cli.PolicySetOps.exportPolicySetsToFile: end`);
225
226
  return outcome;
@@ -237,24 +238,25 @@ export async function exportPolicySetsToFiles(options = {
237
238
  }) {
238
239
  debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: begin`);
239
240
  const errors = [];
241
+ let indicatorId;
240
242
  try {
241
243
  const policySets = await readPolicySets();
242
- createProgressBar(policySets.length, 'Exporting policy sets...');
244
+ indicatorId = createProgressIndicator('determinate', policySets.length, 'Exporting policy sets...');
243
245
  for (const policySet of policySets) {
244
246
  const file = getTypedFilename(policySet.name, 'policyset.authz');
245
247
  try {
246
248
  const exportData = await exportPolicySet(policySet.name, options);
247
249
  saveJsonToFile(exportData, getFilePath(file, true));
248
- updateProgressBar(`Exported ${policySet.name}.`);
250
+ updateProgressIndicator(indicatorId, `Exported ${policySet.name}.`);
249
251
  } catch (error) {
250
252
  errors.push(error);
251
- updateProgressBar(`Error exporting ${policySet.name}.`);
253
+ updateProgressIndicator(indicatorId, `Error exporting ${policySet.name}.`);
252
254
  }
253
255
  }
254
- stopProgressBar(`Export complete.`);
256
+ stopProgressIndicator(indicatorId, `Export complete.`);
255
257
  } catch (error) {
256
258
  errors.push(error);
257
- stopProgressBar(`Error exporting policy sets to files`);
259
+ stopProgressIndicator(indicatorId, `Error exporting policy sets to files`);
258
260
  }
259
261
  debugMessage(`cli.PolicySetOps.exportPolicySetsToFiles: end`);
260
262
  return 0 === errors.length;
@@ -273,15 +275,15 @@ export async function importPolicySetFromFile(policySetId, file, options = {
273
275
  }) {
274
276
  let outcome = false;
275
277
  debugMessage(`cli.PolicySetOps.importPolicySetFromFile: begin`);
276
- showSpinner(`Importing ${policySetId}...`);
278
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Importing ${policySetId}...`);
277
279
  try {
278
280
  const data = fs.readFileSync(getFilePath(file), 'utf8');
279
281
  const fileData = JSON.parse(data);
280
282
  await importPolicySet(policySetId, fileData, options);
281
283
  outcome = true;
282
- succeedSpinner(`Imported ${policySetId}.`);
284
+ stopProgressIndicator(indicatorId, `Imported ${policySetId}.`, 'success');
283
285
  } catch (error) {
284
- failSpinner(`Error importing ${policySetId}.`);
286
+ stopProgressIndicator(indicatorId, `Error importing ${policySetId}.`, 'fail');
285
287
  printMessage(error, 'error');
286
288
  }
287
289
  debugMessage(`cli.PolicySetOps.importPolicySetFromFile: end`);
@@ -301,15 +303,15 @@ export async function importFirstPolicySetFromFile(file, options = {
301
303
  let outcome = false;
302
304
  debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: begin`);
303
305
  const filePath = getFilePath(file);
304
- showSpinner(`Importing first policy set from ${filePath}...`);
306
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Importing first policy set from ${filePath}...`);
305
307
  try {
306
308
  const data = fs.readFileSync(filePath, 'utf8');
307
309
  const fileData = JSON.parse(data);
308
310
  const policySet = await importFirstPolicySet(fileData, options);
309
311
  outcome = true;
310
- succeedSpinner(`Imported first policy set with name '${policySet.name}' from ${filePath}.`);
312
+ stopProgressIndicator(indicatorId, `Imported first policy set with name '${policySet.name}' from ${filePath}.`, 'success');
311
313
  } catch (error) {
312
- failSpinner(`Error importing first policy set from ${filePath}.`);
314
+ stopProgressIndicator(indicatorId, `Error importing first policy set from ${filePath}.`, 'fail');
313
315
  printMessage(error, 'error');
314
316
  }
315
317
  debugMessage(`cli.PolicySetOps.importFirstPolicySetFromFile: end`);
@@ -329,15 +331,15 @@ export async function importPolicySetsFromFile(file, options = {
329
331
  let outcome = false;
330
332
  debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: begin`);
331
333
  const filePath = getFilePath(file);
332
- showSpinner(`Importing ${filePath}...`);
334
+ const indicatorId = createProgressIndicator('indeterminate', 0, `Importing ${filePath}...`);
333
335
  try {
334
336
  const data = fs.readFileSync(filePath, 'utf8');
335
337
  const fileData = JSON.parse(data);
336
338
  await importPolicySets(fileData, options);
337
339
  outcome = true;
338
- succeedSpinner(`Imported ${filePath}.`);
340
+ stopProgressIndicator(indicatorId, `Imported ${filePath}.`, 'success');
339
341
  } catch (error) {
340
- failSpinner(`Error importing ${filePath}.`);
342
+ stopProgressIndicator(indicatorId, `Error importing ${filePath}.`, 'fail');
341
343
  printMessage(error, 'error');
342
344
  }
343
345
  debugMessage(`cli.PolicySetOps.importPolicySetsFromFile: end`);
@@ -354,11 +356,12 @@ export async function importPolicySetsFromFiles(options = {
354
356
  prereqs: false
355
357
  }) {
356
358
  const errors = [];
359
+ let indicatorId;
357
360
  try {
358
361
  debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: begin`);
359
362
  const names = fs.readdirSync(getWorkingDirectory());
360
363
  const files = names.filter(name => name.toLowerCase().endsWith('.policyset.authz.json')).map(name => getFilePath(name));
361
- createProgressBar(files.length, 'Importing policy sets...');
364
+ indicatorId = createProgressIndicator('determinate', files.length, 'Importing policy sets...');
362
365
  let total = 0;
363
366
  for (const file of files) {
364
367
  try {
@@ -367,17 +370,17 @@ export async function importPolicySetsFromFiles(options = {
367
370
  const count = Object.keys(fileData.policyset).length;
368
371
  total += count;
369
372
  await importPolicySets(fileData, options);
370
- updateProgressBar(`Imported ${count} policy sets from ${file}`);
373
+ updateProgressIndicator(indicatorId, `Imported ${count} policy sets from ${file}`);
371
374
  } catch (error) {
372
375
  errors.push(error);
373
- updateProgressBar(`Error importing policy sets from ${file}`);
376
+ updateProgressIndicator(indicatorId, `Error importing policy sets from ${file}`);
374
377
  printMessage(error, 'error');
375
378
  }
376
379
  }
377
- stopProgressBar(`Finished importing ${total} policy sets from ${files.length} files.`);
380
+ stopProgressIndicator(indicatorId, `Finished importing ${total} policy sets from ${files.length} files.`);
378
381
  } catch (error) {
379
382
  errors.push(error);
380
- stopProgressBar(`Error importing policy sets from files.`);
383
+ stopProgressIndicator(indicatorId, `Error importing policy sets from files.`);
381
384
  printMessage(error, 'error');
382
385
  }
383
386
  debugMessage(`cli.PolicySetOps.importPolicySetsFromFiles: end`);
@@ -1 +1 @@
1
- {"version":3,"file":"PolicySetOps.js","names":["frodo","state","fs","createObjectTable","createProgressBar","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","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","errors","policies","_id","error","push","length","errorMessages","map","join","deletePolicySets","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 createProgressBar,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\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 showSpinner(`Deleting ${policySetId}...`);\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 printMessage(error.message, 'error');\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n failSpinner(`Error deleting ${policySetId}: ${errorMessages}`);\n } else {\n try {\n debugMessage(`Deleting policy set ${policySetId}`);\n await deletePolicySet(policySetId);\n succeedSpinner(`Deleted ${policySetId}.`);\n outcome = true;\n } catch (error) {\n printMessage(\n `Error deleting policy set ${policySetId}: ${error}`,\n 'error'\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 try {\n showSpinner(`Retrieving all policy sets...`);\n try {\n policySets = await readPolicySets();\n succeedSpinner(`Found ${policySets.length} policy sets.`);\n } catch (error) {\n error.message = `Error retrieving all policy sets: ${error.message}`;\n failSpinner(error.message);\n throw error;\n }\n if (policySets.length)\n createProgressBar(\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 updateProgressBar(`Deleted ${policySetId}`);\n } catch (error) {\n error.message = `Error deleting policy set ${policySetId}: ${error}`;\n updateProgressBar(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 stopProgressBar(`Error deleting all policy sets: ${errorMessages}`);\n } else {\n if (policySets.length)\n stopProgressBar(`Deleted ${policySets.length} policy sets.`);\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 showSpinner(`Exporting ${policySetId}...`);\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 succeedSpinner(`Exported ${policySetId} to ${filePath}.`);\n outcome = true;\n } catch (error) {\n failSpinner(`Error exporting ${policySetId}: ${error.message}`);\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 showSpinner(`Exporting all policy sets...`);\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 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.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 try {\n const policySets: PolicySetSkeleton[] = await readPolicySets();\n createProgressBar(policySets.length, 'Exporting policy sets...');\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 updateProgressBar(`Exported ${policySet.name}.`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error exporting ${policySet.name}.`);\n }\n }\n stopProgressBar(`Export complete.`);\n } catch (error) {\n errors.push(error);\n stopProgressBar(`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 showSpinner(`Importing ${policySetId}...`);\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 succeedSpinner(`Imported ${policySetId}.`);\n } catch (error) {\n failSpinner(`Error importing ${policySetId}.`);\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 showSpinner(`Importing first policy set from ${filePath}...`);\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 succeedSpinner(\n `Imported first policy set with name '${policySet.name}' from ${filePath}.`\n );\n } catch (error) {\n failSpinner(`Error importing first policy set from ${filePath}.`);\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 showSpinner(`Importing ${filePath}...`);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importPolicySets(fileData, options);\n outcome = true;\n succeedSpinner(`Imported ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing ${filePath}.`);\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 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 createProgressBar(files.length, 'Importing policy sets...');\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 updateProgressBar(`Imported ${count} policy sets from ${file}`);\n } catch (error) {\n errors.push(error);\n updateProgressBar(`Error importing policy sets from ${file}`);\n printMessage(error, 'error');\n }\n }\n stopProgressBar(\n `Finished importing ${total} policy sets from ${files.length} files.`\n );\n } catch (error) {\n errors.push(error);\n stopProgressBar(`Error importing policy sets from files.`);\n printMessage(error, 'error');\n }\n debugMess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,CAAE,iDAAgD,CAAC;EAC/D,OAAO,CAAC,KAAK2C,MAAM,CAACK,MAAM;AAC5B"}
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,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,aAAa,CAACF,CAAC,CAACC,IAAI,CAAC,CAAC;IACvD,KAAK,MAAMP,SAAS,IAAIG,UAAU,EAAE;MAClCzB,YAAY,CAAE,GAAEsB,SAAS,CAACO,IAAK,EAAC,EAAE,MAAM,CAAC;IAC3C;IACAL,OAAO,GAAG,IAAI;EAChB,CAAC,CAAC,OAAOO,GAAG,EAAE;IACZ/B,YAAY,CAAE,yBAAwB+B,GAAG,CAACC,OAAQ,EAAC,EAAE,OAAO,CAAC;IA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I,IAAIsB,KAAK,EAAE;MACxB,IAAI;QACF,MAAMV,IAAI,GAAGpE,EAAE,CAACqE,YAAY,CAACb,IAAI,EAAE,MAAM,CAAC;QAC1C,MAAMc,QAAkC,GAAGC,IAAI,CAACC,KAAK,CAACJ,IAAI,CAAC;QAC3D,MAAMe,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACf,QAAQ,CAACgB,SAAS,CAAC,CAACrC,MAAM;QACpDiC,KAAK,IAAIC,KAAK;QACd,MAAM3D,gBAAgB,CAAC8C,QAAQ,EAAEb,OAAO,CAAC;QACzCnD,uBAAuB,CACrBqC,WAAW,EACV,YAAWwC,KAAM,qBAAoB3B,IAAK,EAC7C,CAAC;MACH,CAAC,CAAC,OAAOT,KAAK,EAAE;QACdH,MAAM,CAACI,IAAI,CAACD,KAAK,CAAC;QAClBzC,uBAAuB,CACrBqC,WAAW,EACV,oCAAmCa,IAAK,EAC3C,CAAC;QACDpD,YAAY,CAAC2C,KAAK,EAAE,OAAO,CAAC;MAC9B;IACF;IACA1C,qBAAqB,CACnBsC,WAAW,EACV,sBAAqBuC,KAAM,qBAAoBJ,KAAK,CAAC7B,MAAO,SAC/D,CAAC;EACH,CAAC,CAAC,OAAOF,KAAK,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,6 +1,6 @@
1
1
  import { frodo, state } from '@rockcarver/frodo-lib';
2
2
  import fs from 'fs';
3
- import { createObjectTable, createProgressBar, createTable, debugMessage, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
3
+ import { createObjectTable, createProgressIndicator, createTable, debugMessage, failSpinner, printMessage, showSpinner, stopProgressIndicator, succeedSpinner, updateProgressIndicator } from '../utils/Console';
4
4
  import { getTypedFilename, saveJsonToFile, titleCase } from '../utils/ExportImportUtils';
5
5
  const {
6
6
  getRealmName,
@@ -162,6 +162,7 @@ export async function deleteResourceTypes() {
162
162
  let outcome = false;
163
163
  const errors = [];
164
164
  let resourceTypes = [];
165
+ let indicatorId;
165
166
  try {
166
167
  showSpinner(`Retrieving all resource types...`);
167
168
  try {
@@ -172,16 +173,16 @@ export async function deleteResourceTypes() {
172
173
  failSpinner(error.message);
173
174
  throw error;
174
175
  }
175
- if (resourceTypes.length) createProgressBar(resourceTypes.length, `Deleting ${resourceTypes.length} resource types...`);
176
+ if (resourceTypes.length) indicatorId = createProgressIndicator('determinate', resourceTypes.length, `Deleting ${resourceTypes.length} resource types...`);
176
177
  for (const resourceType of resourceTypes) {
177
178
  const resourceTypeId = resourceType.uuid;
178
179
  try {
179
180
  debugMessage(`Deleting resource type ${resourceTypeId}`);
180
181
  await deleteResourceType(resourceTypeId);
181
- updateProgressBar(`Deleted ${resourceTypeId}`);
182
+ updateProgressIndicator(indicatorId, `Deleted ${resourceTypeId}`);
182
183
  } catch (error) {
183
184
  error.message = `Error deleting resource type ${resourceTypeId}: ${error}`;
184
- updateProgressBar(error.message);
185
+ updateProgressIndicator(indicatorId, error.message);
185
186
  errors.push(error);
186
187
  }
187
188
  }
@@ -191,9 +192,9 @@ export async function deleteResourceTypes() {
191
192
  } finally {
192
193
  if (errors.length) {
193
194
  const errorMessages = errors.map(error => error.message).join('\n');
194
- if (resourceTypes.length) stopProgressBar(`Error deleting all resource types: ${errorMessages}`);
195
+ if (resourceTypes.length) stopProgressIndicator(indicatorId, `Error deleting all resource types: ${errorMessages}`);
195
196
  } else {
196
- if (resourceTypes.length) stopProgressBar(`Deleted ${resourceTypes.length} resource types.`);
197
+ if (resourceTypes.length) stopProgressIndicator(indicatorId, `Deleted ${resourceTypes.length} resource types.`);
197
198
  outcome = true;
198
199
  }
199
200
  }
@@ -288,24 +289,25 @@ export async function exportResourceTypesToFile(file) {
288
289
  export async function exportResourceTypesToFiles() {
289
290
  debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: begin`);
290
291
  const errors = [];
292
+ let indicatorId;
291
293
  try {
292
294
  const resourceTypes = await readResourceTypes();
293
- createProgressBar(resourceTypes.length, 'Exporting resource types...');
295
+ indicatorId = createProgressIndicator('determinate', resourceTypes.length, 'Exporting resource types...');
294
296
  for (const resourceType of resourceTypes) {
295
297
  const file = getTypedFilename(resourceType.name, 'resourcetype.authz');
296
298
  try {
297
299
  const exportData = await exportResourceType(resourceType.uuid);
298
300
  saveJsonToFile(exportData, getFilePath(file, true));
299
- updateProgressBar(`Exported ${resourceType.name}.`);
301
+ updateProgressIndicator(indicatorId, `Exported ${resourceType.name}.`);
300
302
  } catch (error) {
301
303
  errors.push(error);
302
- updateProgressBar(`Error exporting ${resourceType.name}.`);
304
+ updateProgressIndicator(indicatorId, `Error exporting ${resourceType.name}.`);
303
305
  }
304
306
  }
305
- stopProgressBar(`Export complete.`);
307
+ stopProgressIndicator(indicatorId, `Export complete.`);
306
308
  } catch (error) {
307
309
  errors.push(error);
308
- stopProgressBar(`Error exporting resource types to files`);
310
+ stopProgressIndicator(indicatorId, `Error exporting resource types to files`);
309
311
  }
310
312
  debugMessage(`cli.ResourceTypeOps.exportResourceTypesToFiles: end`);
311
313
  return 0 === errors.length;
@@ -413,11 +415,12 @@ export async function importResourceTypesFromFile(file) {
413
415
  */
414
416
  export async function importResourceTypesFromFiles() {
415
417
  const errors = [];
418
+ let indicatorId;
416
419
  try {
417
420
  debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: begin`);
418
421
  const names = fs.readdirSync(getWorkingDirectory());
419
422
  const files = names.filter(name => name.toLowerCase().endsWith('.resourcetype.authz.json')).map(name => getFilePath(name));
420
- createProgressBar(files.length, 'Importing resource types...');
423
+ indicatorId = createProgressIndicator('determinate', files.length, 'Importing resource types...');
421
424
  let total = 0;
422
425
  for (const file of files) {
423
426
  try {
@@ -426,17 +429,17 @@ export async function importResourceTypesFromFiles() {
426
429
  const count = Object.keys(fileData.resourcetype).length;
427
430
  total += count;
428
431
  await importResourceTypes(fileData);
429
- updateProgressBar(`Imported ${count} resource types from ${file}`);
432
+ updateProgressIndicator(indicatorId, `Imported ${count} resource types from ${file}`);
430
433
  } catch (error) {
431
434
  errors.push(error);
432
- updateProgressBar(`Error importing resource types from ${file}`);
435
+ updateProgressIndicator(indicatorId, `Error importing resource types from ${file}`);
433
436
  printMessage(error, 'error');
434
437
  }
435
438
  }
436
- stopProgressBar(`Finished importing ${total} resource types from ${files.length} files.`);
439
+ stopProgressIndicator(indicatorId, `Finished importing ${total} resource types from ${files.length} files.`);
437
440
  } catch (error) {
438
441
  errors.push(error);
439
- stopProgressBar(`Error importing resource types from files.`);
442
+ stopProgressIndicator(indicatorId, `Error importing resource types from files.`);
440
443
  printMessage(error, 'error');
441
444
  }
442
445
  debugMessage(`cli.ResourceTypeOps.importResourceTypesFromFiles: end`);