@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,307 @@
|
|
|
1
|
+
import { Logger } from "../../js/logger/index.js";
|
|
2
|
+
import { accessSync, constants } from "node:fs";
|
|
3
|
+
import { lstatSync } from "node:fs";
|
|
4
|
+
import { getOS } from "../../util/index.util.js";
|
|
5
|
+
import { Configuration } from "../../util/configuration.util.js";
|
|
6
|
+
import { LoginOpts } from "./login.types.js";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { Utilities } from "../../util/index.util.js";
|
|
9
|
+
import { spawn } from "child_process";
|
|
10
|
+
import Vault from "../../js/crypto/index.js";
|
|
11
|
+
import { encryptString } from "../../util/encryptionutil/encryption.uitl.js";
|
|
12
|
+
import { insertToTable, getZvDB } from "../../util/dbutils/db.utils.js";
|
|
13
|
+
import { DC, OS } from "../../util/consts.util.js";
|
|
14
|
+
import { TransferLoader } from "../../util/loader/transfer.loader.js";
|
|
15
|
+
import { select } from "@inquirer/prompts";
|
|
16
|
+
import { API_DOMAIN_TO_DC } from "./login.const.js";
|
|
17
|
+
export const header = {
|
|
18
|
+
"User-Agent": "CLI/1.0.1 (" + getOS() + ")" //No I18N
|
|
19
|
+
};
|
|
20
|
+
export const setHeaders = (key, value) => {
|
|
21
|
+
header[key] = value;
|
|
22
|
+
};
|
|
23
|
+
export const isValidDC = (dc) => {
|
|
24
|
+
if (typeof dc !== "string") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return ["us", "eu", "au", "in", 'com.cn'].includes(dc);
|
|
28
|
+
};
|
|
29
|
+
export const accessFolder = (path) => {
|
|
30
|
+
try {
|
|
31
|
+
accessSync(path, constants.W_OK);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const isValidPath = async (path) => {
|
|
39
|
+
return new Promise((resolve, _) => {
|
|
40
|
+
path = typeof path === "string" ? path.trim() : "";
|
|
41
|
+
if (typeof path !== "string" || path === "") {
|
|
42
|
+
resolve(false);
|
|
43
|
+
}
|
|
44
|
+
const isDirectory = lstatSync(path).isDirectory();
|
|
45
|
+
if (!isDirectory) {
|
|
46
|
+
Logger.error("Not a valid directory");
|
|
47
|
+
resolve(false);
|
|
48
|
+
}
|
|
49
|
+
resolve(accessFolder(path));
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const checkValidDC = (dc) => {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
if (isValidDC(dc)) {
|
|
55
|
+
resolve(true);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
reject(false);
|
|
59
|
+
console.log("Invalid DC value entered. The following are the valid list of DCs: US | EU | IN | AU | COM.CN");
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const checkConfigPath = (path) => {
|
|
65
|
+
return new Promise(async (resolve, reject) => {
|
|
66
|
+
const isValid = await isValidPath(path);
|
|
67
|
+
if (path !== undefined && !isValid) {
|
|
68
|
+
reject(new Error("Invalid ConfigPath entered. Please specify a valid path and try again.")); //No I18N
|
|
69
|
+
}
|
|
70
|
+
resolve(isValid);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
export const getDeviceCodeAndLink = (configObj) => {
|
|
74
|
+
return new Promise(async (resolve, reject) => {
|
|
75
|
+
try {
|
|
76
|
+
const response = await configObj.generateLinkForDeviceCode();
|
|
77
|
+
if ((response).hasOwnProperty("error")) {
|
|
78
|
+
reject(response.error);
|
|
79
|
+
}
|
|
80
|
+
const { data: { device_code, verification_uri_complete } } = response;
|
|
81
|
+
resolve({ device_code, verification_uri_complete });
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
reject(new Error("Cannot generate device code and link"));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export const openUrl = (url) => {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
try {
|
|
91
|
+
const platform = getOS();
|
|
92
|
+
if (platform == OS.WINDOWS) {
|
|
93
|
+
spawn('cmd', ['/c', 'start', url], { stdio: 'ignore', detached: true });
|
|
94
|
+
resolve(true);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
spawn('open', [url]);
|
|
98
|
+
resolve(true);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
}
|
|
103
|
+
resolve(false);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
export const promptUserWithRetry = async (url) => {
|
|
107
|
+
const answer = await select({
|
|
108
|
+
message: `open ${url} in default browser?`,
|
|
109
|
+
choices: [
|
|
110
|
+
{ name: 'Yes', value: true },
|
|
111
|
+
{ name: 'No', value: false }
|
|
112
|
+
],
|
|
113
|
+
default: true,
|
|
114
|
+
});
|
|
115
|
+
if (answer) {
|
|
116
|
+
await openUrl(url);
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
console.log("Copy and paste the URL displayed below in your browser address bar and hit Enter. You will be prompted to log in to your Zoho account if you haven't already. Grant the necessary permissions to access Vault: "); //No I18N
|
|
120
|
+
console.log(chalk.greenBright.bold.underline(url));
|
|
121
|
+
console.log("\n");
|
|
122
|
+
return undefined;
|
|
123
|
+
};
|
|
124
|
+
// export const promptUserToGiveConsent = async (url: string): Promise<undefined> => {
|
|
125
|
+
// return new Promise((resolve, reject) => {
|
|
126
|
+
// confirm(
|
|
127
|
+
// {
|
|
128
|
+
// message: `open ${url} in default browser`,
|
|
129
|
+
// default: true,
|
|
130
|
+
// }
|
|
131
|
+
// ).then(async (answer) => {
|
|
132
|
+
// if (answer) {
|
|
133
|
+
// const res = await openUrl(url);
|
|
134
|
+
// if (res) {
|
|
135
|
+
// resolve(undefined);
|
|
136
|
+
// return;
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
|
+
// console.log("Copy and paste the URL displayed below in your browser address bar and hit Enter. You will be prompted to log in to your Zoho account if you haven't already. Grant the necessary permissions to access Vault: "); //No I18N
|
|
140
|
+
// console.log(chalk.greenBright.bold.underline(url));
|
|
141
|
+
// console.log("\n");
|
|
142
|
+
// resolve(undefined);
|
|
143
|
+
// })
|
|
144
|
+
// .catch((error) => {
|
|
145
|
+
// reject(undefined);
|
|
146
|
+
// })
|
|
147
|
+
// })
|
|
148
|
+
// }
|
|
149
|
+
export const authenticateUser = (deviceCode, configObj) => {
|
|
150
|
+
console.log("Please wait once granted necessary permission. Authenticating your Zoho account");
|
|
151
|
+
return new Promise(async (resolve, reject) => {
|
|
152
|
+
try {
|
|
153
|
+
let refreshTokenResp = await configObj.generateRefreshToken(deviceCode);
|
|
154
|
+
const { data } = refreshTokenResp;
|
|
155
|
+
if (data.hasOwnProperty("error") && data.error === 'other_dc') {
|
|
156
|
+
const dc = data.user_location;
|
|
157
|
+
configObj.setDC(dc);
|
|
158
|
+
refreshTokenResp = await configObj.generateRefreshToken(deviceCode);
|
|
159
|
+
}
|
|
160
|
+
resolve(data);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
Logger.error(err);
|
|
164
|
+
reject(new Error("Unable to process your request. Please try again later"));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
export const resolvePendingRequest = (data, configObj, deviceCode) => {
|
|
169
|
+
return new Promise(async (resolve, reject) => {
|
|
170
|
+
try {
|
|
171
|
+
let time = 1000;
|
|
172
|
+
while (data.hasOwnProperty("error") && (data.error !== 'access_denied')) { //No I18N
|
|
173
|
+
await Utilities.sleep(time);
|
|
174
|
+
let refreshTokenResp = await configObj.generateRefreshToken(deviceCode);
|
|
175
|
+
data = refreshTokenResp.data;
|
|
176
|
+
if (data.hasOwnProperty('error') && data.error === 'other_dc') {
|
|
177
|
+
let dc = data.user_location;
|
|
178
|
+
configObj.setDc(dc);
|
|
179
|
+
refreshTokenResp = await configObj.generateRefreshToken(deviceCode);
|
|
180
|
+
data = refreshTokenResp.data;
|
|
181
|
+
}
|
|
182
|
+
else if (data.hasOwnProperty('error') && data.error === 'slow_down') {
|
|
183
|
+
time = time + 200;
|
|
184
|
+
}
|
|
185
|
+
if (data.hasOwnProperty("error") && data.error === 'access_denied') {
|
|
186
|
+
reject(new Error("Device Request Access Denied, terminating the authentication process"));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
resolve(data);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
reject(err);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
export const getLanguage = (status, data) => {
|
|
197
|
+
if (status === "Success") {
|
|
198
|
+
const { operation } = data;
|
|
199
|
+
const { Details: { language } } = operation;
|
|
200
|
+
return language;
|
|
201
|
+
}
|
|
202
|
+
return "en";
|
|
203
|
+
};
|
|
204
|
+
export const getUserLanguage = (configObj, accessToken) => {
|
|
205
|
+
setHeaders("Authorization", `Zoho-oauthtoken ${accessToken}`);
|
|
206
|
+
return new Promise(async (resolve, reject) => {
|
|
207
|
+
try {
|
|
208
|
+
let resp = await configObj.getUserLanguage();
|
|
209
|
+
const { data } = resp;
|
|
210
|
+
const { operation: { result: { status } } } = data;
|
|
211
|
+
resolve(getLanguage(status, data));
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
reject(new Error("Problem fetching your preferred language. Please try again."));
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
export const createConfigObject = (refresh_token, access_token, masterkey) => {
|
|
219
|
+
const configObj = { refresh_token, access_token, masterkey };
|
|
220
|
+
return JSON.stringify(configObj);
|
|
221
|
+
};
|
|
222
|
+
export const isValidString = (str) => {
|
|
223
|
+
if (typeof str !== 'string') {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (str.trim() !== '') {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
};
|
|
231
|
+
export const createEncryptedConfigurationObject = async (refresh_token, access_token, lang, date, dc, masterKey, zuid) => {
|
|
232
|
+
const credentials = await encryptString(createConfigObject(refresh_token, access_token, masterKey));
|
|
233
|
+
const language = await encryptString(lang);
|
|
234
|
+
const createdtime = await encryptString(date.toString());
|
|
235
|
+
const workspace = generateWorkspaceHash();
|
|
236
|
+
const dcEnc = await encryptString(dc);
|
|
237
|
+
const hasmasterkey = false.toString();
|
|
238
|
+
const defaults = await encryptString(Vault.Base64_encode('{}'));
|
|
239
|
+
let encZuid = await encryptString(zuid);
|
|
240
|
+
return { workspace, credentials, language, createdtime, dc: dcEnc, hasmasterkey, defaults, zuid: encZuid };
|
|
241
|
+
};
|
|
242
|
+
export const resolveDC = (api_domain) => {
|
|
243
|
+
return API_DOMAIN_TO_DC[api_domain] ?? DC.US;
|
|
244
|
+
};
|
|
245
|
+
export const getUserConsentAndCreateConfig = (dc) => {
|
|
246
|
+
return new Promise(async (resolve, reject) => {
|
|
247
|
+
let loader = new TransferLoader();
|
|
248
|
+
try {
|
|
249
|
+
const configObj = new Configuration(dc);
|
|
250
|
+
const res = await getDeviceCodeAndLink(configObj);
|
|
251
|
+
const { device_code, verification_uri_complete } = res;
|
|
252
|
+
await promptUserWithRetry(verification_uri_complete);
|
|
253
|
+
loader.load();
|
|
254
|
+
let respData = await authenticateUser(device_code, configObj);
|
|
255
|
+
respData = await resolvePendingRequest(respData, configObj, device_code);
|
|
256
|
+
const { access_token, refresh_token, api_domain } = respData;
|
|
257
|
+
// Resolve the user's actual DC from the api_domain in the token response
|
|
258
|
+
const resolvedDc = api_domain ? resolveDC(api_domain) : dc;
|
|
259
|
+
if (resolvedDc !== dc) {
|
|
260
|
+
loader.stop();
|
|
261
|
+
console.log(chalk.yellowBright(`Your account belongs to the ${resolvedDc.toUpperCase()} datacenter, but you logged in to the ${dc.toUpperCase()} datacenter.`));
|
|
262
|
+
console.log(chalk.yellowBright(`Please login again with: zv login --dc ${resolvedDc}`));
|
|
263
|
+
reject(new Error(`DC mismatch: expected ${dc}, got ${resolvedDc}. Please login with --dc ${resolvedDc}`));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const language = await getUserLanguage(configObj, access_token);
|
|
267
|
+
const credentials = await createEncryptedConfigurationObject(refresh_token, access_token, language, Date.now(), resolvedDc, '', '');
|
|
268
|
+
const db = getZvDB();
|
|
269
|
+
insertToTable(db, credentials);
|
|
270
|
+
loader.stop();
|
|
271
|
+
console.log("You are now logged in to your Zoho account");
|
|
272
|
+
resolve(true);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
loader.stop();
|
|
276
|
+
reject(error);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
export const generateWorkspaceHash = () => {
|
|
281
|
+
const path = process.cwd();
|
|
282
|
+
return Vault.hash(path);
|
|
283
|
+
};
|
|
284
|
+
export const getKey = (key) => {
|
|
285
|
+
switch (key) {
|
|
286
|
+
case LoginOpts.DC:
|
|
287
|
+
return "dc";
|
|
288
|
+
default:
|
|
289
|
+
return "";
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
export const constructDefaultOpts = (opts) => {
|
|
293
|
+
if (!('login' in opts)) {
|
|
294
|
+
return {};
|
|
295
|
+
}
|
|
296
|
+
const res = {};
|
|
297
|
+
const { login } = opts;
|
|
298
|
+
for (const key in login) {
|
|
299
|
+
const tkey = key;
|
|
300
|
+
const mkey = getKey(tkey);
|
|
301
|
+
if (login.hasOwnProperty(key)) {
|
|
302
|
+
res[mkey] = login[tkey];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return res;
|
|
306
|
+
};
|
|
307
|
+
//# sourceMappingURL=login.utils.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { reset } from "../../util/dbutils/db.utils.js";
|
|
2
|
+
import { select } from "@inquirer/prompts";
|
|
3
|
+
import { deleteFromKeyring } from "../../util/keyringutil/keyring.util.js";
|
|
4
|
+
import { KEYRING_ACCOUNT, KEYRING_SERVICE } from "../../util/consts.util.js";
|
|
5
|
+
export const resetAction = () => {
|
|
6
|
+
select({
|
|
7
|
+
message: "Confirm reset: ",
|
|
8
|
+
choices: [
|
|
9
|
+
{ name: 'Yes', value: true },
|
|
10
|
+
{ name: 'No', value: false }
|
|
11
|
+
],
|
|
12
|
+
default: true
|
|
13
|
+
}).then(async (answer) => {
|
|
14
|
+
try {
|
|
15
|
+
await deleteFromKeyring(KEYRING_SERVICE, KEYRING_ACCOUNT);
|
|
16
|
+
}
|
|
17
|
+
catch (_) {
|
|
18
|
+
// Keyring entry may not exist — safe to ignore
|
|
19
|
+
}
|
|
20
|
+
if (answer) {
|
|
21
|
+
await reset();
|
|
22
|
+
console.log("All Zoho Vault accounts Logged out successfully.");
|
|
23
|
+
}
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
console.log("Operation terminated unexpectedly");
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=reset.action.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resetAction } from "./reset.action.js";
|
|
2
|
+
import resetHelp from "./reset.help.js";
|
|
3
|
+
export const reset = (program) => {
|
|
4
|
+
program
|
|
5
|
+
.command("reset")
|
|
6
|
+
.description("Logs out all Zoho Vault accounts") //No I18N
|
|
7
|
+
.on('--help', () => {
|
|
8
|
+
resetHelp();
|
|
9
|
+
})
|
|
10
|
+
.action(() => {
|
|
11
|
+
resetAction();
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=reset.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { showError } from "../../util/print.util.js";
|
|
2
|
+
import { Search } from "../../util/search.util.js";
|
|
3
|
+
import { checkConfigurationAndMasterKey } from "./search.utils.js";
|
|
4
|
+
import { getDecryptedCredentials } from "../../util/dbutils/db.utils.js";
|
|
5
|
+
import { generateWorkspaceHash } from "../login/login.utils.js";
|
|
6
|
+
import { Default } from "../../old/Default.js";
|
|
7
|
+
import { constructDefaultOpts } from "./search.utils.js";
|
|
8
|
+
export const searchAction = async (option) => {
|
|
9
|
+
try {
|
|
10
|
+
const { useDefault } = option;
|
|
11
|
+
if (useDefault) {
|
|
12
|
+
const def = new Default(undefined, undefined);
|
|
13
|
+
const options = await def.getDefaults();
|
|
14
|
+
const defaultOpts = constructDefaultOpts(options);
|
|
15
|
+
option = { ...option, ...defaultOpts };
|
|
16
|
+
}
|
|
17
|
+
const { key, strict, tags, desc, name, verbose, output, outFile, notSafe } = option;
|
|
18
|
+
await checkConfigurationAndMasterKey();
|
|
19
|
+
const configData = await getDecryptedCredentials(generateWorkspaceHash());
|
|
20
|
+
const { dc } = configData;
|
|
21
|
+
const searchObj = new Search(key, strict, tags, desc, name, verbose, output, outFile, notSafe, undefined, dc);
|
|
22
|
+
await searchObj.getSecrets();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof Error) {
|
|
26
|
+
showError(err.message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=search.action.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var SEARCH;
|
|
2
|
+
(function (SEARCH) {
|
|
3
|
+
SEARCH["TAGS"] = "tags";
|
|
4
|
+
SEARCH["DESCRIPTION"] = "description";
|
|
5
|
+
SEARCH["SECRETNAME"] = "secretname";
|
|
6
|
+
})(SEARCH || (SEARCH = {}));
|
|
7
|
+
export var OUTPUT;
|
|
8
|
+
(function (OUTPUT) {
|
|
9
|
+
OUTPUT["XML"] = "xml";
|
|
10
|
+
OUTPUT["YAML"] = "yaml";
|
|
11
|
+
OUTPUT["JSON"] = "json";
|
|
12
|
+
OUTPUT["YML"] = "yml";
|
|
13
|
+
})(OUTPUT || (OUTPUT = {}));
|
|
14
|
+
//# sourceMappingURL=search.constants.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const searchHelp = (i18nText) => {
|
|
2
|
+
console.log(`
|
|
3
|
+
\nExample :\n zv search -k mail\n zv search -k "win" \n zv search -k "win" --name \n zv search -k "gmail test" --strict\n zv search -k "win" --name -V\n zv search -k "win" --name -V --not-safe\n zv search -k "win" --name -V --output xml\n zv search -k "win" --name -V --output xml -w output.xml\n` //No I18N
|
|
4
|
+
+ i18nText.getI18nMsg("vault.search.example_note"));
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=search.help.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { searchAction } from "./search.action.js";
|
|
2
|
+
import { I18N } from "../../js/I18n/index.js";
|
|
3
|
+
import { searchHelp } from "./search.help.js";
|
|
4
|
+
export const search = (program) => {
|
|
5
|
+
const i18nText = new I18N();
|
|
6
|
+
program
|
|
7
|
+
.command("search")
|
|
8
|
+
.description(i18nText.getI18nMsg("vault.search.desc"))
|
|
9
|
+
.option("-k, --key <key>", i18nText.getI18nMsg("vault.search.option_key"), "")
|
|
10
|
+
.option("-s, --strict", i18nText.getI18nMsg("vault.search.option_strict"), false)
|
|
11
|
+
// .option("-t, --tags", i18nText.getI18nMsg("vault.search.option_tags"), false)
|
|
12
|
+
// .option("-d, --desc", i18nText.getI18nMsg("vault.search.option_includeDesc"), false)
|
|
13
|
+
.option("-n, --name", i18nText.getI18nMsg("vault.search.option_includeName"), false)
|
|
14
|
+
.option("-V, --verbose", i18nText.getI18nMsg("vault.search.option_verbose"), false)
|
|
15
|
+
.option("-show --not-safe", i18nText.getI18nMsg("vault.search.option_notSafe"), false)
|
|
16
|
+
.option("-w, --out-file [path]", i18nText.getI18nMsg("vault.search.option_outFile"))
|
|
17
|
+
.option("--use-default", "uses default options for search", false)
|
|
18
|
+
.option("-o , --output [type]", i18nText.getI18nMsg("vault.search.option_output"), "table") //TODO get the default value from some config file
|
|
19
|
+
.on("--help", () => {
|
|
20
|
+
searchHelp(i18nText);
|
|
21
|
+
})
|
|
22
|
+
.action((option) => {
|
|
23
|
+
searchAction(option);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { I18N } from "../../js/I18n/index.js";
|
|
2
|
+
const i18N = new I18N();
|
|
3
|
+
export var SearchOpts;
|
|
4
|
+
(function (SearchOpts) {
|
|
5
|
+
SearchOpts["KEY"] = "--key";
|
|
6
|
+
SearchOpts["STRICT"] = "--strict";
|
|
7
|
+
SearchOpts["TAGS"] = "--tags";
|
|
8
|
+
SearchOpts["DESC"] = "--desc";
|
|
9
|
+
SearchOpts["NAME"] = "--name";
|
|
10
|
+
SearchOpts["VERBOSE"] = "--verbose";
|
|
11
|
+
SearchOpts["NOTSAFE"] = "--not-safe";
|
|
12
|
+
SearchOpts["OUT_FILE"] = "--out-file";
|
|
13
|
+
SearchOpts["USE_DEFAULT"] = "--use-default";
|
|
14
|
+
SearchOpts["OUTPUT"] = "--output";
|
|
15
|
+
})(SearchOpts || (SearchOpts = {}));
|
|
16
|
+
//# sourceMappingURL=search.types.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isConfigurationExist, isMasterKeyExist } from "../../util/index.util.js";
|
|
2
|
+
import { SearchOpts } from "./search.types.js";
|
|
3
|
+
export const checkConfigurationAndMasterKey = () => {
|
|
4
|
+
return new Promise(async (resolve, reject) => {
|
|
5
|
+
if (!await isConfigurationExist()) {
|
|
6
|
+
reject(new Error("You are not logged in to your Zoho account yet. Please log in to your Zoho account using zv login"));
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (!await isMasterKeyExist()) {
|
|
10
|
+
reject(new Error("Please unlock your Zoho Vault account using 'zv unlock' before using other commands"));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
resolve(true);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export const getKey = (key) => {
|
|
17
|
+
switch (key) {
|
|
18
|
+
case SearchOpts.KEY:
|
|
19
|
+
return "key";
|
|
20
|
+
case SearchOpts.STRICT:
|
|
21
|
+
return "strict";
|
|
22
|
+
case SearchOpts.TAGS:
|
|
23
|
+
return "tags";
|
|
24
|
+
case SearchOpts.DESC:
|
|
25
|
+
return "desc";
|
|
26
|
+
case SearchOpts.NAME:
|
|
27
|
+
return "name";
|
|
28
|
+
case SearchOpts.VERBOSE:
|
|
29
|
+
return "verbose";
|
|
30
|
+
case SearchOpts.NOTSAFE:
|
|
31
|
+
return "notSafe";
|
|
32
|
+
case SearchOpts.OUT_FILE:
|
|
33
|
+
return "outFile";
|
|
34
|
+
case SearchOpts.OUTPUT:
|
|
35
|
+
return "output";
|
|
36
|
+
default:
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const getValue = (key, search) => {
|
|
41
|
+
if ([SearchOpts.STRICT, SearchOpts.TAGS, SearchOpts.DESC, SearchOpts.NAME, SearchOpts.VERBOSE, SearchOpts.NOTSAFE].includes(key)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return search[key];
|
|
45
|
+
};
|
|
46
|
+
export const constructDefaultOpts = (opts) => {
|
|
47
|
+
if (!('search' in opts)) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
const res = {};
|
|
51
|
+
const { search } = opts;
|
|
52
|
+
for (const key in search) {
|
|
53
|
+
const tkey = key;
|
|
54
|
+
const mkey = getKey(tkey);
|
|
55
|
+
if (search.hasOwnProperty(tkey)) {
|
|
56
|
+
res[mkey] = getValue(tkey, search);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return res;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=search.utils.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SetDefaultOpts } from "./set-default.const.js";
|
|
2
|
+
import { OPTIONS } from "../../util/consts.util.js";
|
|
3
|
+
import { Default } from "../../old/Default.js";
|
|
4
|
+
export const getKey = (key) => {
|
|
5
|
+
switch (key) {
|
|
6
|
+
case SetDefaultOpts.COMMAND:
|
|
7
|
+
return "command";
|
|
8
|
+
default:
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const getVal = (key, setDefaults) => {
|
|
13
|
+
if (key === SetDefaultOpts.CLR) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return setDefaults[key];
|
|
17
|
+
};
|
|
18
|
+
export const constructDefaultOpts = (opts) => {
|
|
19
|
+
if (!(OPTIONS.GET_DEFAULT in opts)) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
const res = {};
|
|
23
|
+
const { "set-default": setDefault } = opts;
|
|
24
|
+
for (const key in setDefault) {
|
|
25
|
+
const tKey = key;
|
|
26
|
+
const mkey = getKey(tKey);
|
|
27
|
+
if (setDefault.hasOwnProperty(tKey)) {
|
|
28
|
+
res[mkey] = getVal(tKey, setDefault);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return res;
|
|
32
|
+
};
|
|
33
|
+
export const getDefaults = async () => {
|
|
34
|
+
const def = new Default(undefined, undefined);
|
|
35
|
+
const options = await def.getDefaults();
|
|
36
|
+
const defaultOpts = constructDefaultOpts(options);
|
|
37
|
+
return defaultOpts;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=set-default.utils.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { checkConfiguration } from "./unlock.utils.js";
|
|
2
|
+
import { Configuration } from "../../util/configuration.util.js";
|
|
3
|
+
import { isValidLicense } from "./unlock.utils.js";
|
|
4
|
+
import { unlockUser } from "./unlock.utils.js";
|
|
5
|
+
import { getDecryptedCredentials } from "../../util/dbutils/db.utils.js";
|
|
6
|
+
import { generateWorkspaceHash } from "../login/login.utils.js";
|
|
7
|
+
export const unlockAction = async (masterPassword, isTrusted) => {
|
|
8
|
+
try {
|
|
9
|
+
await checkConfiguration();
|
|
10
|
+
const credentials = await getDecryptedCredentials(generateWorkspaceHash());
|
|
11
|
+
const configObj = new Configuration(credentials.dc);
|
|
12
|
+
const isvalidLicense = await isValidLicense(configObj);
|
|
13
|
+
if (!isvalidLicense) {
|
|
14
|
+
console.log("You do not have access to Zoho Vault CLI. Please check your subscription"); //No I18N
|
|
15
|
+
throw new Error();
|
|
16
|
+
}
|
|
17
|
+
await unlockUser(masterPassword, configObj, !isTrusted);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.log("Operation ended unexpectedly while unlocking a user");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=unlock.action.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { unlockAction } from "./unlock.action.js";
|
|
2
|
+
export const unlock = (program) => {
|
|
3
|
+
program
|
|
4
|
+
.command('unlock') //No I18N
|
|
5
|
+
.description('Access your Zoho Vault account') //No I18N
|
|
6
|
+
// .option('-nt --notrust', 'Prompt for the master password to run any command. This option can be enabled when using Zoho Vault on a public or an untrustworthy device.', false) //No I18
|
|
7
|
+
.argument('[masterpassword]', 'Zoho Vault Master password') //No I18
|
|
8
|
+
.action(async (masterpassword, options) => {
|
|
9
|
+
await unlockAction(masterpassword, false);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=unlock.js.map
|