@@ -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
0 commit comments