@abtnode/certificate-manager 1.7.9 → 1.7.12
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/libs/acme-manager.js +36 -34
- package/libs/queue.js +11 -0
- package/package.json +10 -9
- package/sdk/manager.js +1 -0
package/libs/acme-manager.js
CHANGED
|
@@ -31,24 +31,23 @@ class Manager extends EventEmitter {
|
|
|
31
31
|
this.maintainerEmail = maintainerEmail;
|
|
32
32
|
this.renewalOffsetInDay = renewalOffsetInDay;
|
|
33
33
|
this.dataDir = dataDir;
|
|
34
|
+
this.getJobId = (job) => (job ? md5(`${job.domain}-${job.challenge}`) : '');
|
|
34
35
|
this.queue = createQueue({
|
|
35
36
|
name: 'create-cert-queue',
|
|
36
37
|
dataDir,
|
|
37
|
-
onJob: async (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
domain: data.domain,
|
|
42
|
-
subscriberEmail: this.subscriberEmail,
|
|
43
|
-
challenges: { 'http-01': http01 },
|
|
44
|
-
});
|
|
38
|
+
onJob: async (data) => {
|
|
39
|
+
if (process.env.NODE_ENV === 'test') {
|
|
40
|
+
logger.info('skip in test environment');
|
|
41
|
+
return;
|
|
45
42
|
}
|
|
43
|
+
|
|
44
|
+
await this._createOrRenewCert(data);
|
|
46
45
|
},
|
|
47
46
|
options: {
|
|
48
|
-
maxRetries:
|
|
47
|
+
maxRetries: 0,
|
|
49
48
|
retryDelay: 60 * 1000,
|
|
50
49
|
maxTimeout: 60 * 1000, // throw timeout error after 1 minutes
|
|
51
|
-
id: (job) => (job
|
|
50
|
+
id: (job) => this.getJobId(job),
|
|
52
51
|
},
|
|
53
52
|
});
|
|
54
53
|
}
|
|
@@ -56,30 +55,39 @@ class Manager extends EventEmitter {
|
|
|
56
55
|
getJobSchedular() {
|
|
57
56
|
return {
|
|
58
57
|
name: 'check-renewal-cert-job',
|
|
59
|
-
time:
|
|
58
|
+
time: '0 0 9 * * *', // 每天执行一次
|
|
60
59
|
fn: this.checkRenewalCerts.bind(this),
|
|
61
60
|
options: { runOnInit: false },
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
63
|
|
|
64
|
+
async pushToJobQueue(domain) {
|
|
65
|
+
const jobData = { domain, subscriberEmail: this.maintainerEmail, challenges: { 'http-01': http01 } };
|
|
66
|
+
|
|
67
|
+
const job = await this.queue.getJob(this.getJobId(jobData));
|
|
68
|
+
|
|
69
|
+
if (!job) {
|
|
70
|
+
this.queue.push(jobData);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
async add(domain) {
|
|
66
75
|
if (!domain) {
|
|
67
76
|
throw new Error('domain is required when add domain');
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
79
|
+
let cert = await states.certificate.findOne({ domain });
|
|
80
|
+
if (!cert) {
|
|
81
|
+
cert = await states.certificate.insert({
|
|
82
|
+
domain,
|
|
83
|
+
source: CERT_SOURCE.letsEncrypt,
|
|
84
|
+
status: CERT_STATUS.waiting,
|
|
85
|
+
});
|
|
73
86
|
}
|
|
74
87
|
|
|
75
|
-
|
|
76
|
-
domain,
|
|
77
|
-
source: CERT_SOURCE.letsEncrypt,
|
|
78
|
-
status: CERT_STATUS.waiting,
|
|
79
|
-
});
|
|
88
|
+
await this.pushToJobQueue(domain);
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
return result;
|
|
90
|
+
return cert;
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
getCertState(domain) {
|
|
@@ -146,22 +154,16 @@ class Manager extends EventEmitter {
|
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
async checkRenewalCerts() {
|
|
149
|
-
logger.info('run
|
|
157
|
+
logger.info('run renewal certificate job');
|
|
150
158
|
const certs = await states.certificate.find({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
source: CERT_SOURCE.letsEncrypt,
|
|
154
|
-
status: { $in: [CERT_STATUS.waiting, CERT_STATUS.error] },
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
source: CERT_SOURCE.letsEncrypt,
|
|
158
|
-
status: CERT_STATUS.generated,
|
|
159
|
-
'meta.validTo': { $lte: moment().add(this.renewalOffsetInDay, 'days').unix() * 1000 },
|
|
160
|
-
},
|
|
161
|
-
],
|
|
159
|
+
source: CERT_SOURCE.letsEncrypt,
|
|
160
|
+
'meta.validTo': { $exists: true, $lte: moment().add(this.renewalOffsetInDay, 'days').unix() * 1000 },
|
|
162
161
|
});
|
|
163
162
|
|
|
164
|
-
|
|
163
|
+
for (const cert of certs) {
|
|
164
|
+
// eslint-disable-next-line no-await-in-loop
|
|
165
|
+
await this.pushToJobQueue(cert.domain);
|
|
166
|
+
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
|
package/libs/queue.js
CHANGED
|
@@ -8,5 +8,16 @@ module.exports = ({ name, dataDir, onJob, options = {} }) => {
|
|
|
8
8
|
options,
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
queue.getJob = (id) =>
|
|
12
|
+
new Promise((resolve, reject) => {
|
|
13
|
+
queue.store.getJob(id, (error, job) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
return reject(error);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return resolve(job);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
11
22
|
return queue;
|
|
12
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/certificate-manager",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.12",
|
|
4
4
|
"description": "Manage ABT Node SSL certificates",
|
|
5
5
|
"author": "polunzh <polunzh@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ArcBlock/blocklet-server#readme",
|
|
@@ -23,19 +23,20 @@
|
|
|
23
23
|
"url": "git+https://github.com/ArcBlock/blocklet-server.git"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"test": "echo \"Error: run tests from root\"",
|
|
27
26
|
"lint": "eslint libs routes sdk states validators index.js",
|
|
28
|
-
"lint:fix": "eslint --fix tests lib"
|
|
27
|
+
"lint:fix": "eslint --fix tests lib",
|
|
28
|
+
"test": "node tools/jest.js",
|
|
29
|
+
"coverage": "npm run test -- --coverage"
|
|
29
30
|
},
|
|
30
31
|
"bugs": {
|
|
31
32
|
"url": "https://github.com/ArcBlock/blocklet-server/issues"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@abtnode/cron": "1.7.
|
|
35
|
-
"@abtnode/db": "1.7.
|
|
36
|
-
"@abtnode/logger": "1.7.
|
|
37
|
-
"@abtnode/queue": "1.7.
|
|
38
|
-
"@abtnode/util": "1.7.
|
|
35
|
+
"@abtnode/cron": "1.7.12",
|
|
36
|
+
"@abtnode/db": "1.7.12",
|
|
37
|
+
"@abtnode/logger": "1.7.12",
|
|
38
|
+
"@abtnode/queue": "1.7.12",
|
|
39
|
+
"@abtnode/util": "1.7.12",
|
|
39
40
|
"@fidm/x509": "^1.2.1",
|
|
40
41
|
"@greenlock/manager": "^3.1.0",
|
|
41
42
|
"@nedb/core": "^1.1.0",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"punycode": "^2.1.1",
|
|
56
57
|
"ursa-optional": "^0.10.2"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "afc78b9cb92448676149262fb02432bc256a5524"
|
|
59
60
|
}
|