@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
@@ -0,0 +1,209 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import Vault from "../js/crypto/index.js";
4
+ import Table from "cli-table3";
5
+ import { I18N } from "../js/I18n/index.js";
6
+ import { getDecryptedCredentials, updateTable } from "../util/dbutils/db.utils.js";
7
+ import { generateWorkspaceHash } from "../commands/login/login.utils.js";
8
+ import { encryptString } from "../util/encryptionutil/encryption.uitl.js";
9
+ let i18nText = new I18N();
10
+ export class Default {
11
+ constructor(optionCommand, command, update) {
12
+ if (!(optionCommand === undefined)) {
13
+ this.options = optionCommand;
14
+ command = (command === undefined) ? [] : command.split(',');
15
+ let unknownCommand = [];
16
+ let knownCommand = [];
17
+ this.commandNames = Object.keys(this.options);
18
+ this.commandNames = this.commandNames.map(name => name.toLowerCase());
19
+ command = command.map(name => name.toLowerCase());
20
+ for (let c in command) {
21
+ if (Object.keys(this.options).includes(command[c])) {
22
+ knownCommand.push(command[c]);
23
+ }
24
+ else {
25
+ unknownCommand.push(command[c]);
26
+ }
27
+ }
28
+ this.command = knownCommand;
29
+ if (command.length > 0 && command !== undefined) {
30
+ if (knownCommand.length === 0) {
31
+ console.log(chalk.red(i18nText.getI18nMsg("vault.defaults.noCommands")));
32
+ console.log(chalk.green(i18nText.getI18nMsg("vault.defaults.commandsSuggestion") + Object.keys(this.options).join()));
33
+ this.command = undefined;
34
+ }
35
+ else if (unknownCommand.length > 0) {
36
+ console.log(chalk.red(i18nText.getI18nMsg("vault.defaults.invalidCommand") + unknownCommand.join()));
37
+ console.log(chalk.green(i18nText.getI18nMsg("vault.defaults.commandConsidered") + knownCommand.join()));
38
+ this.command = knownCommand;
39
+ }
40
+ }
41
+ else {
42
+ this.command = undefined;
43
+ }
44
+ }
45
+ else if (command !== undefined) {
46
+ this.command = command.split(',');
47
+ }
48
+ this.update = update;
49
+ }
50
+ async setDefaults() {
51
+ const noValueOptions = {
52
+ "unlock": ["no-trust"],
53
+ "search": ["strict", "tags", "desc", "name", "verbose", "not-safe"], //No I18N
54
+ "generate-password": ["use-password-policy", "include-upper-case", "include-lower-case", "include-numbers"],
55
+ "get": ["not-safe"],
56
+ "list": ["not-safe", "verbose"]
57
+ };
58
+ const noValueCommands = Object.keys(noValueOptions);
59
+ if (this.command === undefined) {
60
+ let setCommand = await inquirer.prompt([{
61
+ name: 'answer', //No I18N
62
+ type: 'checkbox', //No I18N
63
+ message: i18nText.getI18nMsg("vault.defaults.select_command"),
64
+ choices: Object.keys(this.options)
65
+ }]);
66
+ this.command = setCommand.answer;
67
+ }
68
+ let commandOptions = {};
69
+ for (let c in this.command) {
70
+ var displayTable = new Table({
71
+ chars: {
72
+ 'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
73
+ 'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝',
74
+ 'left': '║', 'left-mid': '╟', 'mid': '─', 'mid-mid': '┼',
75
+ 'right': '║', 'right-mid': '╢', 'middle': '│'
76
+ },
77
+ wordWrap: true,
78
+ wrapWords: true,
79
+ });
80
+ if (noValueCommands.includes(this.command[c])) {
81
+ displayTable.push(["Command : " + chalk.blue.bold(this.command[c]) + "\nNote: " +
82
+ noValueOptions[this.command[c]].join(",") + " does not require any input"]);
83
+ console.log(displayTable.toString());
84
+ }
85
+ else {
86
+ console.log("Command :" + chalk.blue.bold(this.command[c]) + "\n");
87
+ }
88
+ let setOptions = await inquirer.prompt([{
89
+ name: 'answer', //No I18N
90
+ type: 'checkbox', //No I18N
91
+ message: i18nText.getI18nMsg("vault.defaults.select_option"),
92
+ choices: this.getFlagsfromOptions(this.command[c])
93
+ }]);
94
+ setOptions = setOptions.answer;
95
+ let OptionsQuestion = [];
96
+ for (let i in setOptions) {
97
+ OptionsQuestion.push({
98
+ name: setOptions[i].flag,
99
+ type: 'input', //No I18N
100
+ message: i18nText.getI18nMsg("vault.defaults.promptAnswer") + setOptions[i].name + ' -' //No I18N
101
+ });
102
+ }
103
+ let answer = await inquirer.prompt(OptionsQuestion);
104
+ Object.keys(answer).forEach((key) => {
105
+ if (typeof answer[key] === 'string') {
106
+ answer[key] = answer[key].trim();
107
+ }
108
+ });
109
+ if (Object.keys(answer).length !== 0) {
110
+ commandOptions[this.command[c]] = answer;
111
+ }
112
+ }
113
+ let credentialData = await getDecryptedCredentials(generateWorkspaceHash());
114
+ if (this.update) {
115
+ this.command = undefined;
116
+ await this.getDefaults();
117
+ commandOptions = this._mergedefaults(commandOptions, this.defaults);
118
+ }
119
+ this.sanitizeCommandOptions(commandOptions, noValueOptions);
120
+ credentialData.defaults = await encryptString(Vault.Base64_encode(JSON.stringify(commandOptions)));
121
+ updateTable(generateWorkspaceHash(), credentialData.defaults);
122
+ }
123
+ sanitizeCommandOptions(commandOptions, noValueCommands) {
124
+ for (let cmd in commandOptions) {
125
+ const commandOpts = commandOptions[cmd];
126
+ const options = noValueCommands[cmd];
127
+ for (let opt in commandOpts) {
128
+ if (options && options.includes(opt.slice(2))) {
129
+ commandOpts[opt] = true;
130
+ }
131
+ }
132
+ }
133
+ }
134
+ async getDefaults() {
135
+ let defaults = {};
136
+ let credentialData = await getDecryptedCredentials(generateWorkspaceHash());
137
+ if (credentialData.defaults === undefined) {
138
+ defaults = {};
139
+ }
140
+ else {
141
+ defaults = credentialData.defaults;
142
+ }
143
+ if (this.command === undefined) {
144
+ this.defaults = defaults;
145
+ }
146
+ else {
147
+ let newDefaults = {};
148
+ for (let i in this.command) {
149
+ if (defaults[this.command[i]] !== undefined) {
150
+ newDefaults[this.command[i]] = defaults[this.command[i]];
151
+ }
152
+ }
153
+ this.defaults = newDefaults;
154
+ }
155
+ return this.defaults;
156
+ }
157
+ formatDefaultasTable() {
158
+ let table = new Table({
159
+ head: [i18nText.getI18nMsg("vault.default.command"), i18nText.getI18nMsg("vault.default.flag"), i18nText.getI18nMsg("vault.default.value")],
160
+ wordWrap: true,
161
+ wrapWords: true,
162
+ style: { head: ['blue', 'bold'], border: ['grey'] } //No I18N
163
+ });
164
+ if (Object.keys(this.defaults).length === 0) {
165
+ table.push([{ colSpan: 3, vAlign: 'center', content: i18nText.getI18nMsg("vault.default.notConfigured") }]);
166
+ }
167
+ else {
168
+ for (let c in this.defaults) {
169
+ let flags = Object.keys(this.defaults[c]);
170
+ table.push([{ rowSpan: flags.length, vAlign: 'center', content: c }, flags[0], this.defaults[c][flags[0]]] //No I18N
171
+ );
172
+ if (flags.length !== 1) {
173
+ for (let index = 1; index < flags.length; index++) {
174
+ table.push([flags[index], this.defaults[c][flags[index]]]);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ console.log(table.toString());
180
+ }
181
+ getFlagsfromOptions(command) {
182
+ let commandOptions = this.options[command];
183
+ let output = [];
184
+ for (let opt in commandOptions) {
185
+ output.push({
186
+ name: opt,
187
+ value: { flag: commandOptions[opt].flag, name: opt }
188
+ });
189
+ }
190
+ return output;
191
+ }
192
+ _mergedefaults(json1, json2) {
193
+ let json1Keys = Object.keys(json1);
194
+ let json2Keys = Object.keys(json2);
195
+ for (let key in json1Keys) {
196
+ if (json2Keys.includes(json1Keys[key])) {
197
+ let Object1Keys = Object.keys(json1[json1Keys[key]]);
198
+ let Object2Keys = Object.keys(json2[json1Keys[key]]);
199
+ var diffdefaults = Object2Keys.filter((flag) => { return !(Object1Keys.includes(flag)); });
200
+ diffdefaults.forEach((item, index) => {
201
+ json1[json1Keys[key]][item] = json2[json1Keys[key]][item];
202
+ });
203
+ }
204
+ json2[json1Keys[key]] = json1[json1Keys[key]];
205
+ }
206
+ return json2;
207
+ }
208
+ }
209
+ //# sourceMappingURL=Default.js.map
@@ -0,0 +1,69 @@
1
+ import { Login } from "../util/login.util.js";
2
+ import { _pull, Utilities } from "../util/index.util.js";
3
+ import Vault from "../js/crypto/index.js";
4
+ import { I18N } from "../js/I18n/index.js";
5
+ import fs from "node:fs";
6
+ import { VAULT_ENDPOINTS } from "../util/consts.util.js";
7
+ import { header } from "../commands/login/login.utils.js";
8
+ import atob from "atob";
9
+ import path from "node:path";
10
+ import { Logger } from "../js/logger/index.js";
11
+ let i18nText;
12
+ export class Download extends Login {
13
+ constructor(passwordId, dir) {
14
+ super();
15
+ this.passwordId = passwordId;
16
+ if (fs.existsSync(dir)) {
17
+ this.dir = dir;
18
+ }
19
+ else {
20
+ this.dir = '';
21
+ }
22
+ i18nText = new I18N();
23
+ }
24
+ async download() {
25
+ try {
26
+ await this.getDcAndSetHeader();
27
+ this.masterKey = await this.getMasterKeyAfterConfiguration();
28
+ const resp = await _pull(header, `${Utilities.getVaultUrl(this.dc)}${VAULT_ENDPOINTS.URL_OLD_SECRETS}`, { secretId: this.passwordId, OPERATION_NAME: "GET_SECRET_FILES" }, //No I18N
29
+ "POST" //No I18N
30
+ );
31
+ const { result, details } = resp.data.operation;
32
+ if (result.status !== "success") {
33
+ console.log(i18nText.getI18nMsg("vault.download.noFiles"));
34
+ process.exit(1);
35
+ }
36
+ const files = JSON.parse(details.FILEDATA);
37
+ if (files.length === 0) {
38
+ console.log(i18nText.getI18nMsg("vault.download.noFiles"));
39
+ }
40
+ let filesDownloaded = [];
41
+ for (let i = 0; i < files.length; i++) {
42
+ var content;
43
+ const file = files[i];
44
+ var filename = file.name;
45
+ var cipherData = (file.data !== undefined) ? file.data : "";
46
+ const key = file.isShared === "YES" ? await this.getOrgKey() : this.masterKey; //No I18N
47
+ var filedata = Vault.fileDecrypt(cipherData, key);
48
+ if (filedata.split(",")[0].indexOf('base64') >= 0) {
49
+ content = atob(filedata.split(",")[1]);
50
+ }
51
+ var len = content.length, arr = new Array(len);
52
+ for (var idx = 0; idx < len; ++idx) {
53
+ arr[idx] = content.charCodeAt(idx);
54
+ }
55
+ var arrayBuffer = Buffer.from(arr);
56
+ const filePath = path.join(this.dir, filename);
57
+ Utilities.writeToFile(arrayBuffer, filePath);
58
+ filesDownloaded.push(filename);
59
+ }
60
+ console.log(i18nText.getI18nMsg("vault.download.success"));
61
+ console.log(i18nText.getI18nMsg("vault.download.filesDownloaded") + filesDownloaded.join());
62
+ }
63
+ catch (e) {
64
+ Logger.error(r);
65
+ // console.log(e)
66
+ }
67
+ }
68
+ }
69
+ //# sourceMappingURL=Download.js.map
@@ -0,0 +1,171 @@
1
+ import { Login } from "../util/login.util.js";
2
+ import { PasswordPolicies } from "./PasswordPolicies.js";
3
+ import { Utilites } from "./index.js";
4
+ import { PasswordGenerator } from "./PasswordGenerator.js";
5
+ import { PasswordTypes } from "../util/passwordtypes.util.js";
6
+ import { I18N } from "../js/I18n/index.js";
7
+ import chalk from "chalk";
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ let i18nText;
11
+ export class Generate extends Login {
12
+ constructor(policyId, templateId, type, format, outFile) {
13
+ super();
14
+ this.policyId = policyId;
15
+ this.templateId = templateId;
16
+ this.type = type;
17
+ this.format = format;
18
+ let dirPath = outFile;
19
+ if (outFile !== undefined) {
20
+ dirPath = path.parse(outFile).dir;
21
+ if ((outFile === undefined || outFile === '' || fs.existsSync(dirPath) || dirPath === '')) {
22
+ this.outFile = outFile;
23
+ }
24
+ else {
25
+ console.log(chalk.red('Invalid File Path provided'));
26
+ this.outFile = undefined;
27
+ }
28
+ }
29
+ else {
30
+ this.outFile = undefined;
31
+ }
32
+ i18nText = new I18N();
33
+ }
34
+ formatPoliciesForTable(policies) {
35
+ const arr = [];
36
+ for (let i = 0; i < policies.length; i++) {
37
+ arr.push({
38
+ SNO: i + 1,
39
+ "POLICY ID": policies[i].policy_id,
40
+ Name: policies[i].policy_name,
41
+ Description: policies[i].policy_description,
42
+ });
43
+ }
44
+ Utilites.printTable(arr);
45
+ }
46
+ formatTypesForTable(pTypes) {
47
+ const arr = [];
48
+ let i = 0;
49
+ for (const pTypeId in pTypes) {
50
+ const pType = pTypes[pTypeId];
51
+ arr.push({
52
+ SNO: ++i,
53
+ "Category ID": pTypeId, //NO I18N
54
+ "Category Name": pType.secret_type_name //NO I18N
55
+ });
56
+ }
57
+ Utilites.printTable(arr);
58
+ return arr;
59
+ }
60
+ async generatePassword() {
61
+ if (this.policyId === undefined) {
62
+ const policies = await PasswordPolicies.getPolicies(this.dc);
63
+ this.formatPoliciesForTable(policies);
64
+ this.policyId =
65
+ policies[(await Utilites.selectionPrompt(1, policies.length, i18nText.getI18nMsg("vault.selectionPrompt.Category"))) - 1 //NO I18N
66
+ ].policy_id;
67
+ }
68
+ const policy = await PasswordPolicies.getPolicies(this.dc, this.policyId);
69
+ const { characters_not_allowed, min_length, enforce_mixed_case, no_of_special_characters, start_with_alphabet, enforce_numerals, enforce_special_characters, max_length, } = policy;
70
+ PasswordGenerator.init(characters_not_allowed);
71
+ const password = PasswordGenerator.generatePassword(min_length, max_length, enforce_mixed_case, enforce_special_characters, no_of_special_characters, start_with_alphabet, enforce_numerals, true);
72
+ console.log(password);
73
+ }
74
+ async getPolicyDetails() {
75
+ await this.getDcAndSetHeader();
76
+ if (this.policyId === undefined) {
77
+ const policies = await PasswordPolicies.getPolicies(this.dc);
78
+ this.formatPoliciesForTable(policies);
79
+ this.policyId =
80
+ policies[(await Utilites.selectionPrompt(1, policies.length, i18nText.getI18nMsg("vault.selectionPrompt.policyNumber"))) - 1 //NO I18N
81
+ ].policy_id;
82
+ }
83
+ const policy = await PasswordPolicies.getPolicies(this.dc, this.policyId);
84
+ return policy;
85
+ }
86
+ async getDefaultPasswordPloicy() {
87
+ await this.getDcAndSetHeader();
88
+ let policies = await PasswordPolicies.getPolicies(this.dc);
89
+ for (let i = 0; i < policies.length; i++) {
90
+ if (policies[i].is_default_policy) {
91
+ return await PasswordPolicies.getPolicies(this.dc, policies[i].policy_id);
92
+ }
93
+ }
94
+ }
95
+ async generateTemplate() {
96
+ let template;
97
+ if (this.templateId !== undefined) {
98
+ try {
99
+ template = await PasswordTypes.getPasswordTypes(this.dc, this.templateId);
100
+ template = template[this.templateId];
101
+ }
102
+ catch (e) {
103
+ console.log(i18nText.getI18nMsg("vault.generate.templateId_invalid"));
104
+ }
105
+ }
106
+ if (template === undefined) {
107
+ const pTypes = await PasswordTypes.getPasswordTypes(this.dc, undefined, undefined, true);
108
+ const arr = this.formatTypesForTable(pTypes);
109
+ this.templateId =
110
+ arr[(await Utilites.selectionPrompt(1, arr.length, i18nText.getI18nMsg("vault.selectionPrompt.Category"))) - 1]["Category ID"]; //NO I18N
111
+ template = pTypes[this.templateId];
112
+ }
113
+ let secretData = template.secret_type_fields;
114
+ for (let i = 0; i < secretData.length; i++) {
115
+ let field = secretData[i];
116
+ field.value = "";
117
+ delete field.pii;
118
+ delete field.columnOrder;
119
+ delete field.isDeleted;
120
+ delete field.isMandatory;
121
+ }
122
+ const secret = {
123
+ secretname: "",
124
+ classification: "P|E",
125
+ description: "",
126
+ secreturls: [""],
127
+ secrettypeid: this.templateId,
128
+ secretdata: secretData,
129
+ // chamberid: "",
130
+ tags: "(comma separated)",
131
+ securenote: "",
132
+ customcolumnnew: [
133
+ {
134
+ colname: "",
135
+ value: "",
136
+ type: "file",
137
+ },
138
+ {
139
+ colname: "",
140
+ value: "",
141
+ type: "text",
142
+ },
143
+ {
144
+ colname: "",
145
+ value: "",
146
+ type: "password",
147
+ },
148
+ ],
149
+ };
150
+ if (this.format === "xml") {
151
+ Utilites.printAsXML({ secret }, this.outFile);
152
+ }
153
+ else if (this.format === "yaml") {
154
+ Utilites.printAsYML({ secret }, this.outFile);
155
+ }
156
+ else {
157
+ Utilites.printAsJSON(secret, this.outFile);
158
+ }
159
+ }
160
+ async generate() {
161
+ await this.getDcAndSetHeader();
162
+ this.masterKey = await this.getMasterKeyAfterConfiguration();
163
+ if (this.type === "template") {
164
+ await this.generateTemplate();
165
+ }
166
+ else {
167
+ await this.generatePassword();
168
+ }
169
+ }
170
+ }
171
+ //# sourceMappingURL=Generate.js.map
package/out/old/Get.js ADDED
@@ -0,0 +1,225 @@
1
+ import { Login } from "./Login.js";
2
+ import { _pull, Utilites } from "./index.js";
3
+ import { Utilities } from "../util/index.util.js";
4
+ // import { header } from "../commands/login/login.utils.js";
5
+ import { PasswordTypes } from "./PasswordTypes.js";
6
+ import { I18N } from "../js/I18n/index.js";
7
+ import wrap from "word-wrap";
8
+ import Table from "cli-table3";
9
+ import chalk from "chalk";
10
+ import { VAULT_ENDPOINTS } from "../util/consts.util.js";
11
+ import path from "node:path";
12
+ import fs from "node:fs";
13
+ let i18nText;
14
+ export class Get extends Login {
15
+ constructor(passId, outFile, output, notSafe) {
16
+ super();
17
+ this.passId = passId;
18
+ this.outFile = outFile;
19
+ this.output = output;
20
+ this.notSafe = notSafe;
21
+ i18nText = new I18N();
22
+ if (outFile !== undefined && typeof outFile === "string") {
23
+ const dirPath = path.parse(outFile).dir;
24
+ if ((outFile === undefined || outFile === '' || fs.existsSync(dirPath) || dirPath === '')) {
25
+ this.outFile = outFile;
26
+ }
27
+ else {
28
+ console.log(chalk.red('Invalid File Path provided'));
29
+ this.outFile = undefined;
30
+ }
31
+ }
32
+ else {
33
+ this.outFile = undefined;
34
+ }
35
+ }
36
+ formatDataForTable(secret) {
37
+ const table = new Table({ head: [
38
+ i18nText.getI18nMsg("vault.get.formatDataForTable_head_label"),
39
+ i18nText.getI18nMsg("vault.get.formatDataForTable_head_value")
40
+ ],
41
+ style: { head: ['blue', 'bold'], border: ['grey'] }, //NO I18N
42
+ wordWrap: true,
43
+ wrapWords: true });
44
+ table.push([
45
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_passwordId_label"),
46
+ wrap(secret.secretid)
47
+ ]);
48
+ if (secret.decsecretname != undefined) {
49
+ table.push([
50
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_passwordName_label"), //No I18N
51
+ wrap(secret.decsecretname)
52
+ ]);
53
+ }
54
+ else {
55
+ table.push([
56
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_passwordName_label"),
57
+ wrap(secret.secretname)
58
+ ]);
59
+ }
60
+ if (secret.decdescription != undefined) {
61
+ table.push([
62
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_description_label"), //No I18N
63
+ wrap(secret.decdescription)
64
+ ]);
65
+ }
66
+ else {
67
+ table.push([
68
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_description_label"),
69
+ wrap(secret.description)
70
+ ]);
71
+ }
72
+ table.push([
73
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_classification_label"),
74
+ wrap(secret.classification),
75
+ ]);
76
+ if (secret.decryptedurls != undefined) {
77
+ table.push([
78
+ i18nText.getI18nMsg("vault.get.formatDataforTable_body_URL_label"), //No I18N
79
+ wrap(secret.decryptedurls)
80
+ ]);
81
+ }
82
+ else {
83
+ table.push([
84
+ i18nText.getI18nMsg("vault.get.formatDataforTable_body_URL_label"),
85
+ wrap(secret.secreturl)
86
+ ]);
87
+ }
88
+ for (let i = 0; i < secret.secretData.length; i++) {
89
+ const secretDataField = secret.secretData[i];
90
+ let id = secretDataField["id"];
91
+ let label = secretDataField["label"];
92
+ if (id === "username") {
93
+ id = i18nText.getI18nMsg("vault.get.formatDataForTable_body_username_id");
94
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_username_label");
95
+ }
96
+ else if (id === "password") {
97
+ id = i18nText.getI18nMsg("vault.get.formatDataForTable_body_password_id");
98
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_password_label");
99
+ }
100
+ else if (id === "file") { //File Attachments
101
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_file_label");
102
+ }
103
+ else if (id === "agency") { //Health Care Agency
104
+ id = i18nText.getI18nMsg("vault.get.formatDataForTable_body_agency_id");
105
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_agency_label");
106
+ }
107
+ else if (id === "policyno") { //Health Care Agency
108
+ id = i18nText.getI18nMsg("vault.get.formatDataForTable_body_policyno_id");
109
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_policyno_label");
110
+ }
111
+ else if (id === "groupno") { //Health care Agency
112
+ id = i18nText.getI18nMsg("vault.get.formatDataForTable_body_groupno_id");
113
+ label = i18nText.getI18nMsg("vault.get.formatDataForTable_body_groupno_label");
114
+ }
115
+ else if (id === "name") { //category :- Social Security Account
116
+ id = i18nText.getI18nMsg("vault.get.formatDataTable_body_name_id");
117
+ label = i18nText.getI18nMsg("vault.get.formatDataTable_body_name_label");
118
+ }
119
+ else if (id === "ssno") { // Social Security Account
120
+ id = i18nText.getI18nMsg("vault.get.formatDataTable_body_ssno_id");
121
+ label = i18nText.getI18nMsg("vault.get.formatDataTable_body_ssno_label");
122
+ }
123
+ else if (id === "accno") { //Bank Account
124
+ id = i18nText.getI18nMsg("vault.get.formatDataTable_body_accno_id");
125
+ label = i18nText.getI18nMsg("vault.get.formatDataTable_body_accno_label");
126
+ }
127
+ else if (id === "bankid") { //Bank Account
128
+ id = i18nText.getI18nMsg("vault.get.formatDataTable_body_bankid_id");
129
+ label = i18nText.getI18nMsg("vault.get.formatDataTable_body_bankid_label");
130
+ }
131
+ table.push([
132
+ label,
133
+ wrap(secretDataField.value),
134
+ ]);
135
+ }
136
+ if (secret.customcolumn !== undefined) {
137
+ for (let i = 0; i < secret.customcolumn.customcol.length; i++) {
138
+ const customcolElement = secret.customcolumn.customcol[i];
139
+ table.push([
140
+ wrap(customcolElement.colname),
141
+ customcolElement.type === "file" ? wrap(secret.files[customcolElement.value]) : wrap(customcolElement.value, { width: 10 })
142
+ ]);
143
+ }
144
+ }
145
+ table.push([
146
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_ownername_label"),
147
+ wrap(secret.ownerdetails.USERNAME)
148
+ ]);
149
+ table.push([
150
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_owneremail_label"),
151
+ wrap(secret.ownerdetails.EMAIL)
152
+ ]);
153
+ table.push([
154
+ i18nText.getI18nMsg("vault.get.formatDataForTable_body_securenote_label"),
155
+ wrap(secret.notes)
156
+ ]);
157
+ console.log(table.toString());
158
+ }
159
+ static async getPasswrd(dc, passId) {
160
+ let passDetResp = await _pull(`${Utilites.getVaultUrl(dc)}${VAULT_ENDPOINTS.URL_SECRETS}/${passId}`);
161
+ return passDetResp.data;
162
+ }
163
+ static formatFilesArr(files) {
164
+ const filesArr = JSON.parse(files);
165
+ let filesObj = {};
166
+ for (let i = 0; i < filesArr.length; i++) {
167
+ const file = filesArr[i];
168
+ filesObj[file.column] = file.name;
169
+ }
170
+ return filesObj;
171
+ }
172
+ attachColInfoWithSecData(secData, colInfo) {
173
+ colInfo.forEach((col) => {
174
+ col.value = secData[col["name"]];
175
+ });
176
+ }
177
+ async getPassWithId() {
178
+ const { result, Details: password } = (await Get.getPasswrd(this.dc, this.passId)).operation;
179
+ if (result.status !== "Success") {
180
+ console.log(i18nText.getI18nMsg("vault.get.getPassWithId_notSuccess"));
181
+ console.log(result.message);
182
+ process.exit(1);
183
+ }
184
+ const template = await PasswordTypes.getPasswordTypes(this.dc, password.accounttype);
185
+ await this.decryptSecretObj(password, this.notSafe, template[password.accounttype]);
186
+ // this.attachColInfoWithSecData(password.secretData, template[password.accounttype].secret_type_fields);
187
+ // password.secretData = template[password.accounttype].secret_type_fields;
188
+ password.files = password.files === undefined ? {} : Get.formatFilesArr(password.files);
189
+ for (let i = 0; i < password.secretData.length; i++) {
190
+ let secretDataFeild = password.secretData[i];
191
+ delete secretDataFeild.pii;
192
+ delete secretDataFeild.columnOrder;
193
+ delete secretDataFeild.isDeleted;
194
+ delete secretDataFeild.isMandatory;
195
+ secretDataFeild.id = secretDataFeild.name;
196
+ if (secretDataFeild.type === "file") {
197
+ secretDataFeild.value = password.files[secretDataFeild.value];
198
+ }
199
+ delete secretDataFeild.name;
200
+ }
201
+ if (this.output === "xml") {
202
+ Utilities.printAsXML({ secret: password }, this.outFile, "xml");
203
+ }
204
+ else if (this.output === "yml" || this.output === "yaml") {
205
+ Utilities.printAsYAML({ secret: password }, this.outFile, this.output);
206
+ }
207
+ else if (this.output === "json") {
208
+ Utilities.printAsJSON({ secret: password }, this.outFile, "json");
209
+ }
210
+ else {
211
+ if (this.outFile !== undefined) {
212
+ console.log(chalk.red.bold(i18nText.getI18nMsg("vault.get.cantSaveTable")));
213
+ }
214
+ this.formatDataForTable(password);
215
+ }
216
+ }
217
+ async get() {
218
+ await this.getDcAndSetHeader();
219
+ this.masterKey = await this.getMasterKeyAfterConfiguration();
220
+ if (this.passId !== undefined) {
221
+ await this.getPassWithId();
222
+ }
223
+ }
224
+ }
225
+ //# sourceMappingURL=Get.js.map