-
Notifications
You must be signed in to change notification settings - Fork 2
/
export.js
59 lines (48 loc) · 1.55 KB
/
export.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
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env node
var Promise = require('bluebird')
var fs = Promise.promisifyAll(require('fs'))
var os = require('os')
process.stdin.setEncoding('utf8');
var filesToExport = ['ca.pem', 'cert.pem', 'id_rsa', 'id_rsa.pub', 'key.pem', 'server-key.pem', 'server.pem']
var env = ''
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk !== null) {
env += chunk
}
})
process.stdin.on('end', function() {
var config = {}
var path = null
env.split(os.EOL).forEach(function (line) {
// Ignore comment lines
if (line && line[0] !== '#') {
if (line.substr(0, 7) === 'export ') {
var definition = line.substr(7)
var name = definition.split('=')[0]
config[name] = definition.substr(name.length+1)
config[name] = config[name].substr(1, config[name].length-2)
if (line.substr(0, 24) === 'export DOCKER_CERT_PATH=') {
path = line.substr(24)
path = path.substr(1, path.length-2)
}
}
}
})
var files = Promise.all(filesToExport.map(function(filename) {
return fs.readFileAsync(path + '/' + filename, 'utf8').then(function (data) {
// Base64 encode data certificate
return {filename: filename, result: new Buffer(data).toString('base64')}
})
}))
files.then(function (responses) {
responses.forEach(function(response) {
config[response.filename] = response.result
})
return config
}).then(function(config) {
console.log(JSON.stringify(config))
}).catch(function (err) {
console.error(err)
})
})