@@ -337,29 +337,45 @@ const internalCertificate = {
337
337
} ,
338
338
339
339
/**
340
+ * @param {Access } access
340
341
* @param {Object } data
341
342
* @param {Number } data.id
342
343
* @returns {Promise }
343
344
*/
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
+
349
347
return new Promise ( ( resolve , reject ) => {
350
- internalCertificate . zipDirectory ( zipDirectory , opName )
348
+ access . can ( 'certificates:get' , data )
351
349
. 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 ) ) ;
360
376
} ) ;
361
377
} ,
362
-
378
+
363
379
/**
364
380
* @param {String } source
365
381
* @param {String } out
0 commit comments