thrown exception for non LE certificates

This commit is contained in:
Rahul Somasundaram 2021-08-24 06:01:08 +05:30
parent 1b1807c79a
commit be87c45f27
No known key found for this signature in database
GPG Key ID: B8520CB207DD49D3
2 changed files with 32 additions and 16 deletions

View File

@ -337,26 +337,42 @@ const internalCertificate = {
}, },
/** /**
* @param {Access} access
* @param {Object} data * @param {Object} data
* @param {Number} data.id * @param {Number} data.id
* @returns {Promise} * @returns {Promise}
*/ */
download: (data) => { download: (access, data) => {
const downloadName = 'npm-' + data.id + '-' + `${Date.now()}.zip`;
const opName = '/tmp/' + downloadName;
const zipDirectory = '/etc/letsencrypt/live/npm-' + data.id;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
internalCertificate.zipDirectory(zipDirectory, opName) access.can('certificates:get', data)
.then(() => { .then(() => {
logger.debug('zip completed : ', opName); return internalCertificate.get(access, data);
const resp = { })
fileName: opName .then((certificate) => {
}; if (certificate.provider === 'letsencrypt') {
resolve(resp); const zipDirectory = '/etc/letsencrypt/live/npm-' + data.id;
}).catch((err) => {
reject(err); if (!fs.existsSync(zipDirectory)) {
}); throw new error.ItemNotFoundError('Certificate ' + certificate.nice_name + ' does not exists');
}
const downloadName = 'npm-' + data.id + '-' + `${Date.now()}.zip`;
const opName = '/tmp/' + downloadName;
internalCertificate.zipDirectory(zipDirectory, opName)
.then(() => {
logger.debug('zip completed : ', opName);
const resp = {
fileName: opName
};
resolve(resp);
}).catch((err) => {
reject(err);
});
} else {
throw new error.ValidationError('Only Let\'sEncrypt certificates can be renewed');
}
}).catch((err) => reject(err));
}); });
}, },

View File

@ -228,7 +228,7 @@ router
* Renew certificate * Renew certificate
*/ */
.get((req, res, next) => { .get((req, res, next) => {
internalCertificate.download({ internalCertificate.download(res.locals.access, {
id: parseInt(req.params.certificate_id, 10) id: parseInt(req.params.certificate_id, 10)
}) })
.then((result) => { .then((result) => {