@zohocorporation/vault-cli 1.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 (102) hide show
  1. package/README.md +16 -0
  2. package/out/commands/add/add.const.js +6 -0
  3. package/out/commands/add/add.types.js +2 -0
  4. package/out/commands/add/add.util.js +35 -0
  5. package/out/commands/download/download.const.js +6 -0
  6. package/out/commands/download/download.types.js +2 -0
  7. package/out/commands/download/download.utils.js +35 -0
  8. package/out/commands/generate-password/generate-password.const.js +12 -0
  9. package/out/commands/generate-password/generate-password.types.js +2 -0
  10. package/out/commands/generate-password/generate-password.utils.js +58 -0
  11. package/out/commands/generate-template/generate-template.const.js +7 -0
  12. package/out/commands/generate-template/generate-template.types.js +2 -0
  13. package/out/commands/generate-template/generate-template.util.js +37 -0
  14. package/out/commands/get/get.const.js +8 -0
  15. package/out/commands/get/get.types.js +2 -0
  16. package/out/commands/get/get.utils.js +45 -0
  17. package/out/commands/get-default/get-default.const.js +5 -0
  18. package/out/commands/get-default/get-default.types.js +2 -0
  19. package/out/commands/get-default/get-default.utils.js +33 -0
  20. package/out/commands/list/list.const.js +7 -0
  21. package/out/commands/list/list.types.js +2 -0
  22. package/out/commands/list/list.utils.js +43 -0
  23. package/out/commands/lock/lock.action.js +13 -0
  24. package/out/commands/lock/lock.js +10 -0
  25. package/out/commands/lock/lock.utils.js +52 -0
  26. package/out/commands/login/login.action.js +22 -0
  27. package/out/commands/login/login.const.js +10 -0
  28. package/out/commands/login/login.help.js +12 -0
  29. package/out/commands/login/login.js +17 -0
  30. package/out/commands/login/login.types.js +5 -0
  31. package/out/commands/login/login.utils.js +307 -0
  32. package/out/commands/reset/reset.action.js +28 -0
  33. package/out/commands/reset/reset.help.js +8 -0
  34. package/out/commands/reset/reset.js +14 -0
  35. package/out/commands/reset/reset.utils.js +2 -0
  36. package/out/commands/search/search.action.js +30 -0
  37. package/out/commands/search/search.constants.js +14 -0
  38. package/out/commands/search/search.help.js +6 -0
  39. package/out/commands/search/search.js +26 -0
  40. package/out/commands/search/search.types.js +16 -0
  41. package/out/commands/search/search.utils.js +61 -0
  42. package/out/commands/set-default/set-default.const.js +6 -0
  43. package/out/commands/set-default/set-default.types.js +2 -0
  44. package/out/commands/set-default/set-default.utils.js +39 -0
  45. package/out/commands/unlock/unlock.action.js +23 -0
  46. package/out/commands/unlock/unlock.help.js +2 -0
  47. package/out/commands/unlock/unlock.js +12 -0
  48. package/out/commands/unlock/unlock.type.js +2 -0
  49. package/out/commands/unlock/unlock.utils.js +133 -0
  50. package/out/js/I18n/index.js +80 -0
  51. package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
  52. package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
  53. package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
  54. package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
  55. package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
  56. package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
  57. package/out/js/crypto/aes.js +225 -0
  58. package/out/js/crypto/index.js +139 -0
  59. package/out/js/crypto/rsa.js +1945 -0
  60. package/out/js/crypto/zohovault.js +671 -0
  61. package/out/js/logger/index.js +10 -0
  62. package/out/old/Add.js +590 -0
  63. package/out/old/Default.js +209 -0
  64. package/out/old/Download.js +69 -0
  65. package/out/old/Generate.js +171 -0
  66. package/out/old/Get.js +225 -0
  67. package/out/old/List.js +197 -0
  68. package/out/old/Login.js +287 -0
  69. package/out/old/Logout.js +21 -0
  70. package/out/old/PasswordGenerator.js +718 -0
  71. package/out/old/PasswordPolicies.js +21 -0
  72. package/out/old/PasswordTypes.js +33 -0
  73. package/out/old/Update.js +682 -0
  74. package/out/old/cmd/addcmd.js +59 -0
  75. package/out/old/cmd/downloadcmd.js +76 -0
  76. package/out/old/cmd/generate-passwordcmd.js +127 -0
  77. package/out/old/cmd/generate-templatecmd.js +59 -0
  78. package/out/old/cmd/get-defaultcmd.js +48 -0
  79. package/out/old/cmd/getcmd.js +57 -0
  80. package/out/old/cmd/listcmd.js +54 -0
  81. package/out/old/cmd/logoutcmd.js +31 -0
  82. package/out/old/cmd/set-default.js +75 -0
  83. package/out/old/cmd/updatecmd.js +44 -0
  84. package/out/old/index.js +580 -0
  85. package/out/util/configuration.util.js +103 -0
  86. package/out/util/consts.util.js +97 -0
  87. package/out/util/dbutils/db.types.js +2 -0
  88. package/out/util/dbutils/db.utils.js +164 -0
  89. package/out/util/dbutils/dbtable.utils.js +19 -0
  90. package/out/util/dev.utils.js +14 -0
  91. package/out/util/encryptionutil/encryption.uitl.js +108 -0
  92. package/out/util/index.util.js +341 -0
  93. package/out/util/keyringutil/keyring.util.js +57 -0
  94. package/out/util/loader/loader.interface.js +2 -0
  95. package/out/util/loader/transfer.loader.js +28 -0
  96. package/out/util/login.util.js +352 -0
  97. package/out/util/passwordtypes.util.js +91 -0
  98. package/out/util/print.util.js +4 -0
  99. package/out/util/search.util.js +359 -0
  100. package/out/util/types.util.js +7 -0
  101. package/out/zv.js +41 -0
  102. package/package.json +96 -0
