@rockcarver/frodo-cli 0.10.4 → 0.11.1-2

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 (247) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +3 -3
  3. package/package.json +17 -15
  4. package/src/app.js +7 -6
  5. package/src/cli/_template/cmd-delete.js +9 -8
  6. package/src/cli/_template/cmd-describe.js +9 -8
  7. package/src/cli/_template/cmd-export.js +9 -8
  8. package/src/cli/_template/cmd-import.js +9 -8
  9. package/src/cli/_template/cmd-list.js +9 -8
  10. package/src/cli/_template/cmd-sub1-delete.js +9 -8
  11. package/src/cli/_template/cmd-sub1-describe.js +9 -8
  12. package/src/cli/_template/cmd-sub1-export.js +9 -8
  13. package/src/cli/_template/cmd-sub1-import.js +9 -8
  14. package/src/cli/_template/cmd-sub1-list.js +9 -8
  15. package/src/cli/_template/cmd-sub2-delete.js +9 -8
  16. package/src/cli/_template/cmd-sub2-describe.js +9 -8
  17. package/src/cli/_template/cmd-sub2-export.js +9 -8
  18. package/src/cli/_template/cmd-sub2-import.js +9 -8
  19. package/src/cli/_template/cmd-sub2-list.js +9 -8
  20. package/src/cli/admin/admin-add-autoid-static-user-mapping.js +12 -12
  21. package/src/cli/admin/admin-create-oauth2-client-with-admin-privileges.js +15 -18
  22. package/src/cli/admin/admin-get-access-token.js +12 -12
  23. package/src/cli/admin/admin-grant-oauth2-client-admin-privileges.js +13 -13
  24. package/src/cli/admin/admin-hide-generic-extension-attributes.js +13 -13
  25. package/src/cli/admin/admin-list-oauth2-clients-with-admin-privileges.js +13 -13
  26. package/src/cli/admin/admin-list-oauth2-clients-with-custom-privileges.js +14 -13
  27. package/src/cli/admin/admin-list-static-user-mappings.js +12 -12
  28. package/src/cli/admin/admin-remove-static-user-mapping.js +12 -12
  29. package/src/cli/admin/admin-repair-org-model.js +13 -13
  30. package/src/cli/admin/admin-revoke-oauth2-client-admin-privileges.js +13 -13
  31. package/src/cli/admin/admin-show-generic-extension-attributes.js +13 -13
  32. package/src/cli/app/app-delete.js +9 -8
  33. package/src/cli/app/app-describe.js +9 -8
  34. package/src/cli/app/app-export.js +15 -15
  35. package/src/cli/app/app-import.js +11 -11
  36. package/src/cli/app/app-list.js +11 -12
  37. package/src/cli/conn/conn-add.js +11 -11
  38. package/src/cli/conn/conn-delete.js +3 -1
  39. package/src/cli/conn/conn-describe.js +3 -1
  40. package/src/cli/conn/conn-list.js +3 -4
  41. package/src/cli/email/email-template-export.js +16 -16
  42. package/src/cli/email/email-template-import.js +16 -16
  43. package/src/cli/email/email-template-list.js +11 -11
  44. package/src/cli/esv/esv-apply.js +12 -12
  45. package/src/cli/esv/esv-secret-create.js +11 -11
  46. package/src/cli/esv/esv-secret-delete.js +13 -13
  47. package/src/cli/esv/esv-secret-describe.js +11 -11
  48. package/src/cli/esv/esv-secret-export.js +9 -8
  49. package/src/cli/esv/esv-secret-import.js +9 -8
  50. package/src/cli/esv/esv-secret-list.js +11 -11
  51. package/src/cli/esv/esv-secret-set.js +11 -11
  52. package/src/cli/esv/esv-secret-version-activate.js +12 -12
  53. package/src/cli/esv/esv-secret-version-create.js +11 -11
  54. package/src/cli/esv/esv-secret-version-deactivate.js +12 -12
  55. package/src/cli/esv/esv-secret-version-delete.js +13 -13
  56. package/src/cli/esv/esv-secret-version-list.js +11 -11
  57. package/src/cli/esv/esv-variable-create.js +11 -11
  58. package/src/cli/esv/esv-variable-delete.js +13 -16
  59. package/src/cli/esv/esv-variable-describe.js +11 -11
  60. package/src/cli/esv/esv-variable-export.js +9 -8
  61. package/src/cli/esv/esv-variable-import.js +9 -8
  62. package/src/cli/esv/esv-variable-list.js +11 -11
  63. package/src/cli/esv/esv-variable-set.js +13 -16
  64. package/src/cli/idm/idm-count.js +11 -11
  65. package/src/cli/idm/idm-export.js +16 -16
  66. package/src/cli/idm/idm-list.js +11 -11
  67. package/src/cli/idp/idp-export.js +15 -19
  68. package/src/cli/idp/idp-import.js +18 -18
  69. package/src/cli/idp/idp-list.js +12 -12
  70. package/src/cli/info/info.js +23 -19
  71. package/src/cli/journey/journey-delete.js +14 -14
  72. package/src/cli/journey/journey-describe.js +26 -35
  73. package/src/cli/journey/journey-export.js +18 -21
  74. package/src/cli/journey/journey-import.js +17 -17
  75. package/src/cli/journey/journey-list.js +12 -12
  76. package/src/cli/journey/journey-prune.js +12 -12
  77. package/src/cli/logging/logs-list.js +33 -28
  78. package/src/cli/logging/logs-tail.js +26 -22
  79. package/src/cli/realm/realm-add-custom-domain.js +13 -13
  80. package/src/cli/realm/realm-describe.js +14 -14
  81. package/src/cli/realm/realm-list.js +11 -11
  82. package/src/cli/realm/realm-remove-custom-domain.js +16 -13
  83. package/src/cli/saml/saml-cot-export.js +16 -16
  84. package/src/cli/saml/saml-cot-import.js +18 -18
  85. package/src/cli/saml/saml-cot-list.js +12 -12
  86. package/src/cli/saml/saml-describe.js +12 -12
  87. package/src/cli/saml/saml-export.js +16 -19
  88. package/src/cli/saml/saml-import.js +19 -18
  89. package/src/cli/saml/saml-list.js +12 -12
  90. package/src/cli/saml/saml-metadata-export.js +15 -19
  91. package/src/cli/script/script-delete.js +9 -8
  92. package/src/cli/script/script-describe.js +9 -8
  93. package/src/cli/script/script-export.js +18 -20
  94. package/src/cli/script/script-import.js +13 -12
  95. package/src/cli/script/script-list.js +12 -12
  96. package/src/cli/theme/theme-delete.js +17 -21
  97. package/src/cli/theme/theme-export.js +19 -18
  98. package/src/cli/theme/theme-import.js +21 -20
  99. package/src/cli/theme/theme-list.js +12 -12
  100. package/.eslintrc +0 -29
  101. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -30
  102. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  103. package/.github/README.md +0 -273
  104. package/.github/workflows/pipeline.yml +0 -487
  105. package/.prettierrc +0 -6
  106. package/CODE_OF_CONDUCT.md +0 -128
  107. package/docs/BINARIES.md +0 -22
  108. package/docs/CONTRIBUTE.md +0 -96
  109. package/docs/PIPELINE.md +0 -169
  110. package/docs/images/macos_warn1.png +0 -0
  111. package/docs/images/macos_warn2.png +0 -0
  112. package/docs/images/macos_warn3.png +0 -0
  113. package/docs/images/npm_versioning_guidelines.png +0 -0
  114. package/docs/images/release_pipeline.png +0 -0
  115. package/gulpfile.js +0 -49
  116. package/jsconfig.json +0 -6
  117. package/resources/sampleEntitiesFile.json +0 -8
  118. package/resources/sampleEnvFile.env +0 -2
  119. package/src/api/AuthenticateApi.js +0 -33
  120. package/src/api/BaseApi.js +0 -242
  121. package/src/api/CirclesOfTrustApi.js +0 -87
  122. package/src/api/EmailTemplateApi.js +0 -37
  123. package/src/api/IdmConfigApi.js +0 -88
  124. package/src/api/LogApi.js +0 -45
  125. package/src/api/ManagedObjectApi.js +0 -62
  126. package/src/api/OAuth2ClientApi.js +0 -69
  127. package/src/api/OAuth2OIDCApi.js +0 -73
  128. package/src/api/OAuth2ProviderApi.js +0 -32
  129. package/src/api/RealmApi.js +0 -99
  130. package/src/api/Saml2Api.js +0 -176
  131. package/src/api/ScriptApi.js +0 -84
  132. package/src/api/SecretsApi.js +0 -151
  133. package/src/api/ServerInfoApi.js +0 -41
  134. package/src/api/SocialIdentityProvidersApi.js +0 -114
  135. package/src/api/StartupApi.js +0 -45
  136. package/src/api/ThemeApi.js +0 -181
  137. package/src/api/TreeApi.js +0 -207
  138. package/src/api/VariablesApi.js +0 -104
  139. package/src/api/utils/ApiUtils.js +0 -77
  140. package/src/api/utils/Base64.js +0 -62
  141. package/src/cli/journey/journey-delete.e2e.test.js +0 -380
  142. package/src/cli/journey/journey-list.e2e.test.js +0 -141
  143. package/src/cli/theme/theme-delete.e2e.test.js +0 -178
  144. package/src/cli/theme/theme-list.e2e.test.js +0 -119
  145. package/src/ops/AdminOps.js +0 -901
  146. package/src/ops/AuthenticateOps.js +0 -342
  147. package/src/ops/CirclesOfTrustOps.js +0 -350
  148. package/src/ops/ConnectionProfileOps.js +0 -254
  149. package/src/ops/EmailTemplateOps.js +0 -326
  150. package/src/ops/IdmOps.js +0 -227
  151. package/src/ops/IdpOps.js +0 -342
  152. package/src/ops/JourneyOps.js +0 -2026
  153. package/src/ops/LogOps.js +0 -357
  154. package/src/ops/ManagedObjectOps.js +0 -34
  155. package/src/ops/OAuth2ClientOps.js +0 -151
  156. package/src/ops/OrganizationOps.js +0 -85
  157. package/src/ops/RealmOps.js +0 -139
  158. package/src/ops/SamlOps.js +0 -541
  159. package/src/ops/ScriptOps.js +0 -211
  160. package/src/ops/SecretsOps.js +0 -288
  161. package/src/ops/StartupOps.js +0 -114
  162. package/src/ops/ThemeOps.js +0 -379
  163. package/src/ops/VariablesOps.js +0 -185
  164. package/src/ops/templates/OAuth2ClientTemplate.json +0 -270
  165. package/src/ops/templates/OrgModelUserAttributesTemplate.json +0 -149
  166. package/src/ops/templates/cloud/GenericExtensionAttributesTemplate.json +0 -392
  167. package/src/ops/templates/cloud/managed.json +0 -4119
  168. package/src/ops/utils/Console.js +0 -434
  169. package/src/ops/utils/DataProtection.js +0 -92
  170. package/src/ops/utils/ExportImportUtils.js +0 -146
  171. package/src/ops/utils/OpsUtils.js +0 -76
  172. package/src/ops/utils/Wordwrap.js +0 -11
  173. package/src/storage/SessionStorage.js +0 -45
  174. package/test/client_cli/en/connections.test.js +0 -62
  175. package/test/client_cli/en/connections_add.test.js +0 -34
  176. package/test/client_cli/en/connections_delete.test.js +0 -34
  177. package/test/client_cli/en/connections_list.test.js +0 -34
  178. package/test/client_cli/en/email_templates.test.js +0 -77
  179. package/test/client_cli/en/email_templates_export.test.js +0 -196
  180. package/test/client_cli/en/email_templates_import.test.js +0 -145
  181. package/test/client_cli/en/email_templates_list.test.js +0 -130
  182. package/test/client_cli/en/idm.test.js +0 -111
  183. package/test/client_cli/en/idm_count.test.js +0 -121
  184. package/test/client_cli/en/idm_export.test.js +0 -136
  185. package/test/client_cli/en/idm_exportAll.test.js +0 -156
  186. package/test/client_cli/en/idm_exportAllRaw.test.js +0 -120
  187. package/test/client_cli/en/idm_import.test_.js +0 -103
  188. package/test/client_cli/en/idm_importAll.test_.js +0 -103
  189. package/test/client_cli/en/idm_list.test.js +0 -103
  190. package/test/client_cli/en/info.test.js +0 -125
  191. package/test/client_cli/en/journey.test.js +0 -127
  192. package/test/client_cli/en/journey_describe.test.js +0 -196
  193. package/test/client_cli/en/journey_export.test.js +0 -213
  194. package/test/client_cli/en/journey_import.test.js +0 -195
  195. package/test/client_cli/en/journey_importAll.test.js +0 -180
  196. package/test/client_cli/en/journey_list.test.js +0 -162
  197. package/test/client_cli/en/journey_prune.test.js +0 -148
  198. package/test/client_cli/en/logs.test.js +0 -79
  199. package/test/client_cli/en/logs_list.test.js +0 -83
  200. package/test/client_cli/en/logs_tail.test.js +0 -118
  201. package/test/client_cli/en/root.test.js +0 -91
  202. package/test/client_cli/en/script.test.js +0 -77
  203. package/test/client_cli/en/script_export.test.js +0 -213
  204. package/test/client_cli/en/script_import.test.js +0 -163
  205. package/test/client_cli/en/script_list.test.js +0 -148
  206. package/test/client_cli/utils/utils.js +0 -32
  207. package/test/e2e/journey/baseline/ForgottenUsername.journey.json +0 -216
  208. package/test/e2e/journey/baseline/Login.journey.json +0 -205
  209. package/test/e2e/journey/baseline/PasswordGrant.journey.json +0 -139
  210. package/test/e2e/journey/baseline/ProgressiveProfile.journey.json +0 -198
  211. package/test/e2e/journey/baseline/Registration.journey.json +0 -249
  212. package/test/e2e/journey/baseline/ResetPassword.journey.json +0 -268
  213. package/test/e2e/journey/baseline/UpdatePassword.journey.json +0 -323
  214. package/test/e2e/journey/baseline/allAlphaJourneys.journeys.json +0 -1520
  215. package/test/e2e/journey/delete/ForgottenUsername.journey.json +0 -216
  216. package/test/e2e/journey/delete/Login.journey.json +0 -205
  217. package/test/e2e/journey/delete/PasswordGrant.journey.json +0 -139
  218. package/test/e2e/journey/delete/ProgressiveProfile.journey.json +0 -198
  219. package/test/e2e/journey/delete/Registration.journey.json +0 -249
  220. package/test/e2e/journey/delete/ResetPassword.journey.json +0 -268
  221. package/test/e2e/journey/delete/UpdatePassword.journey.json +0 -323
  222. package/test/e2e/journey/delete/deleteMe.journey.json +0 -230
  223. package/test/e2e/journey/list/Disabled.journey.json +0 -43
  224. package/test/e2e/journey/list/ForgottenUsername.journey.json +0 -216
  225. package/test/e2e/journey/list/Login.journey.json +0 -205
  226. package/test/e2e/journey/list/PasswordGrant.journey.json +0 -139
  227. package/test/e2e/journey/list/ProgressiveProfile.journey.json +0 -198
  228. package/test/e2e/journey/list/Registration.journey.json +0 -249
  229. package/test/e2e/journey/list/ResetPassword.journey.json +0 -268
  230. package/test/e2e/journey/list/UpdatePassword.journey.json +0 -323
  231. package/test/e2e/setup.js +0 -98
  232. package/test/e2e/theme/baseline/Contrast.theme.json +0 -95
  233. package/test/e2e/theme/baseline/Highlander.theme.json +0 -95
  234. package/test/e2e/theme/baseline/Robroy.theme.json +0 -95
  235. package/test/e2e/theme/baseline/Starter-Theme.theme.json +0 -94
  236. package/test/e2e/theme/baseline/Zardoz.theme.json +0 -95
  237. package/test/e2e/theme/import/Contrast.theme.json +0 -95
  238. package/test/e2e/theme/import/Highlander.theme.json +0 -95
  239. package/test/e2e/theme/import/Robroy.theme.json +0 -95
  240. package/test/e2e/theme/import/Starter-Theme.theme.json +0 -94
  241. package/test/e2e/theme/import/Zardoz.default.theme.json +0 -95
  242. package/test/fs_tmp/.gitkeep +0 -2
  243. package/test/global/setup.js +0 -65
  244. package/test/lib_api/unit_tests/ApiUtils.test.js +0 -186
  245. package/test/lib_api/unit_tests/Base64URL.test.js +0 -22
  246. package/test/lib_api/unit_tests/DataProtection.test.js +0 -25
  247. package/test/lib_api/unit_tests/ExportImportUtils.test.js +0 -121
