@abtnode/certificate-manager 1.7.11 → 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 +25 -26
- package/libs/queue.js +11 -0
- package/package.json +10 -9
- package/sdk/manager.js +1 -0
package/libs/acme-manager.js
CHANGED
|
@@ -35,7 +35,14 @@ class Manager extends EventEmitter {
|
|
|
35
35
|
this.queue = createQueue({
|
|
36
36
|
name: 'create-cert-queue',
|
|
37
37
|
dataDir,
|
|
38
|
-
onJob: (data) =>
|
|
38
|
+
onJob: async (data) => {
|
|
39
|
+
if (process.env.NODE_ENV === 'test') {
|
|
40
|
+
logger.info('skip in test environment');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await this._createOrRenewCert(data);
|
|
45
|
+
},
|
|
39
46
|
options: {
|
|
40
47
|
maxRetries: 0,
|
|
41
48
|
retryDelay: 60 * 1000,
|
|
@@ -48,12 +55,22 @@ class Manager extends EventEmitter {
|
|
|
48
55
|
getJobSchedular() {
|
|
49
56
|
return {
|
|
50
57
|
name: 'check-renewal-cert-job',
|
|
51
|
-
time:
|
|
58
|
+
time: '0 0 9 * * *', // 每天执行一次
|
|
52
59
|
fn: this.checkRenewalCerts.bind(this),
|
|
53
60
|
options: { runOnInit: false },
|
|
54
61
|
};
|
|
55
62
|
}
|
|
56
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
|
+
|
|
57
74
|
async add(domain) {
|
|
58
75
|
if (!domain) {
|
|
59
76
|
throw new Error('domain is required when add domain');
|
|
@@ -68,28 +85,7 @@ class Manager extends EventEmitter {
|
|
|
68
85
|
});
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
new Promise((resolve, reject) => {
|
|
73
|
-
this.queue.store.getJob(id, (error, job) => {
|
|
74
|
-
if (error) {
|
|
75
|
-
return reject(error);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return resolve(job);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const jobData = {
|
|
83
|
-
domain,
|
|
84
|
-
subscriberEmail: this.subscriberEmail,
|
|
85
|
-
challenges: { 'http-01': http01 },
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const job = await getJob(jobData);
|
|
89
|
-
|
|
90
|
-
if (!job) {
|
|
91
|
-
this.queue.push(jobData);
|
|
92
|
-
}
|
|
88
|
+
await this.pushToJobQueue(domain);
|
|
93
89
|
|
|
94
90
|
return cert;
|
|
95
91
|
}
|
|
@@ -158,13 +154,16 @@ class Manager extends EventEmitter {
|
|
|
158
154
|
}
|
|
159
155
|
|
|
160
156
|
async checkRenewalCerts() {
|
|
161
|
-
logger.info('run
|
|
157
|
+
logger.info('run renewal certificate job');
|
|
162
158
|
const certs = await states.certificate.find({
|
|
163
159
|
source: CERT_SOURCE.letsEncrypt,
|
|
164
160
|
'meta.validTo': { $exists: true, $lte: moment().add(this.renewalOffsetInDay, 'days').unix() * 1000 },
|
|
165
161
|
});
|
|
166
162
|
|
|
167
|
-
|
|
163
|
+
for (const cert of certs) {
|
|
164
|
+
// eslint-disable-next-line no-await-in-loop
|
|
165
|
+
await this.pushToJobQueue(cert.domain);
|
|
166
|
+
}
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
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
|
}
|