@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.
- package/README.md +16 -0
- package/out/commands/add/add.const.js +6 -0
- package/out/commands/add/add.types.js +2 -0
- package/out/commands/add/add.util.js +35 -0
- package/out/commands/download/download.const.js +6 -0
- package/out/commands/download/download.types.js +2 -0
- package/out/commands/download/download.utils.js +35 -0
- package/out/commands/generate-password/generate-password.const.js +12 -0
- package/out/commands/generate-password/generate-password.types.js +2 -0
- package/out/commands/generate-password/generate-password.utils.js +58 -0
- package/out/commands/generate-template/generate-template.const.js +7 -0
- package/out/commands/generate-template/generate-template.types.js +2 -0
- package/out/commands/generate-template/generate-template.util.js +37 -0
- package/out/commands/get/get.const.js +8 -0
- package/out/commands/get/get.types.js +2 -0
- package/out/commands/get/get.utils.js +45 -0
- package/out/commands/get-default/get-default.const.js +5 -0
- package/out/commands/get-default/get-default.types.js +2 -0
- package/out/commands/get-default/get-default.utils.js +33 -0
- package/out/commands/list/list.const.js +7 -0
- package/out/commands/list/list.types.js +2 -0
- package/out/commands/list/list.utils.js +43 -0
- package/out/commands/lock/lock.action.js +13 -0
- package/out/commands/lock/lock.js +10 -0
- package/out/commands/lock/lock.utils.js +52 -0
- package/out/commands/login/login.action.js +22 -0
- package/out/commands/login/login.const.js +10 -0
- package/out/commands/login/login.help.js +12 -0
- package/out/commands/login/login.js +17 -0
- package/out/commands/login/login.types.js +5 -0
- package/out/commands/login/login.utils.js +307 -0
- package/out/commands/reset/reset.action.js +28 -0
- package/out/commands/reset/reset.help.js +8 -0
- package/out/commands/reset/reset.js +14 -0
- package/out/commands/reset/reset.utils.js +2 -0
- package/out/commands/search/search.action.js +30 -0
- package/out/commands/search/search.constants.js +14 -0
- package/out/commands/search/search.help.js +6 -0
- package/out/commands/search/search.js +26 -0
- package/out/commands/search/search.types.js +16 -0
- package/out/commands/search/search.utils.js +61 -0
- package/out/commands/set-default/set-default.const.js +6 -0
- package/out/commands/set-default/set-default.types.js +2 -0
- package/out/commands/set-default/set-default.utils.js +39 -0
- package/out/commands/unlock/unlock.action.js +23 -0
- package/out/commands/unlock/unlock.help.js +2 -0
- package/out/commands/unlock/unlock.js +12 -0
- package/out/commands/unlock/unlock.type.js +2 -0
- package/out/commands/unlock/unlock.utils.js +133 -0
- package/out/js/I18n/index.js +80 -0
- package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
- package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
- package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
- package/out/js/crypto/aes.js +225 -0
- package/out/js/crypto/index.js +139 -0
- package/out/js/crypto/rsa.js +1945 -0
- package/out/js/crypto/zohovault.js +671 -0
- package/out/js/logger/index.js +10 -0
- package/out/old/Add.js +590 -0
- package/out/old/Default.js +209 -0
- package/out/old/Download.js +69 -0
- package/out/old/Generate.js +171 -0
- package/out/old/Get.js +225 -0
- package/out/old/List.js +197 -0
- package/out/old/Login.js +287 -0
- package/out/old/Logout.js +21 -0
- package/out/old/PasswordGenerator.js +718 -0
- package/out/old/PasswordPolicies.js +21 -0
- package/out/old/PasswordTypes.js +33 -0
- package/out/old/Update.js +682 -0
- package/out/old/cmd/addcmd.js +59 -0
- package/out/old/cmd/downloadcmd.js +76 -0
- package/out/old/cmd/generate-passwordcmd.js +127 -0
- package/out/old/cmd/generate-templatecmd.js +59 -0
- package/out/old/cmd/get-defaultcmd.js +48 -0
- package/out/old/cmd/getcmd.js +57 -0
- package/out/old/cmd/listcmd.js +54 -0
- package/out/old/cmd/logoutcmd.js +31 -0
- package/out/old/cmd/set-default.js +75 -0
- package/out/old/cmd/updatecmd.js +44 -0
- package/out/old/index.js +580 -0
- package/out/util/configuration.util.js +103 -0
- package/out/util/consts.util.js +97 -0
- package/out/util/dbutils/db.types.js +2 -0
- package/out/util/dbutils/db.utils.js +164 -0
- package/out/util/dbutils/dbtable.utils.js +19 -0
- package/out/util/dev.utils.js +14 -0
- package/out/util/encryptionutil/encryption.uitl.js +108 -0
- package/out/util/index.util.js +341 -0
- package/out/util/keyringutil/keyring.util.js +57 -0
- package/out/util/loader/loader.interface.js +2 -0
- package/out/util/loader/transfer.loader.js +28 -0
- package/out/util/login.util.js +352 -0
- package/out/util/passwordtypes.util.js +91 -0
- package/out/util/print.util.js +4 -0
- package/out/util/search.util.js +359 -0
- package/out/util/types.util.js +7 -0
- package/out/zv.js +41 -0
- package/package.json +96 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import { Login } from "./Login.js";
|
|
2
|
+
import { Get } from "./Get.js";
|
|
3
|
+
import { PasswordTypes } from "./PasswordTypes.js";
|
|
4
|
+
import { Utilites, _pull } from "./index.js";
|
|
5
|
+
// import { _pull, Utilities } from "../util/index.util.js";
|
|
6
|
+
// import { header } from "../commands/login/login.utils.js";
|
|
7
|
+
import Vault from "../js/crypto/index.js";
|
|
8
|
+
import { I18N } from "../js/I18n/index.js";
|
|
9
|
+
//import { _pull, urlSecrets,urlV2Secrets, Utilites } from "./index";
|
|
10
|
+
import inquirer from "inquirer";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import { Logger } from "../js/logger/index.js";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import * as mime from "mime-types";
|
|
16
|
+
import { VAULT_ENDPOINTS } from "../util/consts.util.js";
|
|
17
|
+
// var mime = require('mime-types')
|
|
18
|
+
let i18nText;
|
|
19
|
+
export class Update extends Login {
|
|
20
|
+
constructor(id, input) {
|
|
21
|
+
super();
|
|
22
|
+
if (input !== undefined) {
|
|
23
|
+
this.input = JSON.parse(input);
|
|
24
|
+
}
|
|
25
|
+
this.id = id;
|
|
26
|
+
i18nText = new I18N();
|
|
27
|
+
}
|
|
28
|
+
async update() {
|
|
29
|
+
await this.getDcAndSetHeader();
|
|
30
|
+
this.masterKey = await this.getMasterKeyAfterConfiguration();
|
|
31
|
+
let { result, Details: password } = (await Get.getPasswrd(this.dc, this.id)).operation;
|
|
32
|
+
if (result.status !== "Success") {
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
// console.log("result: ", result, "password: ", password);
|
|
36
|
+
const template = await PasswordTypes.getPasswordTypes(this.dc, password.accounttype);
|
|
37
|
+
await this.decryptSecretObj(password, template[password.accounttype], true);
|
|
38
|
+
if (this.input.notes !== undefined) {
|
|
39
|
+
password.notes = this.input.notes;
|
|
40
|
+
}
|
|
41
|
+
delete password.creationtime;
|
|
42
|
+
delete password.secretTypeName;
|
|
43
|
+
delete password.passwordmodifiedtime;
|
|
44
|
+
delete password.sharinglevel;
|
|
45
|
+
delete password.onetimeacess;
|
|
46
|
+
delete password.autosubmit;
|
|
47
|
+
delete password.isfavourites;
|
|
48
|
+
delete password.displayaccctrlicon;
|
|
49
|
+
delete password.ownerdetails;
|
|
50
|
+
delete password.userid;
|
|
51
|
+
delete password.accesssctrlconfigured;
|
|
52
|
+
delete password.POLICYID;
|
|
53
|
+
password.secreturls = password.secretmultipleurl;
|
|
54
|
+
delete password.secretmultipleurl;
|
|
55
|
+
password.securenote = password.notes;
|
|
56
|
+
password.secrettypeid = password.accounttype;
|
|
57
|
+
delete password.notes;
|
|
58
|
+
delete password.accounttype;
|
|
59
|
+
for (const id in this.input) {
|
|
60
|
+
if (password[id] !== undefined) {
|
|
61
|
+
if (id === "secretname") {
|
|
62
|
+
const validation = Utilites.XSSValidatorWithMand(this.input[id]);
|
|
63
|
+
if (typeof validation === "string") {
|
|
64
|
+
console.log(id, validation);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
password[id] = this.input[id];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (id === "classification") {
|
|
72
|
+
if (this.input[id].toUpperCase() === "E" ||
|
|
73
|
+
this.input[id].toUpperCase() === "P") {
|
|
74
|
+
password[id] = this.input[id].toUpperCase();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(chalk.red(i18nText.getI18nMsg("vault.update.classification_allowedValues")));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const validation = Utilites.XSSValidator(this.input[id]);
|
|
83
|
+
if (typeof validation === "string") {
|
|
84
|
+
console.log(id, validation);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
password[id] = this.input[id];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
delete this.input[id];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
let key = password.isshared === "YES" ? await this.getOrgKey() : this.masterKey;
|
|
95
|
+
const oldvalues = {};
|
|
96
|
+
for (const id in this.input) {
|
|
97
|
+
for (let i = 0; i < password.secretData.length; i++) {
|
|
98
|
+
let secretField = password.secretData[i];
|
|
99
|
+
if (secretField.name === id) {
|
|
100
|
+
if (secretField.type === "file") {
|
|
101
|
+
console.log(i18nText.getI18nMsg("vault.update.fileUpdate_notSupported"));
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
else if (secretField.type === "password") {
|
|
105
|
+
if (secretField.isMandatory) {
|
|
106
|
+
if (this.input[id].trim() === "") {
|
|
107
|
+
console.log(id, i18nText.getI18nMsg("vault.update.mand_emptyFields"));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
oldvalues[secretField.name] = Vault.encrypt(secretField.value, key);
|
|
111
|
+
secretField.value = this.input[id];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (secretField.isMandatory) {
|
|
116
|
+
const validation = Utilites.XSSValidatorWithMand(this.input[id]);
|
|
117
|
+
if (typeof validation === "string") {
|
|
118
|
+
console.log(id, validation);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const validation = Utilites.XSSValidator(this.input[id]);
|
|
124
|
+
if (typeof validation === "string") {
|
|
125
|
+
console.log(id, validation);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
secretField.value = this.input[id];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
delete password.old_values;
|
|
135
|
+
for (const id in this.input) {
|
|
136
|
+
for (let i = 0; i < password.customcolumn.customcol.length; i++) {
|
|
137
|
+
let customcolElement = password.customcolumn.customcol[i];
|
|
138
|
+
if (customcolElement.id === id) {
|
|
139
|
+
if (this.input[id].trim() === "") {
|
|
140
|
+
console.log(id, i18nText.getI18nMsg("vault.update.customCol_emptyField"));
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
if (customcolElement.type === "file") {
|
|
144
|
+
console.log(i18nText.getI18nMsg("vault.update.fileUpdate_notSupported"));
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
else if (customcolElement.type === "password") {
|
|
148
|
+
const validation = Utilites.XSSValidator(this.input[id]);
|
|
149
|
+
if (typeof validation === "string") {
|
|
150
|
+
console.log(id, validation);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
customcolElement.value = this.input[id];
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const validation = Utilites.XSSValidator(this.input[id]);
|
|
157
|
+
if (typeof validation === "string") {
|
|
158
|
+
console.log(id, validation);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
customcolElement.value = this.input[id];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (let i = 0; i < password.customcolumn.customcol.length; i++) {
|
|
167
|
+
let customcolElement = password.customcolumn.customcol[i];
|
|
168
|
+
customcolElement.value = Vault.encrypt(customcolElement.value, key);
|
|
169
|
+
}
|
|
170
|
+
let formattedSecretData = {};
|
|
171
|
+
for (let i = 0; i < password.secretData.length; i++) {
|
|
172
|
+
let secretDataField = password.secretData[i];
|
|
173
|
+
formattedSecretData[secretDataField.name] = Vault.encrypt(secretDataField.value, key);
|
|
174
|
+
}
|
|
175
|
+
password.oldvalues = oldvalues;
|
|
176
|
+
password.secretdata = formattedSecretData;
|
|
177
|
+
delete password.secretData;
|
|
178
|
+
const secretId = password.secretid;
|
|
179
|
+
password.secret_auto_id = password.secretid;
|
|
180
|
+
delete password.secretid;
|
|
181
|
+
password.customcolumnnew = Vault.Base64_encode(JSON.stringify(password.customcolumn));
|
|
182
|
+
delete password.files;
|
|
183
|
+
delete password.autologon;
|
|
184
|
+
delete password.customcolumn;
|
|
185
|
+
delete password.lastmodifiedtime;
|
|
186
|
+
delete password.changepassword;
|
|
187
|
+
delete password.issharedtousers;
|
|
188
|
+
delete password.sharingtype;
|
|
189
|
+
password.securenote = Vault.encrypt(password.securenote, key);
|
|
190
|
+
password = { INPUT_DATA: JSON.stringify(password) };
|
|
191
|
+
const secretResp = await _pull(`${Utilites.getVaultUrl(this.dc)}${VAULT_ENDPOINTS.URL_SECRETS}/${secretId}`, password, "PUT");
|
|
192
|
+
if (secretResp.data.operation.result.status === "Success") {
|
|
193
|
+
console.log(i18nText.getI18nMsg("vault.update.updateSuccess"));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.log(secretResp.data.operation.result.status);
|
|
197
|
+
console.log(secretResp.data.operation.result.message);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async interactiveUpdate() {
|
|
201
|
+
await this.getDcAndSetHeader();
|
|
202
|
+
this.masterKey = await this.getMasterKeyAfterConfiguration();
|
|
203
|
+
let { result, Details: password } = (await Get.getPasswrd(this.dc, this.id)).operation;
|
|
204
|
+
if (result.status !== "Success") {
|
|
205
|
+
console.log(result.message);
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
const template = await PasswordTypes.getPasswordTypes(this.dc, password.accounttype);
|
|
209
|
+
// console.log("Templete: ", template);
|
|
210
|
+
await this.decryptSecretObj(password, true, template[password.accounttype]);
|
|
211
|
+
let fileCount = 0;
|
|
212
|
+
if (password.files !== undefined) {
|
|
213
|
+
password.files = JSON.parse(password.files);
|
|
214
|
+
fileCount = password.files.length;
|
|
215
|
+
}
|
|
216
|
+
let key = password.isshared === "YES" ? await this.getOrgKey() : this.masterKey;
|
|
217
|
+
const updateCol = [{ name: "notes", type: "input", label: "Notes" }, { name: "description", type: "input", label: "Description" }, { name: "secreturl", type: "input", label: "URL" }, { name: "secretname", type: "input", label: "Password Name" }, { name: "tags", type: "input", label: "Tags" }, { name: "classification", type: "input", label: "Classification" }];
|
|
218
|
+
let mandFields = ["secretname"];
|
|
219
|
+
let secretFields = {}; // secret fields present
|
|
220
|
+
for (let i in password.secretData) {
|
|
221
|
+
let type = password.secretData[i].type;
|
|
222
|
+
if (type === "text") {
|
|
223
|
+
type = "input";
|
|
224
|
+
}
|
|
225
|
+
secretFields[password.secretData[i].name] = password.secretData[i].value;
|
|
226
|
+
updateCol.push({ name: password.secretData[i].name, type: type, label: password.secretData[i].label });
|
|
227
|
+
if (password.secretData[i].isMandatory === true) {
|
|
228
|
+
mandFields.push(password.secretData[i].name);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let answer = await inquirer.prompt([{
|
|
232
|
+
name: "colUpdate",
|
|
233
|
+
type: "checkbox",
|
|
234
|
+
loop: false,
|
|
235
|
+
message: i18nText.getI18nMsg("vault.update.updateCol"),
|
|
236
|
+
choices: function () {
|
|
237
|
+
let colOptions = [];
|
|
238
|
+
for (let col in updateCol) {
|
|
239
|
+
colOptions.push({
|
|
240
|
+
name: updateCol[col].label,
|
|
241
|
+
value: updateCol[col]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return colOptions;
|
|
245
|
+
}
|
|
246
|
+
}]);
|
|
247
|
+
let customColAnswer = false;
|
|
248
|
+
if (password.customcolumn !== undefined && password.customcolumn.customcol.length > 0) {
|
|
249
|
+
customColAnswer = await inquirer.prompt([{
|
|
250
|
+
name: "answer",
|
|
251
|
+
type: "list", //NO I18N
|
|
252
|
+
message: i18nText.getI18nMsg("vault.update.updatecustomCol"), //NO I18N
|
|
253
|
+
choices: [
|
|
254
|
+
{ name: 'Yes', value: true }, //NO I18N
|
|
255
|
+
{ name: 'No', value: false } //NO I18N
|
|
256
|
+
],
|
|
257
|
+
default: true
|
|
258
|
+
}]);
|
|
259
|
+
customColAnswer = customColAnswer.answer;
|
|
260
|
+
}
|
|
261
|
+
let customColPrompt = [];
|
|
262
|
+
let updatePassword = { INPUT_DATA: {} };
|
|
263
|
+
let setCustomCol = {};
|
|
264
|
+
if (customColAnswer) {
|
|
265
|
+
for (let i in password.customcolumn.customcol) {
|
|
266
|
+
setCustomCol[password.customcolumn.customcol[i].id] = password.customcolumn.customcol[i];
|
|
267
|
+
let type = password.customcolumn.customcol[i].type;
|
|
268
|
+
if (type === "text") {
|
|
269
|
+
type = "input";
|
|
270
|
+
}
|
|
271
|
+
else if (type === "password") {
|
|
272
|
+
type = 'password';
|
|
273
|
+
}
|
|
274
|
+
customColPrompt.push({
|
|
275
|
+
name: password.customcolumn.customcol[i].id,
|
|
276
|
+
type: type,
|
|
277
|
+
mask: type === 'password' ? '*' : null, //No I18N
|
|
278
|
+
message: "Update Value for " + password.customcolumn.customcol[i].colname + "(" + password.customcolumn.customcol[i].id + ")", //No I18N
|
|
279
|
+
default: password.customcolumn.customcol[i].value,
|
|
280
|
+
validate: async function (value) {
|
|
281
|
+
if (type === 'file') {
|
|
282
|
+
if (value !== password.customcolumn.customcol[i].value && fs.existsSync(value) && fs.statSync(value).isFile()) {
|
|
283
|
+
if (fs.existsSync(value) && fs.statSync(value).isFile()) {
|
|
284
|
+
let fileStats = fs.statSync(value);
|
|
285
|
+
let data = 'data:' + mime.lookup(value) + ';base64,' + fs.readFileSync(value, 'base64').toString();
|
|
286
|
+
if (updatePassword.INPUT_DATA.deletedFiles === undefined) {
|
|
287
|
+
updatePassword.INPUT_DATA.deletedFiles = [];
|
|
288
|
+
}
|
|
289
|
+
updatePassword.INPUT_DATA.deletedFiles.push(password.customcolumn.customcol[i].value);
|
|
290
|
+
fileCount = fileCount - 1;
|
|
291
|
+
if (updatePassword.INPUT_DATA.files === undefined) {
|
|
292
|
+
updatePassword.INPUT_DATA.files = [];
|
|
293
|
+
}
|
|
294
|
+
updatePassword.INPUT_DATA.files.push({
|
|
295
|
+
name: path.basename(value),
|
|
296
|
+
column: password.customcolumn.customcol[i].value,
|
|
297
|
+
size: fileStats.size,
|
|
298
|
+
data: Vault.fileEncrypt(data, key)
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
return i18nText.getI18nMsg("vault.update.file_doesntExit");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
let keysecretFields = []; //secret field to update
|
|
312
|
+
const keysToUpdate = answer.colUpdate;
|
|
313
|
+
let updateVal = [];
|
|
314
|
+
for (let i in keysToUpdate) {
|
|
315
|
+
if (Object.keys(secretFields).includes(keysToUpdate[i].name)) {
|
|
316
|
+
keysecretFields.push(keysToUpdate[i].name);
|
|
317
|
+
}
|
|
318
|
+
if (keysToUpdate[i].name === 'tags') {
|
|
319
|
+
updateVal.push({
|
|
320
|
+
type: 'input',
|
|
321
|
+
name: 'add_tags',
|
|
322
|
+
message: 'Add New Tags (Comma seperated) :',
|
|
323
|
+
default: ""
|
|
324
|
+
}, {
|
|
325
|
+
type: 'input',
|
|
326
|
+
name: 'remove_tags',
|
|
327
|
+
message: 'Remove Existing Tags (Comma seperated) :',
|
|
328
|
+
default: ""
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
updateVal.push({
|
|
333
|
+
type: keysToUpdate[i].name === 'classification' ? 'list' : keysToUpdate[i].type,
|
|
334
|
+
name: keysToUpdate[i].name,
|
|
335
|
+
mask: keysToUpdate[i].type === 'password' ? '*' : null,
|
|
336
|
+
message: "Update Value for " + keysToUpdate[i].label,
|
|
337
|
+
default: keysToUpdate[i].name === 'tags' ? password.tags : null,
|
|
338
|
+
choices: function () {
|
|
339
|
+
if (keysToUpdate[i].name === 'classification') {
|
|
340
|
+
return [{ name: 'Personal', value: 'P' }, { name: 'Enterprise', value: 'E' }];
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
validate: async function (value) {
|
|
344
|
+
if (keysToUpdate[i].type === "file") {
|
|
345
|
+
try {
|
|
346
|
+
if (fs.existsSync(value) && fs.statSync(value).isFile()) {
|
|
347
|
+
let fileStats = fs.statSync(value);
|
|
348
|
+
let data = 'data:' + mime.lookup(value) + ';base64,' + fs.readFileSync(value, 'base64').toString();
|
|
349
|
+
if (password.files === undefined) {
|
|
350
|
+
updatePassword.INPUT_DATA.files = [];
|
|
351
|
+
updatePassword.INPUT_DATA.files.push({
|
|
352
|
+
name: path.basename(value),
|
|
353
|
+
column: "file",
|
|
354
|
+
size: fileStats.size,
|
|
355
|
+
data: Vault.fileEncrypt(data, key)
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
for (let file in password.files) {
|
|
360
|
+
if (password.files[file].column === "file") {
|
|
361
|
+
fileCount = fileCount - 1;
|
|
362
|
+
if (updatePassword.INPUT_DATA.deletedFiles === undefined) {
|
|
363
|
+
updatePassword.INPUT_DATA.deletedFiles = ["file"];
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
updatePassword.INPUT_DATA.deletedFiles.push("file");
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (updatePassword.INPUT_DATA.files === undefined || updatePassword.INPUT_DATA.files.length === 0) {
|
|
372
|
+
updatePassword.INPUT_DATA.files = [];
|
|
373
|
+
}
|
|
374
|
+
updatePassword.INPUT_DATA.files.push({
|
|
375
|
+
name: path.basename(value),
|
|
376
|
+
column: "file",
|
|
377
|
+
size: fileStats.size,
|
|
378
|
+
data: Vault.fileEncrypt(data, key)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
if (keysToUpdate[i].isMandatory === "true") {
|
|
382
|
+
return Utilites.mandFileValidator(value);
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
return Utilites.FileValidator(value);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
return i18nText.getI18nMsg("vault.update.file_doesntExit");
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
catch (e) {
|
|
393
|
+
Logger.error(e);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
if (mandFields.includes(keysToUpdate[i].name)) {
|
|
398
|
+
if (keysToUpdate[i].type === 'password') {
|
|
399
|
+
return Utilites.passwordMandValidator(value);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
return Utilites.mandValidator(value);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
filter: function (value) {
|
|
409
|
+
if (keysToUpdate[i].type !== "password") {
|
|
410
|
+
value = Utilites.trimText(value);
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
updateVal = await inquirer.prompt(updateVal);
|
|
418
|
+
let customColUpdateAnswer = await inquirer.prompt(customColPrompt);
|
|
419
|
+
let passwordmodified = false;
|
|
420
|
+
if (keysecretFields.includes("password")) {
|
|
421
|
+
passwordmodified = true;
|
|
422
|
+
}
|
|
423
|
+
updatePassword.INPUT_DATA.passwordmodified = passwordmodified;
|
|
424
|
+
updatePassword.INPUT_DATA.secretdata = {};
|
|
425
|
+
updatePassword.INPUT_DATA.oldvalues = {};
|
|
426
|
+
if (password.notes !== undefined) {
|
|
427
|
+
if (updateVal.notes === undefined) {
|
|
428
|
+
updatePassword.INPUT_DATA.securenote = Vault.encrypt(password.notes, key);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
updatePassword.INPUT_DATA.securenote = Vault.encrypt(updateVal.notes, key);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
let keyfield = Object.keys(secretFields);
|
|
435
|
+
for (let field in keyfield) {
|
|
436
|
+
if (updateVal[keyfield[field]] === undefined) {
|
|
437
|
+
updatePassword.INPUT_DATA.secretdata[keyfield[field]] = Vault.encrypt(secretFields[keyfield[field]], key);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
if (keyfield[field] === "file") {
|
|
441
|
+
updatePassword.INPUT_DATA.secretdata[keyfield[field]] = Vault.encrypt("file", key);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
updatePassword.INPUT_DATA.oldvalues[keyfield[field]] = Vault.encrypt(secretFields[keyfield[field]], key);
|
|
445
|
+
updatePassword.INPUT_DATA.secretdata[keyfield[field]] = Vault.encrypt(updateVal[keyfield[field]], key);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
updatePassword.INPUT_DATA.secrettypeid = password.accounttype;
|
|
450
|
+
updatePassword.INPUT_DATA.classification = updateVal.classification === undefined ? password.classification : updateVal.classification;
|
|
451
|
+
updatePassword.INPUT_DATA.secretname = updateVal.secretname === undefined ? password.secretname : updateVal.secretname;
|
|
452
|
+
updatePassword.INPUT_DATA.isshared = password.isshared;
|
|
453
|
+
let secreturls = [];
|
|
454
|
+
if (updateVal.secreturl !== undefined) {
|
|
455
|
+
secreturls = updateVal.secreturl.split(",");
|
|
456
|
+
}
|
|
457
|
+
updatePassword.INPUT_DATA.secreturls = secreturls;
|
|
458
|
+
updatePassword.INPUT_DATA.customcolumnnew = {};
|
|
459
|
+
updatePassword.INPUT_DATA.customcolumnnew.customcol = [];
|
|
460
|
+
if (customColAnswer) {
|
|
461
|
+
for (let col in customColUpdateAnswer) {
|
|
462
|
+
if (setCustomCol[col].type === 'file') {
|
|
463
|
+
for (let file in updatePassword.INPUT_DATA.files) {
|
|
464
|
+
if (updatePassword.INPUT_DATA.files[file].name === path.basename(customColUpdateAnswer[col])) {
|
|
465
|
+
setCustomCol[col].value = Vault.encrypt(updatePassword.INPUT_DATA.files[file].column, key);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
setCustomCol[col].value = Vault.encrypt(customColUpdateAnswer[col], key);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
if (password.customcolumn != undefined) {
|
|
476
|
+
for (let col in password.customcolumn.customcol) {
|
|
477
|
+
setCustomCol[col] = password.customcolumn.customcol[col];
|
|
478
|
+
setCustomCol[col].value = Vault.encrypt(password.customcolumn.customcol[col].value, key);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (setCustomCol != null) {
|
|
483
|
+
for (let col in setCustomCol) {
|
|
484
|
+
updatePassword.INPUT_DATA.customcolumnnew.customcol.push(setCustomCol[col]);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
let cusColPrompt = {
|
|
488
|
+
type: "list", //No I18N
|
|
489
|
+
name: "customcolumnnew", //No I18N
|
|
490
|
+
message: i18nText.getI18nMsg("vault.add.interactiveAdd_addCustomCol"), //No I18N
|
|
491
|
+
choices: [
|
|
492
|
+
{ name: 'Yes', value: true }, //No I18N
|
|
493
|
+
{ name: 'No', value: false } //No I18N
|
|
494
|
+
],
|
|
495
|
+
default: true
|
|
496
|
+
};
|
|
497
|
+
let customColType = {
|
|
498
|
+
type: "list", //No I18N
|
|
499
|
+
name: "type", //No I18N
|
|
500
|
+
message: i18nText.getI18nMsg("vault.add.interactiveAdd_colType"), //No I18N
|
|
501
|
+
choices: [
|
|
502
|
+
{ name: i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_file"), value: "file" }, //No I18N
|
|
503
|
+
{ name: i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_text"), value: "text" }, //No I18N
|
|
504
|
+
{ name: i18nText.getI18nMsg("vault.add.interactiveAdd_option_colType_password"), value: "password" } //No I18N
|
|
505
|
+
]
|
|
506
|
+
};
|
|
507
|
+
let ans = [];
|
|
508
|
+
while ((await inquirer.prompt(cusColPrompt)).customcolumnnew) {
|
|
509
|
+
let customType = await inquirer.prompt(customColType);
|
|
510
|
+
let custom_col = [
|
|
511
|
+
{
|
|
512
|
+
type: "input", //No I18N
|
|
513
|
+
name: "colname", //No I18N
|
|
514
|
+
message: i18nText.getI18nMsg("vault.add.interactiveAdd_customCol_name"), //No I18N
|
|
515
|
+
validate: Utilites.mandValidator,
|
|
516
|
+
filter: Utilites.trimText
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
type: customType.type === "password" ? "password" : "input",
|
|
520
|
+
mask: customType.type === 'password' ? '*' : null,
|
|
521
|
+
name: "value", //No I18N
|
|
522
|
+
message: i18nText.getI18nMsg("vault.add.interactiveAdd_customCol_value"), //No I18N
|
|
523
|
+
validate: function (value) {
|
|
524
|
+
if (customType.type === "file") {
|
|
525
|
+
if (fs.existsSync(value) && fs.statSync(value).isFile()) {
|
|
526
|
+
return Utilites.mandFileValidator(value);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
return i18nText.getI18nMsg("vault.update.file_doesntExit");
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
filter: function (ans) {
|
|
537
|
+
if (customType.type !== "password") {
|
|
538
|
+
return Utilites.trimText(ans);
|
|
539
|
+
}
|
|
540
|
+
return ans;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
];
|
|
544
|
+
custom_col = await inquirer.prompt(custom_col);
|
|
545
|
+
custom_col.type = customType.type;
|
|
546
|
+
ans.push(custom_col);
|
|
547
|
+
}
|
|
548
|
+
if (ans.length > 0) {
|
|
549
|
+
if (updatePassword.INPUT_DATA.customcolumnnew === undefined) {
|
|
550
|
+
updatePassword.INPUT_DATA.customcolumnnew = {};
|
|
551
|
+
updatePassword.INPUT_DATA.customcolumnnew.customcol = [];
|
|
552
|
+
}
|
|
553
|
+
else if (updatePassword.INPUT_DATA.customcolumnnew.customcol === undefined) {
|
|
554
|
+
updatePassword.INPUT_DATA.customcolumnnew.customcol = [];
|
|
555
|
+
}
|
|
556
|
+
let index = 0;
|
|
557
|
+
const prefix_col = "custColDiv_"; //No I18N
|
|
558
|
+
let fileIndex = 0;
|
|
559
|
+
const filePrefix = "customattrivalue_"; //No I18N
|
|
560
|
+
if (password.customcolumn !== undefined && password.customcolumn.customcol !== undefined) {
|
|
561
|
+
if (password.customcolumn.customcol.length > 0) {
|
|
562
|
+
index = parseInt(password.customcolumn.customcol[password.customcolumn.customcol.length - 1].id.slice(11)) + 1;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (password.files !== undefined) {
|
|
566
|
+
for (let i in password.files) {
|
|
567
|
+
if (password.files[i].column.startsWith(filePrefix) && fileIndex < parseInt(password.files[i].column.slice(18))) {
|
|
568
|
+
fileIndex = parseInt(password.files[i].column.slice(18));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
fileIndex = fileIndex + 1;
|
|
573
|
+
for (let i in ans) {
|
|
574
|
+
if (ans[i].type === "file") {
|
|
575
|
+
let fileStats = fs.statSync(ans[i].value);
|
|
576
|
+
const data = 'data:' + mime.lookup(ans[i].value) + ';base64,' + fs.readFileSync(ans[i].value, 'base64').toString();
|
|
577
|
+
if (updatePassword.INPUT_DATA.files === undefined || updatePassword.INPUT_DATA.files.length === 0) {
|
|
578
|
+
updatePassword.INPUT_DATA.files = [];
|
|
579
|
+
}
|
|
580
|
+
updatePassword.INPUT_DATA.files.push({
|
|
581
|
+
name: path.basename(ans[i].value),
|
|
582
|
+
column: filePrefix + fileIndex.toString(),
|
|
583
|
+
size: fileStats.size,
|
|
584
|
+
data: Vault.fileEncrypt(data, key)
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
ans[i].id = prefix_col + index.toString();
|
|
588
|
+
updatePassword.INPUT_DATA.customcolumnnew.customcol.push(ans[i]);
|
|
589
|
+
if (ans[i].type === "file") {
|
|
590
|
+
ans[i].value = Vault.encrypt(filePrefix + fileIndex.toString(), key);
|
|
591
|
+
fileIndex = fileIndex + 1;
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
ans[i].value = Vault.encrypt(ans[i].value, key);
|
|
595
|
+
}
|
|
596
|
+
index = index + 1;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (updatePassword.INPUT_DATA.customcolumnnew !== undefined && updatePassword.INPUT_DATA.customcolumnnew.customcol !== undefined) {
|
|
600
|
+
updatePassword.INPUT_DATA.customcolumnnew = Vault.Base64_encode(JSON.stringify(updatePassword.INPUT_DATA.customcolumnnew));
|
|
601
|
+
}
|
|
602
|
+
if (updateVal.add_tags !== undefined && updateVal.remove_tags !== undefined) {
|
|
603
|
+
if (password.tags === undefined || password.tags === '') {
|
|
604
|
+
updatePassword.INPUT_DATA.tags = updateVal.add_tags;
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
updatePassword.INPUT_DATA.tags = password.tags + "," + updateVal.add_tags;
|
|
608
|
+
}
|
|
609
|
+
let removeTags = updateVal.remove_tags.split(",");
|
|
610
|
+
let tagsPresent = updatePassword.INPUT_DATA.tags.split(",");
|
|
611
|
+
let newTags = tagsPresent.filter(tag => !removeTags.includes(tag));
|
|
612
|
+
updatePassword.INPUT_DATA.tags = newTags.join(",");
|
|
613
|
+
}
|
|
614
|
+
if (updateVal.description !== undefined) {
|
|
615
|
+
updatePassword.INPUT_DATA.description = updateVal.description;
|
|
616
|
+
}
|
|
617
|
+
if (updatePassword.INPUT_DATA.files !== undefined) {
|
|
618
|
+
fileCount = fileCount + updatePassword.INPUT_DATA.files.length;
|
|
619
|
+
}
|
|
620
|
+
// need ecnrypt the non-encrypted files here
|
|
621
|
+
if (updatePassword.INPUT_DATA.description != '' && updatePassword.INPUT_DATA.description != undefined) {
|
|
622
|
+
updatePassword.INPUT_DATA.encdescription = Vault.encrypt(updatePassword.INPUT_DATA.description, key);
|
|
623
|
+
}
|
|
624
|
+
if (updatePassword.INPUT_DATA.tags != '' && updatePassword.INPUT_DATA.tags != undefined) {
|
|
625
|
+
updatePassword.INPUT_DATA.encryptedtags = Vault.encrypt(updatePassword.INPUT_DATA.tags, key);
|
|
626
|
+
} // v2 api
|
|
627
|
+
if (updatePassword.INPUT_DATA.secreturls.length > 1) {
|
|
628
|
+
for (let url in updatePassword.INPUT_DATA.secreturls) {
|
|
629
|
+
updatePassword.INPUT_DATA.encryptedurls[url] = Vault.encrypt(updatePassword.INPUT_DATA.secreturls[url], key);
|
|
630
|
+
} //v2 api
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
if (updatePassword.INPUT_DATA.secreturls[0] != undefined) {
|
|
634
|
+
updatePassword.INPUT_DATA.encryptedurls = [Vault.encrypt(updatePassword.INPUT_DATA.secreturls[0], key)];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
updatePassword.INPUT_DATA.encsecretname = Vault.encrypt(updatePassword.INPUT_DATA.secretname, key);
|
|
638
|
+
let v2_updatePassword = {};
|
|
639
|
+
let v2_fields = ["passwordmodified", "isshared", "oldvalues", "secretname", "classification", "isshared", "policyid", "secrettypeid", "secretdata", "customcolumnnew", "securenote", "encsecretname", "encdescription", "encryptedtags", "encryptedurls", "files"]; //No I18N
|
|
640
|
+
for (let fields in v2_fields) {
|
|
641
|
+
let field = v2_fields[fields];
|
|
642
|
+
if ((updatePassword.INPUT_DATA[v2_fields[fields]]) != undefined) {
|
|
643
|
+
v2_updatePassword[field] = updatePassword.INPUT_DATA[v2_fields[fields]];
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
updatePassword = { INPUT_DATA: JSON.stringify(updatePassword.INPUT_DATA) };
|
|
647
|
+
this.sanitizeInput(v2_updatePassword);
|
|
648
|
+
v2_updatePassword = { INPUT_DATA: JSON.stringify(v2_updatePassword) };
|
|
649
|
+
if (fileCount > 2) {
|
|
650
|
+
console.log(chalk.red(i18nText.getI18nMsg("vault.update.file_limit")));
|
|
651
|
+
process.exit(1);
|
|
652
|
+
}
|
|
653
|
+
try {
|
|
654
|
+
const secretResp = await _pull(`${Utilites.getVaultUrl(this.dc)}${VAULT_ENDPOINTS.URL_V2_SECRETS}/${this.id}`, v2_updatePassword, "PUT");
|
|
655
|
+
if (secretResp.data.operation.result.status === "Success") {
|
|
656
|
+
console.log(chalk.green(i18nText.getI18nMsg("vault.update.updateSuccess")));
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
Logger.error(secretResp.data.operation.result);
|
|
660
|
+
console.log(chalk.red(i18nText.getI18nMsg("vault.update.secrets_errorUpdating")));
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
catch (e) {
|
|
664
|
+
Logger.error(e);
|
|
665
|
+
console.log(chalk.red(i18nText.getI18nMsg("vault.update.secrets_errorUpdating")));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
sanitizeInput(input) {
|
|
669
|
+
if (input.files == undefined) {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
const { files } = input;
|
|
673
|
+
if (input.deletedFiles !== undefined) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
input.deletedFiles = [];
|
|
677
|
+
for (const file of files) {
|
|
678
|
+
input.deletedFiles.push(file.column);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
//# sourceMappingURL=Update.js.map
|