This commit is contained in:
Ryan Burnette 2019-04-20 18:02:45 -04:00
parent c82e718022
commit da6e37b00a
3 changed files with 31 additions and 68 deletions

View File

@ -1,4 +1,4 @@
# [greenlock-store-sequelize][1] # [greenlock-store-sequelize](https://git.rootprojects.org/root/greenlock-store-sequelize.js) | A [Root](https://rootprojects.org) project
> A database-driven Greenlock storage plugin with wildcard support. > A database-driven Greenlock storage plugin with wildcard support.
@ -8,82 +8,50 @@ To use, provide this Greenlock storage plugin as the `store` attribute when you
invoke `create`. invoke `create`.
```js ```js
var store = require('le-store-sequelize'); greenlock.create({
store: require('le-store-sequelize')
var gl = greenlock.create({
store,
approveDomains,
...
}); });
``` ```
## Wildcards & AltNames
Working with wildcards and multiple altnames requires Greenlock `>= v2.7`.
To do so you must set `opts.subject` and `opts.domains` within the
`approvedomains()` callback.
`subject` refers to "the subject of the ssl certificate" as opposed to `domain`
which indicates "the domain servername used in the current request". For
single-domain certificates they're always the same, but for multiple-domain
certificates `subject` must be the name no matter what `domain` is receiving a
request. `subject` is used as part of the name of the file storage path where
the certificate will be saved (or retrieved).
`domains` should be the list of "altnames" on the certificate, which should
include the `subject`.
## Example
```javascript
function approveDomains() {
}
```
## Configuration ## Configuration
### Defaults ### Defaults
No configuration is required. By default, you'll get a baked-in Sequelize No configuration is required. By default, you'll get a baked-in Sequelize
database running sqlite3. database running [sqlite3](https://www.npmjs.com/package/sqlite3).
```javascript
greenlock.create({
store: require('le-store-sequelize'),
...
});
```
### Database Connection ### Database Connection
Without `config.dbOptions`, the baked-in sequelize object uses sqlite3 with Without `config.dbOptions`, the baked-in sequelize object uses sqlite3 with
default options. If `config.dbOptions` is provided, you can configure the defaults. If `config.dbOptions` is provided, you can configure the database
database connection per the Sequelize documentation. connection per the Sequelize documentation.
If a dialect other than sqlite3 is used, dependencies will need to be
installed.
```javascript ```javascript
var store = require('le-store-sequelize')({
dbConfig: {
username: 'mysqluser',
password: 'mysqlpassword',
database: 'mysqldatabase,
host: '127.0.0.1',
dialect: 'mysql'
}
});
greenlock.create({ greenlock.create({
store, store: require('le-store-sequelize')({
... dbConfig: {
username: 'mysqluser',
password: 'mysqlpassword',
database: 'mysqldatabase,
host: '127.0.0.1',
dialect: 'mysql'
}
})
}); });
``` ```
The database can also be configured using an env variable. The database can also be configured using an env variable.
```javascript ```javascript
var store = require('le-store-sequelize')({ greenlock.create({
dbConfig: { store: require('greenlock-store-sequelize')({
use_env_variable: 'DB_URL' dbConfig: {
} use_env_variable: 'DB_URL'
}
})
}); });
``` ```
@ -93,16 +61,11 @@ If you already have a Sequelize object, you can pass that in as `config.db`,
circumventing the baked-in database entirely. circumventing the baked-in database entirely.
```javascript ```javascript
var db = require('./db'); var db = require('./db'); // your db
var store = require('le-store-sequelize')({
db
});
greenlock.create({ greenlock.create({
store, store: require('le-store-sequelize')({
... db
})
}); });
``` ```
[1]: https://www.npmjs.com/package/greenlock-store-sequelize

View File

@ -133,7 +133,7 @@ module.exports.create = function (config={}) {
// using xid because id is reserved by sequelize // using xid because id is reserved by sequelize
xid: opts.certificate.kid || opts.certificate.id || opts.subject xid: opts.certificate.kid || opts.certificate.id || opts.subject
} }
}) });
}).then(function ([record,created]) { }).then(function ([record,created]) {
// { privateKeyPem, privateKeyJWK } // { privateKeyPem, privateKeyJWK }
record.content = JSON.stringify(opts.keypair); record.content = JSON.stringify(opts.keypair);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function syncSequelizeModels(db) { function sync(db) {
var keys = Object.keys(db); var keys = Object.keys(db);
function next() { function next() {
@ -19,4 +19,4 @@ function isModel(key) {
return !(['sequelize','Sequelize'].includes(key)); return !(['sequelize','Sequelize'].includes(key));
} }
module.exports = syncSequelizeModels; module.exports = sync;