-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials.js
48 lines (41 loc) · 1.02 KB
/
credentials.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require('fs');
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
class Credentials {
constructor() {
this.creds = {
"pass": "",
"email": "",
"pin": "",
"appName": "",
"appSource": "",
"userId": "",
"password": "",
"userKey": "",
"encryptionKey": "",
"dob": ""
}
}
async getCreds() {
if (process.platform == 'darwin' && fs.existsSync("/opt/homebrew/bin/pass")) {
await this.getCredsFromPass();
}
}
async getCredsFromPass() {
const { stdout, stderr } = await exec("pass " + process.env.PASS_KEY);
for (const line of stdout.split("\n")) {
if (line == '---') continue;
const parts = line.split(":");
if (parts.length > 1)
this.creds[parts[0].trim()] = parts[1].trim();
else
this.creds["pass"] = line.trim();
}
}
}
const getCreds = async () => {
const creds = new Credentials();
await creds.getCreds();
return creds.creds;
}
module.exports = { getCreds }