@drifted/raven 0.0.1 → 0.0.3
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 +2 -2
- package/index.js +39 -3
- package/package.json +1 -1
- package/test/raven.test.js +5 -0
- package/config/secret.json +0 -3
- package/test/workspace/config/secret.json +0 -3
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -7,7 +7,6 @@ const ivLength = 16;
|
|
|
7
7
|
class JSONDataFile {
|
|
8
8
|
constructor(options={}) {
|
|
9
9
|
Object.assign(this, options)
|
|
10
|
-
|
|
11
10
|
if (this.data != undefined && typeof this.data == 'string') {
|
|
12
11
|
try {
|
|
13
12
|
this.data = JSON.parse(this.data);
|
|
@@ -21,7 +20,7 @@ class JSONDataFile {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
if (this.secret == undefined && JSONDataFile.hasFile()) {
|
|
24
|
-
this.
|
|
23
|
+
this.populateSecretFromFile();
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
if (this.secret == undefined) {
|
|
@@ -29,7 +28,7 @@ class JSONDataFile {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
populateSecretFromFile() {
|
|
33
32
|
var data = fs.readFileSync(JSONDataFile.secretFile()).toString();
|
|
34
33
|
var json = JSON.parse(data);
|
|
35
34
|
this.secret = json.secret;
|
|
@@ -39,6 +38,43 @@ class JSONDataFile {
|
|
|
39
38
|
return this.file.replace(process.cwd()+"/", "")
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
static eval(options={}) {
|
|
42
|
+
var iterations = 0;
|
|
43
|
+
|
|
44
|
+
if (options.iterations != undefined) {
|
|
45
|
+
iterations = options.iterations;
|
|
46
|
+
delete options.iterations;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new Promise(async(resolve) => {
|
|
50
|
+
var file = new JSONDataFile(options);
|
|
51
|
+
var times = 0;
|
|
52
|
+
|
|
53
|
+
await file.read();
|
|
54
|
+
|
|
55
|
+
while(times < options.iterations) {
|
|
56
|
+
file.data = file.encrypt(file.data)
|
|
57
|
+
times += 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var json = JSON.parse(file.data.toString());
|
|
61
|
+
|
|
62
|
+
//console.log(json);
|
|
63
|
+
|
|
64
|
+
resolve(json)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static toEnv(options={}) {
|
|
69
|
+
var self = this;
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
self.eval(options).then((json) => {
|
|
72
|
+
Object.assign(process.env, json);
|
|
73
|
+
resolve()
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
static show() {
|
|
43
79
|
return fs.readFileSync(this.secretFile()).toString();
|
|
44
80
|
}
|
package/package.json
CHANGED
package/test/raven.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const assert = require('assert');
|
|
3
|
+
process.env.NODE_ENV = 'test';
|
|
3
4
|
|
|
4
5
|
const JSONDataFile = require(path.join(__dirname, '..'));
|
|
5
6
|
|
|
@@ -7,6 +8,10 @@ var defaults = {
|
|
|
7
8
|
secret: 'ffdnZY17Fw+sup2+lhOOt6PW++/RkLTXRaLL3RJsjzE='
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
// this seems to work. i should write a test to make sure that it works
|
|
12
|
+
//JSONDataFile.toEnv({file: path.join(__dirname, '..', 'config', process.env.NODE_ENV+'.json')});
|
|
13
|
+
|
|
14
|
+
|
|
10
15
|
process.chdir(path.join(__dirname, 'workspace'));
|
|
11
16
|
|
|
12
17
|
describe('raven', function() {
|
package/config/secret.json
DELETED