homegames-common 0.1.34 → 0.2.0
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/index.js +94 -22
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -117,17 +117,17 @@ const guaranteeCertFiles = (dir) => new Promise((resolve, reject) => {
|
|
|
117
117
|
|
|
118
118
|
fs.readdir(dir, (err, files) => {
|
|
119
119
|
files.forEach(file => {
|
|
120
|
-
if (file === '
|
|
120
|
+
if (file === 'cert.pem') {
|
|
121
121
|
certPath = path.join(dir, file);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
if (file === '
|
|
124
|
+
if (file === 'key.pem') {
|
|
125
125
|
keyPath = path.join(dir, file);
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
if (!certPath) {
|
|
130
|
-
reject('Could not find
|
|
130
|
+
reject('Could not find cert.pem');
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
if (!keyPath) {
|
|
@@ -143,19 +143,21 @@ const guaranteeCertFiles = (dir) => new Promise((resolve, reject) => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
const validateCertData = (certPaths, username, accessToken) => new Promise((resolve, reject) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}).
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
// one day
|
|
147
|
+
resolve(JSON.stringify({success: true}));
|
|
148
|
+
// postUrl('https://certifier.homegames.io', '/verify', {
|
|
149
|
+
// checksum: ''
|
|
150
|
+
// },
|
|
151
|
+
// {
|
|
152
|
+
// 'hg-username': username,
|
|
153
|
+
// 'hg-access-token': accessToken
|
|
154
|
+
// }).then(data => {
|
|
155
|
+
// resolve(data);
|
|
156
|
+
// }).catch(err => {
|
|
157
|
+
// reject({
|
|
158
|
+
// message: err.toString()
|
|
159
|
+
// });
|
|
160
|
+
// });
|
|
159
161
|
|
|
160
162
|
});
|
|
161
163
|
|
|
@@ -226,7 +228,7 @@ const certInit = (certPath, loginPath) => new Promise((resolve, reject) => {
|
|
|
226
228
|
validateExistingCerts(certPath).then((certData) => {
|
|
227
229
|
}).catch(err => {
|
|
228
230
|
validateLoginData(loginPath).then((loginData) => {
|
|
229
|
-
getUrl('https://certifier.homegames.
|
|
231
|
+
getUrl('https://certifier.homegames.io/get-certs').then(data => {
|
|
230
232
|
resolve(data);
|
|
231
233
|
}).catch(err => {
|
|
232
234
|
});
|
|
@@ -343,13 +345,15 @@ const getLoginInfo = (authPath) => new Promise((resolve, reject) => {
|
|
|
343
345
|
|
|
344
346
|
const getCertData = (username, accessToken) => new Promise((resolve, reject) => {
|
|
345
347
|
|
|
346
|
-
getUrl('https://certifier.homegames.
|
|
348
|
+
getUrl('https://certifier.homegames.io/get-cert', {
|
|
347
349
|
|
|
348
350
|
'hg-username': username,
|
|
349
|
-
'hg-
|
|
351
|
+
'hg-token': accessToken
|
|
350
352
|
}).then(data => {
|
|
351
353
|
resolve(data);
|
|
352
354
|
}).catch(err => {
|
|
355
|
+
console.log(err.toString());
|
|
356
|
+
console.log('that was an error');
|
|
353
357
|
});
|
|
354
358
|
});
|
|
355
359
|
|
|
@@ -407,8 +411,8 @@ const guaranteeCerts = (authPath, certPath) => new Promise((resolve, reject) =>
|
|
|
407
411
|
if (data.success) {
|
|
408
412
|
storeCertData(certData, certPath).then(() => {
|
|
409
413
|
resolve({
|
|
410
|
-
certPath: `${certPath}/
|
|
411
|
-
keyPath: `${certPath}/
|
|
414
|
+
certPath: `${certPath}/cert.pem`,
|
|
415
|
+
keyPath: `${certPath}/key.pem`,
|
|
412
416
|
});
|
|
413
417
|
});
|
|
414
418
|
} else {
|
|
@@ -464,6 +468,19 @@ const lockFile = (path) => new Promise((resolve, reject) => {
|
|
|
464
468
|
const lockPath = `${path}.hglock`;
|
|
465
469
|
fs.exists(lockPath, (exists) => {
|
|
466
470
|
if (!exists) {
|
|
471
|
+
const pathPieces = path.split('/');
|
|
472
|
+
let pathParent = [];
|
|
473
|
+
for (let x in pathPieces) {
|
|
474
|
+
if (x == pathPieces.length - 1) {
|
|
475
|
+
break
|
|
476
|
+
} else {
|
|
477
|
+
pathParent.push(pathPieces[x]);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
guaranteeDir(pathParent.join('/')).then(() => {
|
|
482
|
+
console.log("writing lock file");
|
|
483
|
+
console.log(lockPath);
|
|
467
484
|
fs.writeFile(lockPath, 'lock', 'utf-8', () => {
|
|
468
485
|
clearInterval(_interval);
|
|
469
486
|
fs.readFile(lockPath, (err, data) => {
|
|
@@ -475,7 +492,9 @@ const lockFile = (path) => new Promise((resolve, reject) => {
|
|
|
475
492
|
}
|
|
476
493
|
});
|
|
477
494
|
});
|
|
495
|
+
});
|
|
478
496
|
} else {
|
|
497
|
+
console.log('waiting for lock');
|
|
479
498
|
const { birthtime } = fs.statSync(lockPath);
|
|
480
499
|
const fiveMinsAgo = Date.now() - ( 1000 * 60 * 5 );
|
|
481
500
|
console.log(birthtime);
|
|
@@ -536,6 +555,7 @@ const authWorkflow = (authPath) => new Promise((resolve, reject) => {
|
|
|
536
555
|
});
|
|
537
556
|
};
|
|
538
557
|
|
|
558
|
+
console.log('about to lock ' + authPath);
|
|
539
559
|
lockFile(authPath).then(() => {
|
|
540
560
|
getLoginInfo(authPath).then((loginInfo) => {
|
|
541
561
|
verifyAccessToken(loginInfo.username, loginInfo.tokens.accessToken).then(() => {
|
|
@@ -558,6 +578,55 @@ const authWorkflow = (authPath) => new Promise((resolve, reject) => {
|
|
|
558
578
|
});
|
|
559
579
|
});
|
|
560
580
|
|
|
581
|
+
const getConfigValue = (key, _default = undefined) => {
|
|
582
|
+
const config = getConfig();
|
|
583
|
+
|
|
584
|
+
let envValue = process.env[key] && `${process.env[key]}`;
|
|
585
|
+
if (envValue !== undefined) {
|
|
586
|
+
if (envValue === 'true') {
|
|
587
|
+
envValue = true;
|
|
588
|
+
} else if (envValue === 'false') {
|
|
589
|
+
envValue = false;
|
|
590
|
+
}
|
|
591
|
+
console.log(`Using environment value: ${envValue} for key: ${key}`);
|
|
592
|
+
return envValue;
|
|
593
|
+
}
|
|
594
|
+
if (config[key] === undefined && _default === undefined) {
|
|
595
|
+
throw new Error(`No value for ${key} found in config`);
|
|
596
|
+
} else if (config[key] === undefined && _default !== undefined) {
|
|
597
|
+
return _default;
|
|
598
|
+
}
|
|
599
|
+
console.log(`Found value ${config[key]} in config`);
|
|
600
|
+
return config[key];
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
let cachedConfig = {};
|
|
604
|
+
|
|
605
|
+
const getConfig = () => {
|
|
606
|
+
|
|
607
|
+
if (Object.keys(cachedConfig).length > 0) {
|
|
608
|
+
return cachedConfig;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const options = [process.cwd(), require.main.filename, process.mainModule.filename, __dirname]
|
|
612
|
+
let baseDir = process.cwd();
|
|
613
|
+
let _config = {};
|
|
614
|
+
|
|
615
|
+
for (let i = 0; i < options.length; i++) {
|
|
616
|
+
if (fs.existsSync(`${options[i]}/config.json`)) {
|
|
617
|
+
console.log(`Using config at ${options[i]}`);
|
|
618
|
+
_config = JSON.parse(fs.readFileSync(`${options[i]}/config.json`));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
console.log('using this config data');
|
|
623
|
+
console.log(_config);
|
|
624
|
+
|
|
625
|
+
cachedConfig = _config;
|
|
626
|
+
|
|
627
|
+
return _config;
|
|
628
|
+
}
|
|
629
|
+
|
|
561
630
|
|
|
562
631
|
module.exports = {
|
|
563
632
|
guaranteeCerts,
|
|
@@ -576,5 +645,8 @@ module.exports = {
|
|
|
576
645
|
promptLogin,
|
|
577
646
|
getUserHash,
|
|
578
647
|
authWorkflow,
|
|
579
|
-
guaranteeDir
|
|
648
|
+
guaranteeDir,
|
|
649
|
+
getUrl,
|
|
650
|
+
getConfigValue
|
|
580
651
|
};
|
|
652
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homegames-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Homegames common tools",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/homegamesio/homegames-common#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"aws-sdk": "^2.
|
|
20
|
+
"aws-sdk": "^2.1151.0",
|
|
21
21
|
"unzipper": "^0.10.11",
|
|
22
|
-
"ws": "^7.4
|
|
22
|
+
"ws": "^7.5.4"
|
|
23
23
|
}
|
|
24
24
|
}
|