Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ your environment:
| `s3-cert-bucket` | An S3 bucket to place domain certificate data into. You will need to create this bucket and assign the [IAM role](AWS.md) to read/write. |
| `s3-folder` | A folder within the above buckets to place the files under, in case there are other contents of these buckets. |
| `certificate-info` | Object containing [certificate information mapping](https://github.com/ocelotconsulting/node-letsencrypt-lambda#certificate-info-field-of-configuration-file) certificate names to domains. |
| `certificate-info-file` | As an alternative to `certificate-info`, you can specify here the name of a JSON file containing the certificate information mapping. This will be looked for in the `s3-folder` folder of the `s3-account-bucket`. |

## Execution
Follow these steps to get started:
Expand Down
18 changes: 17 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const generateCertificate = require('./src/acme/generateCertificate')
const isExpired = require('./src/util/isExpired')
const config = require('./config/default.json')
const readFile = require('./src/aws/s3/readFile')

const single = (key, domains) =>
isExpired(key)
Expand All @@ -24,8 +25,23 @@ const certificates = (certDefinitions) =>
single(certKey, certDefinitions[certKey])
)

const certDefinitions = () => {
if (config['certificate-info']) {
return Promise.accept(config['certificate-info'])
} else if (config['certificate-info-file']) {
return readFile(config['s3-account-bucket'],
config['s3-folder'],
config['certificate-info-file']
).then((data) => JSON.parse(data.Body.toString()))
} else {
return Promise.reject('need to specify either certificate-info or certificate-info-file in config')
}
}

const updateCertificates = (options, context) =>
Promise.all(certificates(config['certificate-info']))
certDefinitions()
.then((definitions) => Promise.all(certificates(definitions)))
.then((msgs) => context.succeed(msgs))
.catch((e) => context.fail(e))

module.exports = { handler: updateCertificates }
4 changes: 4 additions & 0 deletions bin/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const testContext = {
succeed: (data) => {
console.log(data)
process.exit(0)
},
fail: (data) => {
console.error(data)
process.exit(1)
}
}

Expand Down