package/src/ops/IdmOps.js DELETED
@@ -1,227 +0,0 @@
1
- import fs from 'fs';
2
- import fse from 'fs-extra';
3
- import replaceall from 'replaceall';
4
- import propertiesReader from 'properties-reader';
5
- import {
6
- getAllConfigEntities,
7
- getConfigEntity,
8
- queryAllManagedObjectsByType,
9
- } from '../api/IdmConfigApi.js';
10
- import { printMessage, showSpinner, succeedSpinner } from './utils/Console.js';
11
- import { getTypedFilename } from './utils/ExportImportUtils.js';
12
-
13
- /**
14
- * List all IDM configuration objects
15
- */
16
- export async function listAllConfigEntities() {
17
- let configEntities = [];
18
- try {
19
- configEntities = (await getAllConfigEntities()).data;
20
- } catch (getAllConfigEntitiesError) {
21
- printMessage(getAllConfigEntitiesError, 'error');
22
- printMessage(
23
- `Error getting config entities: ${getAllConfigEntitiesError}`,
24
- 'error'
25
- );
26
- }
27
- if ('configurations' in configEntities) {
28
- configEntities.configurations.forEach((configEntity) => {
29
- printMessage(`${configEntity._id}`, 'data');
30
- });
31
- }
32
- }
33
-
34
- /**
35
- * Export an IDM configuration object.
36
- * @param {String} id the desired configuration object
37
- * @param {String} file optional export file
38
- */
39
- export async function exportConfigEntity(id, file) {
40
- let fileName = file;
41
- if (!fileName) {
42
- fileName = getTypedFilename(`${id}`, 'idm');
43
- }
44
- const configEntity = (await getConfigEntity(id)).data;
45
- fs.writeFile(fileName, JSON.stringify(configEntity, null, 2), (err) => {
46
- if (err) {
47
- return printMessage(`ERROR - can't save ${id} export to file`, 'error');
48
- }
49
- return '';
50
- });
51
- }
52
-
53
- /**
54
- * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>
55
- * @param {String} directory export directory
56
- */
57
- export async function exportAllRawConfigEntities(directory) {
58
- let configEntities = [];
59
- try {
60
- configEntities = (await getAllConfigEntities()).data;
61
- } catch (getAllConfigEntitiesError) {
62
- printMessage(getAllConfigEntitiesError, 'error');
63
- printMessage(
64
- `Error getting config entities: ${getAllConfigEntitiesError}`,
65
- 'error'
66
- );
67
- }
68
- if ('configurations' in configEntities) {
69
- if (!fs.existsSync(directory)) {
70
- fs.mkdirSync(directory);
71
- }
72
- showSpinner('Exporting config objects...');
73
- const entityPromises = [];
74
- configEntities.configurations.forEach((x) => {
75
- entityPromises.push(
76
- getConfigEntity(x._id)
77
- .then((response) => response.data)
78
- .catch((getConfigEntityError) => {
79
- if (
80
- !(
81
- getConfigEntityError.response.status === 403 &&
82
- getConfigEntityError.response.data.message ===
83
- 'This operation is not available in ForgeRock Identity Cloud.'
84
- )
85
- ) {
86
- printMessage(getConfigEntityError, 'error');
87
- printMessage(
88
- `Error getting config entity: ${getConfigEntityError}`,
89
- 'error'
90
- );
91
- }
92
- })
93
- );
94
- });
95
- Promise.all(entityPromises).then((result) => {
96
- // console.log(result);
97
- result.forEach((item) => {
98
- if (item != null) {
99
- fse.outputFile(
100
- `${directory}/${item._id}.json`,
101
- JSON.stringify(item, null, 2),
102
- // eslint-disable-next-line consistent-return
103
- (err) => {
104
- if (err) {
105
- return printMessage(
106
- `ERROR - can't save config ${item._id} to file - ${err}`,
107
- 'error'
108
- );
109
- }
110
- }
111
- );
112
- }
113
- });
114
- succeedSpinner();
115
- });
116
- }
117
- }
118
-
119
- /**
120
- * Export all IDM configuration objects
121
- * @param {String} directory export directory
122
- * @param {String} entitiesFile JSON file that specifies the config entities to export/import
123
- * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import
124
- */
125
- export async function exportAllConfigEntities(
126
- directory,
127
- entitiesFile,
128
- envFile
129
- ) {
130
- let entriesToExport = [];
131
- // read list of entities to export
132
- fs.readFile(entitiesFile, 'utf8', async (err, data) => {
133
- if (err) throw err;
134
- const entriesData = JSON.parse(data);
135
- entriesToExport = entriesData.idm;
136
- // console.log(`entriesToExport ${entriesToExport}`);
137
-
138
- // read list of configs to parameterize for environment specific values
139
- const envParams = propertiesReader(envFile);
140
-
141
- let configEntities = [];
142
- try {
143
- configEntities = (await getAllConfigEntities()).data;
144
- } catch (getAllConfigEntitiesError) {
145
- printMessage(getAllConfigEntitiesError, 'error');
146
- printMessage(
147
- `Error getting config entities: ${getAllConfigEntitiesError}`,
148
- 'error'
149
- );
150
- }
151
- if ('configurations' in configEntities) {
152
- // create export directory if not exist
153
- if (!fs.existsSync(directory)) {
154
- fs.mkdirSync(directory);
155
- }
156
- showSpinner('Exporting config objects...');
157
- const entityPromises = [];
158
- configEntities.configurations.forEach((x) => {
159
- if (entriesToExport.includes(x._id)) {
160
- // console.log(`- ${x._id}`);
161
- entityPromises.push(
162
- getConfigEntity(x._id).then((response) => response.data)
163
- );
164
- }
165
- });
166
- Promise.all(entityPromises).then((result) => {
167
- // console.log(result);
168
- result.forEach((item) => {
169
- if (item != null) {
170
- let configEntityString = JSON.stringify(item, null, 2);
171
- envParams.each((key, value) => {
172
- configEntityString = replaceall(
173
- value,
174
- `\${${key}}`,
175
- configEntityString
176
- );
177
- });
178
- fse.outputFile(
179
- `${directory}/${item._id}.json`,
180
- JSON.stringify(item, null, 2),
181
- // eslint-disable-next-line consistent-return
182
- (error) => {
183
- if (err) {
184
- return printMessage(
185
- `ERROR - can't save config ${item._id} to file - ${error}`,
186
- 'error'
187
- );
188
- }
189
- }
190
- );
191
- }
192
- });
193
- succeedSpinner();
194
- });
195
- }
196
- });
197
- }
198
-
199
- /**
200
- * Count number of managed objects of a given type
201
- * @param {String} type managed object type, e.g. alpha_user
202
- */
203
- export async function countManagedObjects(type) {
204
- let count = 0;
205
- let result = {
206
- result: [],
207
- resultCount: 0,
208
- pagedResultsCookie: null,
209
- totalPagedResultsPolicy: 'NONE',
210
- totalPagedResults: -1,
211
- remainingPagedResults: -1,
212
- };
213
- try {
214
- do {
215
- // eslint-disable-next-line no-await-in-loop
216
- result = (
217
- await queryAllManagedObjectsByType(type, [], result.pagedResultsCookie)
218
- ).data;
219
- count += result.resultCount;
220
- // printMessage(result);
221
- } while (result.pagedResultsCookie);
222
- printMessage(`${type}: ${count}`);
223
- } catch (error) {
224
- printMessage(error.response.data, 'error');
225
- printMessage(`Error querying managed objects by type: ${error}`, 'error');
226
- }
227
- }
package/src/ops/IdpOps.js DELETED
@@ -1,342 +0,0 @@
1
- import fs from 'fs';
2
- import {
3
- getSocialIdentityProviders,
4
- putProviderByTypeAndId,
5
- } from '../api/SocialIdentityProvidersApi.js';
6
- import { getScript } from '../api/ScriptApi.js';
7
- import { createOrUpdateScript } from './ScriptOps.js';
8
- import {
9
- convertBase64TextToArray,
10
- convertTextArrayToBase64,
11
- getRealmString,
12
- getTypedFilename,
13
- saveJsonToFile,
14
- validateImport,
15
- } from './utils/ExportImportUtils.js';
16
- import {
17
- printMessage,
18
- createProgressBar,
19
- updateProgressBar,
20
- stopProgressBar,
21
- } from './utils/Console.js';
22
-
23
- // use a function vs a template variable to avoid problems in loops
24
- function getFileDataTemplate() {
25
- return {
26
- meta: {},
27
- script: {},
28
- idp: {},
29
- };
30
- }
31
-
32
- /**
33
- * List providers
34
- */
35
- export async function listProviders() {
36
- getSocialIdentityProviders()
37
- .then((response) => {
38
- response.data.result.sort((a, b) => a._id.localeCompare(b._id));
39
- response.data.result.forEach((socialIdentityProvider) => {
40
- printMessage(`${socialIdentityProvider._id}`, 'data');
41
- });
42
- })
43
- .catch((err) => {
44
- printMessage(`listProviders ERROR: ${err.message}`, 'error');
45
- printMessage(err, 'error');
46
- });
47
- }
48
-
49
- /**
50
- * Get social identity provider by id
51
- * @param {String} id social identity provider id/name
52
- * @returns {Promise} a promise that resolves a social identity provider object
53
- */
54
- export async function getSocialIdentityProviderById(id) {
55
- return getSocialIdentityProviders().then((response) => {
56
- const foundProviders = response.data.result.filter(
57
- (provider) => provider._id === id
58
- );
59
- switch (foundProviders.length) {
60
- case 1:
61
- return foundProviders[0];
62
- case 0:
63
- throw new Error(`Provider '${id}' not found`);
64
- default:
65
- throw new Error(`${foundProviders.length} providers '${id}' found`);
66
- }
67
- });
68
- }
69
-
70
- /**
71
- * Export provider by id
72
- * @param {String} id provider id/name
73
- * @param {String} file optional export file name
74
- */
75
- export async function exportProvider(id, file = null) {
76
- let fileName = file;
77
- if (!fileName) {
78
- fileName = getTypedFilename(id, 'idp');
79
- }
80
- createProgressBar(1, `Exporting ${id}`);
81
- try {
82
- const idpData = await getSocialIdentityProviderById(id);
83
- updateProgressBar(`Writing file ${fileName}`);
84
- const fileData = getFileDataTemplate();
85
- fileData.idp[idpData._id] = idpData;
86
- if (idpData.transform) {
87
- const scriptData = (await getScript(idpData.transform)).data;
88
- scriptData.script = convertBase64TextToArray(scriptData.script);
89
- fileData.script[idpData.transform] = scriptData;
90
- }
91
- saveJsonToFile(fileData, fileName);
92
- stopProgressBar(`Exported ${id.brightCyan} to ${fileName.brightCyan}.`);
93
- } catch (err) {
94
- stopProgressBar(`${err}`);
95
- printMessage(`${err}`, 'error');
96
- }
97
- }
98
-
99
- /**
100
- * Export all providers
101
- * @param {String} file optional export file name
102
- */
103
- export async function exportProvidersToFile(file) {
104
- let fileName = file;
105
- if (!fileName) {
106
- fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');
107
- }
108
- const fileData = getFileDataTemplate();
109
- const allIdpsData = (await getSocialIdentityProviders()).data.result;
110
- createProgressBar(allIdpsData.length, 'Exporting providers');
111
- for (const idpData of allIdpsData) {
112
- updateProgressBar(`Exporting provider ${idpData._id}`);
113
- fileData.idp[idpData._id] = idpData;
114
- if (idpData.transform) {
115
- // eslint-disable-next-line no-await-in-loop
116
- const scriptData = (await getScript(idpData.transform)).data;
117
- scriptData.script = convertBase64TextToArray(scriptData.script);
118
- fileData.script[idpData.transform] = scriptData;
119
- }
120
- }
121
- saveJsonToFile(fileData, fileName);
122
- stopProgressBar(`${allIdpsData.length} providers exported to ${fileName}.`);
123
- }
124
-
125
- /**
126
- * Export all providers to individual files
127
- */
128
- export async function exportProvidersToFiles() {
129
- const allIdpsData = await (await getSocialIdentityProviders()).data.result;
130
- // printMessage(allIdpsData, 'data');
131
- createProgressBar(allIdpsData.length, 'Exporting providers');
132
- for (const idpData of allIdpsData) {
133
- updateProgressBar(`Writing provider ${idpData._id}`);
134
- const fileName = getTypedFilename(idpData._id, 'idp');
135
- const fileData = getFileDataTemplate();
136
- fileData.idp[idpData._id] = idpData;
137
- if (idpData.transform) {
138
- // eslint-disable-next-line no-await-in-loop
139
- const scriptData = (await getScript(idpData.transform)).data;
140
- scriptData.script = convertBase64TextToArray(scriptData.script);
141
- fileData.script[idpData.transform] = scriptData;
142
- }
143
- saveJsonToFile(fileData, fileName);
144
- }
145
- stopProgressBar(`${allIdpsData.length} providers exported.`);
146
- }
147
-
148
- /**
149
- * Import provider by id/name
150
- * @param {String} id provider id/name
151
- * @param {String} file import file name
152
- */
153
- export async function importProviderById(id, file) {
154
- fs.readFile(file, 'utf8', async (err, data) => {
155
- if (err) throw err;
156
- const fileData = JSON.parse(data);
157
- if (validateImport(fileData.meta)) {
158
- createProgressBar(1, 'Importing provider...');
159
- let found = false;
160
- for (const idpId in fileData.idp) {
161
- if ({}.hasOwnProperty.call(fileData.idp, idpId)) {
162
- if (idpId === id) {
163
- found = true;
164
- updateProgressBar(`Importing ${fileData.idp[idpId]._id}`);
165
- const scriptId = fileData.idp[idpId].transform;
166
- const scriptData = fileData.script[scriptId];
167
- if (scriptId && scriptData) {
168
- scriptData.script = convertTextArrayToBase64(scriptData.script);
169
- // eslint-disable-next-line no-await-in-loop
170
- await createOrUpdateScript(
171
- fileData.idp[idpId].transform,
172
- fileData.script[fileData.idp[idpId].transform]
173
- );
174
- }
175
- putProviderByTypeAndId(
176
- fileData.idp[idpId]._type._id,
177
- idpId,
178
- fileData.idp[idpId]
179
- )
180
- .then(() => {
181
- stopProgressBar(`Successfully imported provider ${id}.`);
182
- })
183
- .catch((importProviderErr) => {
184
- stopProgressBar(
185
- `Error importing provider ${fileData.idp[idpId]._id}`
186
- );
187
- printMessage(`\nError importing provider ${id}`, 'error');
188
- printMessage(importProviderErr.response.data, 'error');
189
- });
190
- break;
191
- }
192
- }
193
- }
194
- if (!found) {
195
- stopProgressBar(
196
- `Provider ${id.brightCyan} not found in ${file.brightCyan}!`
197
- );
198
- }
199
- } else {
200
- printMessage('Import validation failed...', 'error');
201
- }
202
- });
203
- }
204
-
205
- /**
206
- * Import first provider from file
207
- * @param {String} file import file name
208
- */
209
- export async function importFirstProvider(file) {
210
- fs.readFile(file, 'utf8', async (err, data) => {
211
- if (err) throw err;
212
- const fileData = JSON.parse(data);
213
- if (validateImport(fileData.meta)) {
214
- createProgressBar(1, 'Importing provider...');
215
- for (const idpId in fileData.idp) {
216
- if ({}.hasOwnProperty.call(fileData.idp, idpId)) {
217
- updateProgressBar(`Importing ${fileData.idp[idpId]._id}`);
218
- const scriptId = fileData.idp[idpId].transform;
219
- const scriptData = fileData.script[scriptId];
220
- if (scriptId && scriptData) {
221
- scriptData.script = convertTextArrayToBase64(scriptData.script);
222
- // eslint-disable-next-line no-await-in-loop
223
- await createOrUpdateScript(
224
- fileData.idp[idpId].transform,
225
- fileData.script[fileData.idp[idpId].transform]
226
- );
227
- }
228
- putProviderByTypeAndId(
229
- fileData.idp[idpId]._type._id,
230
- idpId,
231
- fileData.idp[idpId]
232
- ).then((result) => {
233
- if (result == null) {
234
- stopProgressBar(
235
- `Error importing provider ${fileData.idp[idpId]._id}`
236
- );
237
- printMessage(
238
- `Error importing provider ${fileData.idp[idpId]._id}`,
239
- 'error'
240
- );
241
- } else {
242
- stopProgressBar(
243
- `Successfully imported provider ${fileData.idp[idpId]._id}.`
244
- );
245
- }
246
- });
247
- break;
248
- }
249
- }
250
- } else {
251
- printMessage('Import validation failed...', 'error');
252
- }
253
- });
254
- }
255
-
256
- /**
257
- * Import all providers from file
258
- * @param {String} file import file name
259
- */
260
- export async function importProvidersFromFile(file) {
261
- fs.readFile(file, 'utf8', async (err, data) => {
262
- if (err) throw err;
263
- const fileData = JSON.parse(data);
264
- if (validateImport(fileData.meta)) {
265
- createProgressBar(
266
- Object.keys(fileData.idp).length,
267
- 'Importing providers...'
268
- );
269
- for (const idpId in fileData.idp) {
270
- if ({}.hasOwnProperty.call(fileData.idp, idpId)) {
271
- const scriptId = fileData.idp[idpId].transform;
272
- const scriptData = fileData.script[scriptId];
273
- if (scriptId && scriptData) {
274
- scriptData.script = convertTextArrayToBase64(scriptData.script);
275
- // eslint-disable-next-line no-await-in-loop
276
- await createOrUpdateScript(
277
- fileData.idp[idpId].transform,
278
- fileData.script[fileData.idp[idpId].transform]
279
- );
280
- }
281
- // eslint-disable-next-line no-await-in-loop
282
- const result = await putProviderByTypeAndId(
283
- fileData.idp[idpId]._type._id,
284
- idpId,
285
- fileData.idp[idpId]
286
- );
287
- if (!result) {
288
- updateProgressBar(
289
- `Successfully imported ${fileData.idp[idpId].name}`
290
- );
291
- }
292
- }
293
- }
294
- stopProgressBar(`Providers imported.`);
295
- } else {
296
- printMessage('Import validation failed...', 'error');
297
- }
298
- });
299
- }
300
-
301
- /**
302
- * Import providers from *.idp.json files in current working directory
303
- */
304
- export async function importProvidersFromFiles() {
305
- const names = fs.readdirSync('.');
306
- const jsonFiles = names.filter((name) =>
307
- name.toLowerCase().endsWith('.idp.json')
308
- );
309
-
310
- createProgressBar(jsonFiles.length, 'Importing providers...');
311
- let total = 0;
312
- for (const file of jsonFiles) {
313
- const data = fs.readFileSync(file, 'utf8');
314
- const fileData = JSON.parse(data);
315
- if (validateImport(fileData.meta)) {
316
- const count = Object.keys(fileData.idp).length;
317
- total += count;
318
- for (const idpId in fileData.idp) {
319
- if ({}.hasOwnProperty.call(fileData.idp, idpId)) {
320
- // eslint-disable-next-line no-await-in-loop
321
- const result = await putProviderByTypeAndId(
322
- fileData.idp[idpId]._type._id,
323
- idpId,
324
- fileData.idp[idpId]
325
- );
326
- if (result == null) {
327
- printMessage(
328
- `Error importing ${count} providers from ${file}`,
329
- 'error'
330
- );
331
- }
332
- }
333
- }
334
- updateProgressBar(`Imported ${count} provider(s) from ${file}`);
335
- } else {
336
- printMessage(`Validation of ${file} failed!`, 'error');
337
- }
338
- }
339
- stopProgressBar(
340
- `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`
341
- );
342
- }