package/out/old/Add.js ADDED
@@ -0,0 +1,590 @@
1
+ import { Login } from "../util/login.util.js";
2
+ import { PasswordTypes } from "../util/passwordtypes.util.js";
3
+ import inquirer from "inquirer";
4
+ import { _pull, Utilities } from "../util/index.util.js";
5
+ import { Utilites } from "./index.js";
6
+ import Vault from "../js/crypto/index.js";
7
+ import path from "node:path";
8
+ import fs from "node:fs";
9
+ import { I18N } from "../js/I18n/index.js";
10
+ import * as mime from "mime-types";
11
+ import { VAULT_ENDPOINTS } from "../util/consts.util.js";
12
+ import { header } from "../commands/login/login.utils.js";
13
+ import { Logger } from "../js/logger/index.js";
14
+ let i18nText;
15
+ export class Add extends Login {
16
+ constructor(passType, file) {
17
+ super();
18
+ this.passType = passType;
19
+ this.templateFile = file;
20
+ i18nText = new I18N();
21
+ }
22
+ // Need to add I18N for induvidual password Types
23
+ async interactiveAdd() {
24
+ const passTypes = await PasswordTypes.getPasswordTypes(this.dc, undefined, undefined, true);
25
+ let template = undefined;
26
+ if (passTypes.hasOwnProperty(this.passType)) {
27
+ template = passTypes[this.passType];
28
+ }
29
+ else {
30
+ this.passType = undefined;
31
+ }
32
+ if (this.passType === undefined) {
33
+ const passChoices = [];
34
+ for (let passType in passTypes) {
35
+ passChoices.push({
36
+ name: passTypes[passType].secret_type_name,
37
+ value: passType
38
+ });
39
+ }
40
+ const answer = await inquirer.prompt([
41
+ {
42
+ type: "list", //No I18N
43
+ loop: false,
44
+ name: "passType", //No I18N
45
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_passwordType"), //No I18N
46
+ choices: passChoices
47
+ },
48
+ {
49
+ type: "list", //No I18N
50
+ name: "classification", //No I18N
51
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_classification"), //No I18N
52
+ choices: [
53
+ { name: "Personal", value: "P" }, //No I18N
54
+ { name: "Enterprise", value: "E" } //No I18N
55
+ ]
56
+ }
57
+ ]);
58
+ template = passTypes[answer.passType];
59
+ this.passType = answer.passType;
60
+ this.classification = answer.classification;
61
+ }
62
+ else {
63
+ const answer = await inquirer.prompt([
64
+ {
65
+ type: "list", //No I18N
66
+ name: "classification", //No I18N
67
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_classification"), //No I18N
68
+ choices: [
69
+ { name: "Personal", value: "P" }, //No I18N
70
+ { name: "Enterprise", value: "E" } //No I18N
71
+ ]
72
+ }
73
+ ]);
74
+ this.classification = answer.classification;
75
+ }
76
+ let folders = await _pull(header, Utilities.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_FOLDER, {
77
+ pageNum: 1,
78
+ rowPerPage: -1
79
+ });
80
+ folders = folders.data.operation.Details;
81
+ let folderChoice = [];
82
+ for (let i = 0; i < folders.length; i++) {
83
+ if (this.classification == "P") {
84
+ if (folders[i].isshared == false) {
85
+ folderChoice.push({ name: folders[i].chambername, value: folders[i].chamberid });
86
+ }
87
+ }
88
+ else if ((folders[i].sharinglevel == "110" || folders[i].sharinglevel == "140") && this.classification === "E") //changed conditon here
89
+ {
90
+ if (folders[i].ischconnotsharablesecrets == false) {
91
+ folderChoice.push({ name: folders[i].chambername, value: folders[i].chamberid });
92
+ }
93
+ }
94
+ }
95
+ folderChoice.push({ name: "Select Folder", value: "0000" });
96
+ const secret_ques_p1 = [
97
+ {
98
+ type: "input", //No I18N
99
+ name: "secretname", //No I18N
100
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_passwordName"), //No I18N
101
+ validate: Utilites.XSSValidatorWithMand,
102
+ filter: Utilites.trimText
103
+ },
104
+ {
105
+ type: "input", //No I18N
106
+ name: "description", //No I18N
107
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_desc"), //No I18N
108
+ validate: Utilites.XSSValidator,
109
+ filter: Utilites.trimText
110
+ },
111
+ {
112
+ type: "input", //No I18N
113
+ name: "secreturls", //No I18N
114
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_URL"), //No I18N
115
+ validate: Utilites.URLValidator,
116
+ filter: Utilites.trimText
117
+ },
118
+ {
119
+ type: "list", //No I18N
120
+ name: "chamberid", //No I18N
121
+ message: "Folder:", //No I18N
122
+ choices: folderChoice,
123
+ default: "0000"
124
+ }
125
+ ];
126
+ const secret_data = [];
127
+ const { secret_type_fields } = template;
128
+ this.passTypeFields = secret_type_fields;
129
+ for (let i = 0; i < secret_type_fields.length; i++) {
130
+ const field = secret_type_fields[i];
131
+ const secret_field = {
132
+ type: field.type === "password" ? "password" : "input",
133
+ mask: field.type === 'password' ? '*' : null,
134
+ name: field.name,
135
+ message: `${field.label}${field.isMandatory ? "*" : ""} : `,
136
+ validate: function (value) {
137
+ if (field.type === "file") {
138
+ if (field.isMandatory === "true" || field.isMandatory === true) {
139
+ return Utilites.mandFileValidator(value);
140
+ }
141
+ else {
142
+ return Utilites.FileValidator(value);
143
+ }
144
+ }
145
+ else {
146
+ if (field.isMandatory === "true" || field.isMandatory === true) {
147
+ if (field.type === "password") {
148
+ return Utilites.passwordMandValidator(value);
149
+ }
150
+ else {
151
+ return Utilites.mandValidator(value);
152
+ }
153
+ }
154
+ return true;
155
+ }
156
+ }
157
+ };
158
+ if (field.type !== "password") {
159
+ secret_field.filter = Utilites.trimText;
160
+ }
161
+ secret_data.push(secret_field);
162
+ }
163
+ const secret_ques_p2 = [
164
+ {
165
+ type: "input", //No I18N
166
+ name: "tags", //No I18N
167
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_tags"), //No I18N
168
+ filter: Utilites.trimText
169
+ }
170
+ ];
171
+ const secret_ques_p3 = [
172
+ {
173
+ type: "editor", //No I18N
174
+ name: "securenote", //No I18N
175
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_secureNotes"), //No I18N
176
+ filter: Utilites.trimText,
177
+ default: ""
178
+ }
179
+ ];
180
+ let ans = {
181
+ ...(await inquirer.prompt(secret_ques_p1)),
182
+ ...{ secretdata: await inquirer.prompt(secret_data) },
183
+ ...(await inquirer.prompt(secret_ques_p2)),
184
+ };
185
+ if (ans.chamberid === "0000") {
186
+ delete ans.chamberid;
187
+ }
188
+ let securenotecnfrm = await inquirer.prompt([{
189
+ type: "list", //No I18N
190
+ name: "ans", //No I18N
191
+ message: "Add Secure Notes?", //No I18N
192
+ choices: [
193
+ { name: 'Yes', value: true }, //No I18N
194
+ { name: 'No', value: false }, //No I18N
195
+ ],
196
+ default: true
197
+ }]);
198
+ if (securenotecnfrm.ans) {
199
+ let securenotes = await inquirer.prompt(secret_ques_p3);
200
+ ans.securenote = securenotes.securenote;
201
+ }
202
+ ans.customcolumnnew = [];
203
+ let customColPrompt = {
204
+ type: "list", //No I18N
205
+ name: "customcolumnnew", //No I18N
206
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_addCustomCol"), //No I18N
207
+ choices: [
208
+ { name: 'Yes', value: true }, //No I18N
209
+ { name: 'No', value: false }, //No I18N
210
+ ],
211
+ default: true
212
+ };
213
+ let customColType = {
214
+ type: "list", //No I18N
215
+ name: "type", //No I18N
216
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_colType"), //No I18N
217
+ choices: [
218
+ i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_file"), //No I18N
219
+ i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_text"), //No I18N
220
+ i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_password") //No I18N
221
+ ]
222
+ };
223
+ while ((await inquirer.prompt(customColPrompt)).customcolumnnew) {
224
+ let customType = await inquirer.prompt(customColType);
225
+ let custom_col = [
226
+ {
227
+ type: "input", //No I18N
228
+ name: "colname", //No I18N
229
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_customCol_name"), //No I18N
230
+ validate: Utilites.mandValidator,
231
+ filter: Utilites.trimText
232
+ },
233
+ {
234
+ type: customType.type === "password" ? "password" : "input",
235
+ name: "value", //No I18N
236
+ mask: customType.type === 'password' ? '*' : null,
237
+ message: i18nText.getI18nMsg("vault.add.interactiveAdd_customCol_value"), //No I18N
238
+ validate: customType.type === "file"
239
+ ? Utilites.mandFileValidator
240
+ : Utilites.XSSValidatorWithMand,
241
+ filter: Utilites.trimText
242
+ }
243
+ ];
244
+ custom_col = await inquirer.prompt(custom_col);
245
+ custom_col.type = customType.type;
246
+ ans.customcolumnnew.push(custom_col);
247
+ }
248
+ return ans;
249
+ }
250
+ formatXMLOutput(json) {
251
+ let formattedJSON = {};
252
+ json = json.secret;
253
+ formattedJSON.secretname =
254
+ json.secretname._text === undefined ? "" : json.secretname._text.trim();
255
+ formattedJSON.classification =
256
+ json.classification._text === undefined
257
+ ? ""
258
+ : json.classification._text.trim();
259
+ formattedJSON.description =
260
+ json.description._text === undefined ? "" : json.description._text.trim();
261
+ formattedJSON.secreturls = [];
262
+ if (Array.isArray(json.secreturls)) {
263
+ for (let i = 0; i < json.secreturls.length; i++) {
264
+ formattedJSON.secreturls.push(json.secreturls[i]._text.trim());
265
+ }
266
+ }
267
+ else if (json.secreturls.hasOwnProperty("_text")) {
268
+ formattedJSON.secreturls.push(json.secreturls._text.trim());
269
+ }
270
+ formattedJSON.secrettypeid =
271
+ json.secrettypeid._text === undefined
272
+ ? ""
273
+ : json.secrettypeid._text.trim();
274
+ formattedJSON.tags =
275
+ json.tags._text === undefined ? "" : json.tags._text.trim();
276
+ formattedJSON.securenote =
277
+ json.securenote._text === undefined ? "" : json.securenote._text.trim();
278
+ formattedJSON.secretdata = [];
279
+ if (Array.isArray(json.secretdata)) {
280
+ for (let i = 0; i < json.secretdata.length; i++) {
281
+ let secret = json.secretdata[i];
282
+ let formattedSecret = {};
283
+ for (let field in secret) {
284
+ formattedSecret[field] =
285
+ secret[field]._text === undefined ? "" : secret[field]._text;
286
+ }
287
+ formattedJSON.secretdata.push(formattedSecret);
288
+ }
289
+ }
290
+ else if (typeof json.secretdata === "object") {
291
+ let formattedSecret = {};
292
+ for (let field in json.secretdata) {
293
+ formattedSecret[field] =
294
+ json.secretdata[field]._text === undefined
295
+ ? ""
296
+ : json.secretdata[field]._text;
297
+ }
298
+ // if (formattedSecret === {}) {
299
+ // formattedJSON.secretdata.push(formattedSecret);
300
+ // }
301
+ }
302
+ formattedJSON.customcolumnnew = [];
303
+ if (Array.isArray(json.customcolumnnew)) {
304
+ for (let i = 0; i < json.customcolumnnew.length; i++) {
305
+ let column = json.customcolumnnew[i];
306
+ let formattedColumn = {};
307
+ for (let field in column) {
308
+ formattedColumn[field] =
309
+ column[field]._text === undefined ? "" : column[field]._text;
310
+ }
311
+ formattedJSON.customcolumnnew.push(formattedColumn);
312
+ }
313
+ }
314
+ else if (typeof json.customcolumnnew === "object") {
315
+ let formattedColumn = {};
316
+ for (let field in json.customcolumnnew) {
317
+ formattedColumn[field] =
318
+ json.customcolumnnew[field]._text === undefined
319
+ ? ""
320
+ : json.customcolumnnew[field]._text;
321
+ }
322
+ // if (formattedColumn === {}) {
323
+ // formattedJSON.customcolumnnew.push(formattedColumn);
324
+ // }
325
+ }
326
+ return formattedJSON;
327
+ }
328
+ getJSONFromTemplate() {
329
+ const ext = path.extname(this.templateFile);
330
+ let templateString;
331
+ try {
332
+ templateString = fs.readFileSync(this.templateFile, "utf-8"); //No I18N
333
+ }
334
+ catch (e) {
335
+ console.log(i18nText.getI18nMsg("vault.add.getJSONFromTemplate_problem"));
336
+ process.exit(1);
337
+ }
338
+ try {
339
+ if (ext === ".yaml" || ext === ".yml") {
340
+ return Utilites.convertFromYAML(templateString).secret;
341
+ }
342
+ else if (ext === ".xml") {
343
+ return this.formatXMLOutput(Utilites.convertFromXML(templateString));
344
+ }
345
+ else {
346
+ return JSON.parse(templateString);
347
+ }
348
+ }
349
+ catch (e) {
350
+ console.log(e.message);
351
+ Logger.error(e);
352
+ }
353
+ }
354
+ printError(validation, field) {
355
+ if (typeof validation === "string") {
356
+ console.log(`${field} - ${validation}`);
357
+ process.exit(1);
358
+ }
359
+ }
360
+ async processTemplate() {
361
+ let secret = this.getJSONFromTemplate();
362
+ let secretType;
363
+ if (secret.hasOwnProperty("secrettypeid") && secret.secrettypeid !== "") {
364
+ try {
365
+ secretType = await PasswordTypes.getPasswordTypes(this.dc, secret.secrettypeid);
366
+ secretType = secretType[secret.secrettypeid].secret_type_fields;
367
+ this.passType = secret.secrettypeid;
368
+ this.passTypeFields = secretType;
369
+ }
370
+ catch (e) {
371
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secretType_invalid"));
372
+ process.exit(1);
373
+ }
374
+ }
375
+ else {
376
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secretType_notPresent"));
377
+ }
378
+ if (secret.chamberid === "") {
379
+ delete secret.chamberid;
380
+ }
381
+ secret.secretname = secret.secretname.trim();
382
+ let validation = Utilites.XSSValidatorWithMand(secret.secretname);
383
+ this.printError(validation, i18nText.getI18nMsg("vault.add.processTemplate_secretName")); //No I18N
384
+ secret.classification = secret.classification.trim().toUpperCase();
385
+ if (secret.classification !== "P" && secret.classification !== "E") {
386
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_allowedClassification"));
387
+ process.exit();
388
+ }
389
+ validation = Utilites.XSSValidator(secret.description);
390
+ this.printError(validation, i18nText.getI18nMsg("vault.add.processTemplate_Description")); //No I18N
391
+ if (Array.isArray(secret.secreturls) && secret.secreturls.length > 0) {
392
+ for (let i = 0; i < secret.secreturls.length; i++) {
393
+ validation = Utilites.URLValidator(secret.secreturls[i]);
394
+ this.printError(validation, i18nText.getI18nMsg("vault.add.processTemplate_URL")); //No I18N
395
+ }
396
+ }
397
+ else {
398
+ secret.secreturls = [];
399
+ }
400
+ const validCols = [];
401
+ for (let i = 0; i < secret.customcolumnnew.length; i++) {
402
+ const customCol = secret.customcolumnnew[i];
403
+ if (customCol.type === "file") {
404
+ customCol.value = customCol.value.trim();
405
+ if (customCol.value !== "") {
406
+ if (typeof Utilites.FileValidator(customCol.value) !== "boolean") {
407
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_customCol_invalid"), customCol.value);
408
+ process.exit(1);
409
+ }
410
+ else {
411
+ validCols.push(customCol);
412
+ }
413
+ }
414
+ }
415
+ else {
416
+ if (customCol.value !== "") {
417
+ validCols.push(customCol);
418
+ }
419
+ }
420
+ }
421
+ secret.customcolumnnew = validCols;
422
+ if (secretType.length !== secret.secretdata.length) {
423
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secret_incomplete"));
424
+ }
425
+ let formattedSecretData = {};
426
+ for (let i = 0; i < secretType.length; i++) {
427
+ const secretCol = secretType[i];
428
+ for (let i = 0; i < secret.secretdata.length; i++) {
429
+ let templateCol = secret.secretdata[i];
430
+ if (templateCol.name === secretCol.name) {
431
+ if (secretCol.type === "file") {
432
+ templateCol.value = templateCol.value.trim();
433
+ const validation = secretCol.isMandatory
434
+ ? Utilites.mandFileValidator(templateCol.value)
435
+ : Utilites.FileValidator(templateCol.value);
436
+ if (typeof validation === "string") {
437
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secretCol_invalid"), secretCol.label);
438
+ process.exit();
439
+ }
440
+ else {
441
+ formattedSecretData[secretCol.name] = templateCol.value;
442
+ }
443
+ }
444
+ else if (secretCol.type === "text") {
445
+ templateCol.value = templateCol.value.trim();
446
+ const validation = secretCol.isMandatory
447
+ ? Utilites.XSSValidatorWithMand(templateCol.value)
448
+ : Utilites.XSSValidator(templateCol.value);
449
+ if (typeof validation === "string") {
450
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secretCol_invalid"), secretCol.label);
451
+ process.exit();
452
+ }
453
+ else {
454
+ formattedSecretData[secretCol.name] = templateCol.value;
455
+ }
456
+ }
457
+ else {
458
+ const validation = secretCol.isMandatory
459
+ ? Utilites.mandValidator(templateCol.value)
460
+ : true;
461
+ if (typeof validation === "string") {
462
+ console.log(i18nText.getI18nMsg("vault.add.processTemplate_secretCol_invalid"), secretCol.label);
463
+ process.exit();
464
+ }
465
+ else {
466
+ formattedSecretData[secretCol.name] = templateCol.value;
467
+ }
468
+ }
469
+ break;
470
+ }
471
+ }
472
+ }
473
+ secret.secretdata = formattedSecretData;
474
+ secret.tags = secret.tags.trim();
475
+ validation = Utilites.XSSValidator(secret.tags);
476
+ this.printError(validation, i18nText.getI18nMsg("vault.add.processTemplate_tags")); //No I18N
477
+ return secret;
478
+ }
479
+ async add() {
480
+ await this.getDcAndSetHeader();
481
+ this.masterKey = await this.getMasterKeyAfterConfiguration();
482
+ let template;
483
+ if (this.templateFile === undefined) {
484
+ template = await this.interactiveAdd();
485
+ }
486
+ else {
487
+ template = await this.processTemplate();
488
+ }
489
+ template.isshared = template.classification === "P" ? "NO" : "YES"; //No I18N
490
+ let key = template.isshared === "YES" ? await this.getOrgKey() : this.masterKey; //No I18N
491
+ template.encsecretname = Vault.encrypt(template.secretname, key);
492
+ if (template.description != '') {
493
+ template.encdescription = Vault.encrypt(template.description, key);
494
+ }
495
+ else {
496
+ template.encdescription = template.description;
497
+ }
498
+ if (template.tags != '') {
499
+ template.encryptedtags = Vault.encrypt(template.tags, key);
500
+ } // v2 api
501
+ else {
502
+ template.encryptedtags = template.tags;
503
+ }
504
+ template.classification = this.classification != undefined ? this.classification : template.classification; // changed this line
505
+ template.secrettypeid = this.passType;
506
+ template.secreturls = Array.isArray(template.secreturls)
507
+ ? template.secreturls
508
+ : [template.secreturls];
509
+ template.encryptedurls = [];
510
+ if (template.secreturls.length > 0) {
511
+ for (let url in template.secreturls) {
512
+ const secertUrl = template.secreturls[url];
513
+ if (secertUrl !== '') {
514
+ template.encryptedurls[url] = Vault.encrypt(secertUrl, key);
515
+ }
516
+ } //v2 api
517
+ }
518
+ else {
519
+ template.encryptedurls = [];
520
+ }
521
+ let secretDataFeilds = {};
522
+ for (let i = 0; i < this.passTypeFields.length; i++) {
523
+ secretDataFeilds[this.passTypeFields[i].name] = this.passTypeFields[i];
524
+ }
525
+ let encryptedFiles = [];
526
+ for (let column in template.secretdata) {
527
+ if (secretDataFeilds[column].type === "file" &&
528
+ template.secretdata[column] !== "") {
529
+ let absPath = template.secretdata[column];
530
+ let stats = fs.statSync(absPath);
531
+ let fileSizeInBytes = stats.size;
532
+ let fileName = path.basename(absPath);
533
+ let data = 'data:' + mime.lookup(absPath) + ';base64,' + fs.readFileSync(absPath, 'base64').toString();
534
+ encryptedFiles.push({
535
+ size: fileSizeInBytes,
536
+ data: Vault.fileEncrypt(data, key), //No I18N
537
+ name: fileName,
538
+ column: column
539
+ });
540
+ template.secretdata[column] = Vault.encrypt(column, key);
541
+ }
542
+ else {
543
+ template.secretdata[column] = Vault.encrypt(template.secretdata[column], key);
544
+ }
545
+ }
546
+ template.securenote = template.securenote === undefined ? "" : Vault.encrypt(template.securenote, key);
547
+ for (let i = 0; i < template.customcolumnnew.length; i++) {
548
+ let customCol = template.customcolumnnew[i];
549
+ customCol.id = "custColDiv_" + i;
550
+ if (customCol.type === "file") {
551
+ let absPath = customCol.value;
552
+ let stats = fs.statSync(absPath);
553
+ let fileSizeInBytes = stats.size;
554
+ let fileName = path.basename(absPath);
555
+ encryptedFiles.push({
556
+ size: fileSizeInBytes,
557
+ data: Vault.fileEncrypt('data:' + mime.lookup(customCol.value) + ';base64,' + fs.readFileSync(customCol.value, 'base64').toString(), key), //No I18N
558
+ name: fileName,
559
+ column: "customattrivalue_" + i //No I18N
560
+ });
561
+ customCol.value = Vault.encrypt("customattrivalue_" + i, key); //No I18N
562
+ }
563
+ else {
564
+ customCol.value = Vault.encrypt(customCol.value, key);
565
+ }
566
+ }
567
+ template.customcolumnnew = Vault.Base64_encode(JSON.stringify({ "customcol": template.customcolumnnew }) //No I18N
568
+ );
569
+ template.files = encryptedFiles;
570
+ let v2_template = {};
571
+ let v2_fields = ["secretname", "classification", "isshared", "policyid", "secrettypeid", "secretdata", "customcolumnnew", "securenote", "encsecretname", "encdescription", "encryptedtags", "encryptedurls", "files"]; //No I18N
572
+ for (let fields in v2_fields) {
573
+ let field = v2_fields[fields];
574
+ if ((template[v2_fields[fields]]) != undefined) {
575
+ v2_template[field] = template[v2_fields[fields]];
576
+ }
577
+ }
578
+ template = { INPUT_DATA: JSON.stringify(template) };
579
+ v2_template = { INPUT_DATA: JSON.stringify(v2_template) };
580
+ const secretResp = await _pull(header, Utilites.getVaultUrl(this.dc) + VAULT_ENDPOINTS.URL_V2_SECRETS, v2_template, "POST" //No I18N
581
+ );
582
+ if (secretResp.data.operation.result.status !== "Success") {
583
+ console.log("Error Response:" + secretResp.data.operation.result.message);
584
+ }
585
+ else {
586
+ console.log("Password Successfully Added");
587
+ }
588
+ }
589
+ }
590
+ //# sourceMappingURL=Add.js.map