This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
start.js
40 lines (36 loc) · 1.43 KB
/
start.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
var CertService = require('./index.js');
var log = require('./lib/logger');
var zxcvbn = require('zxcvbn');
var assert = require('chai').assert;
var validator = require('validator');
var checkEnv = function() {
if (process.env.CERT_SERVICE_PRIVATE) {
assert.isDefined(process.env.CERT_SERVICE_PASSWORD, 'CERT_SERVICE_PASSWORD not set.');
assert.isDefined(process.env.CERT_SERVICE_USERNAME, 'CERT_SERVICE_USERNAME not set.');
var passwordStrength = zxcvbn(process.env.CERT_SERVICE_PASSWORD).score;
assert.isTrue(passwordStrength >= 2, 'CERT_SERVICE_PASSWORD too weak. Result = ' + passwordStrength);
}
assert.isDefined(process.env.CERT_DOMAINS, 'CERT_DOMAINS not set.');
assert.isDefined(process.env.CERT_EMAIL, 'CERT_EMAIL not set.');
assert.isTrue(validator.isEmail(process.env.CERT_EMAIL), 'CERT_EMAIL is not a valid email address');
};
try {
checkEnv();
} catch(err) {
return log.error({
error: err.message
}, 'Missing or wrong environment variables. See error text for more details');
}
var certService = new CertService({
privateRoutes: process.env.CERT_SERVICE_PRIVATE,
password: process.env.CERT_SERVICE_PASSWORD,
username: process.env.CERT_SERVICE_USERNAME,
domains: process.env.CERT_DOMAINS.split(','),
email: process.env.CERT_EMAIL
});
certService.start(function(err) {
if (err) {
return log.error('Failed to start cert service');
}
return log.info('Succeeded to start cert service');
});