-
Notifications
You must be signed in to change notification settings - Fork 3
/
store.js
84 lines (67 loc) · 1.89 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// @flow
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
}
/*::
type S3 = {
bucketName: string
}
type Options = {
S3: S3,
privkeyPath: string,
fullchangePath: string,
certPath: string,
chainPath: string,
configDir: string,
renewalPath: string,
renewalDir: string,
accountsDir: string,
rsaKeySize: number,
domainKeyPath: string
}
*/
class Store {
/*::
s3: AWS.S3
options: Options
keypairs: Keypairs
configs: Configs
accounts: Accounts
certificates: Certificates
*/
constructor(options /*: Options*/) {
this.s3 = 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