Skip to content

Commit be87c45

Browse files
committed
thrown exception for non LE certificates
1 parent 1b1807c commit be87c45

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

backend/internal/certificate.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,29 +337,45 @@ const internalCertificate = {
337337
},
338338

339339
/**
340+
* @param {Access} access
340341
* @param {Object} data
341342
* @param {Number} data.id
342343
* @returns {Promise}
343344
*/
344-
download: (data) => {
345-
const downloadName = 'npm-' + data.id + '-' + `${Date.now()}.zip`;
346-
const opName = '/tmp/' + downloadName;
347-
const zipDirectory = '/etc/letsencrypt/live/npm-' + data.id;
348-
345+
download: (access, data) => {
346+
349347
return new Promise((resolve, reject) => {
350-
internalCertificate.zipDirectory(zipDirectory, opName)
348+
access.can('certificates:get', data)
351349
.then(() => {
352-
logger.debug('zip completed : ', opName);
353-
const resp = {
354-
fileName: opName
355-
};
356-
resolve(resp);
357-
}).catch((err) => {
358-
reject(err);
359-
});
350+
return internalCertificate.get(access, data);
351+
})
352+
.then((certificate) => {
353+
if (certificate.provider === 'letsencrypt') {
354+
const zipDirectory = '/etc/letsencrypt/live/npm-' + data.id;
355+
356+
if (!fs.existsSync(zipDirectory)) {
357+
throw new error.ItemNotFoundError('Certificate ' + certificate.nice_name + ' does not exists');
358+
}
359+
360+
const downloadName = 'npm-' + data.id + '-' + `${Date.now()}.zip`;
361+
const opName = '/tmp/' + downloadName;
362+
internalCertificate.zipDirectory(zipDirectory, opName)
363+
.then(() => {
364+
logger.debug('zip completed : ', opName);
365+
const resp = {
366+
fileName: opName
367+
};
368+
resolve(resp);
369+
}).catch((err) => {
370+
reject(err);
371+
});
372+
} else {
373+
throw new error.ValidationError('Only Let\'sEncrypt certificates can be renewed');
374+
}
375+
}).catch((err) => reject(err));
360376
});
361377
},
362-
378+
363379
/**
364380
* @param {String} source
365381
* @param {String} out

backend/routes/api/nginx/certificates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ router
228228
* Renew certificate
229229
*/
230230
.get((req, res, next) => {
231-
internalCertificate.download({
231+
internalCertificate.download(res.locals.access, {
232232
id: parseInt(req.params.certificate_id, 10)
233233
})
234234
.then((result) => {

0 commit comments

Comments
 (0)