forked from llun/le-store-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
50 lines (40 loc) · 1.46 KB
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const Promise = require('bluebird')
const AWS = require('aws-sdk')
const path = require('path')
const Accounts = require('./accounts')
const Certificates = require('./certificates')
const Keypairs = require('./keypairs')
const Configs = require('./configs')
const DEFAULT_OPTIONS = {
privkeyPath: ':configDir/live/:hostname/privkey.pem',
fullchainPath: ':configDir/live/:hostname/fullchain.pem',
certPath: ':configDir/live/:hostname/cert.pem',
chainPath: ':configDir/live/:hostname/chain.pem',
configDir: 'configs',
renewalPath: ':configDir/renewal/:hostname.conf',
renewalDir: ':configDir/renewal/',
accountsDir: ':configDir/accounts/:serverDir',
serverDirGet({ server }) {
return (server || '').replace('https://', '').replace(/(\/)$/, '').replace(/\//g, path.sep)
},
rsaKeySize: 2048
}
class Store {
constructor(options) {
this.s3 = Promise.promisifyAll(new AWS.S3(options.S3))
options.domainKeyPath = options.domainKeyPath ||
options.privkeyPath || DEFAULT_OPTIONS.privkeyPath
this.options = Object.assign({}, DEFAULT_OPTIONS, options)
if (!this.options.S3.bucketName) {
return Promise.reject(new Error('missing bucket name in S3 options'))
}
this.keypairs = new Keypairs(this)
this.configs = new Configs(this)
this.accounts = new Accounts(this, this.keypairs)
this.certificates = new Certificates(this, this.keypairs, this.configs)
}
getOptions() {
return this.options
}
}
module.exports = Store