@@ -14,6 +14,7 @@ const letsencryptStaging = process.env.NODE_ENV !== 'production';
14
14
const letsencryptConfig = '/etc/letsencrypt.ini' ;
15
15
const certbotCommand = 'certbot' ;
16
16
const archiver = require ( 'archiver' ) ;
17
+ const path = require ( 'path' ) ;
17
18
18
19
function omissions ( ) {
19
20
return [ 'is_deleted' ] ;
@@ -350,22 +351,25 @@ const internalCertificate = {
350
351
} )
351
352
. then ( ( certificate ) => {
352
353
if ( certificate . provider === 'letsencrypt' ) {
353
- const zipDirectory = '/etc/letsencrypt/archive /npm-' + data . id ;
354
+ const zipDirectory = '/etc/letsencrypt/live /npm-' + data . id ;
354
355
355
356
if ( ! fs . existsSync ( zipDirectory ) ) {
356
357
throw new error . ItemNotFoundError ( 'Certificate ' + certificate . nice_name + ' does not exists' ) ;
357
358
}
358
359
360
+ let certFiles = fs . readdirSync ( zipDirectory )
361
+ . filter ( ( fn ) => fn . endsWith ( '.pem' ) )
362
+ . map ( ( fn ) => fs . realpathSync ( path . join ( zipDirectory , fn ) ) ) ;
359
363
const downloadName = 'npm-' + data . id + '-' + `${ Date . now ( ) } .zip` ;
360
364
const opName = '/tmp/' + downloadName ;
361
- internalCertificate . zipDirectory ( zipDirectory , opName )
365
+ internalCertificate . zipFiles ( certFiles , opName )
362
366
. then ( ( ) => {
363
367
logger . debug ( 'zip completed : ' , opName ) ;
364
368
const resp = {
365
369
fileName : opName
366
370
} ;
367
371
resolve ( resp ) ;
368
- } ) ;
372
+ } ) . catch ( ( err ) => reject ( err ) ) ;
369
373
} else {
370
374
throw new error . ValidationError ( 'Only Let\'sEncrypt certificates can be downloaded' ) ;
371
375
}
@@ -378,21 +382,26 @@ const internalCertificate = {
378
382
* @param {String } out
379
383
* @returns {Promise }
380
384
*/
381
- zipDirectory ( source , out ) {
385
+ zipFiles ( source , out ) {
382
386
const archive = archiver ( 'zip' , { zlib : { level : 9 } } ) ;
383
387
const stream = fs . createWriteStream ( out ) ;
384
388
385
389
return new Promise ( ( resolve , reject ) => {
390
+ source
391
+ . map ( ( fl ) => {
392
+ let fileName = path . basename ( fl ) ;
393
+ logger . debug ( fileName , ' added to certificate download zip' ) ;
394
+ archive . file ( fl , { name : fileName } ) ;
395
+ } ) ;
386
396
archive
387
- . directory ( source , false )
388
397
. on ( 'error' , ( err ) => reject ( err ) )
389
398
. pipe ( stream ) ;
390
399
391
400
stream . on ( 'close' , ( ) => resolve ( ) ) ;
392
401
archive . finalize ( ) ;
393
402
} ) ;
394
403
} ,
395
-
404
+
396
405
/**
397
406
* @param {Access } access
398
407
* @param {Object } data
0 commit comments