diff --git a/README.md b/README.md index aa4cd9e..820e6d3 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The strategy is tested against the [greenlock-challenge-test](https://git.coolaj To run the tests yourself, create a `.env` file with the following -``` +```console // .env file AWS_ACCESS_KEY_ID=abc // Replace with your accessKeyId AWS_SECRET_ACCESS_KEY=abc // Replace with your secretAccessKey diff --git a/clean.js b/clean.js index d6db2f2..aa3f948 100644 --- a/clean.js +++ b/clean.js @@ -5,7 +5,7 @@ require("dotenv").config(); let accessKeyId = process.env.AWS_ACCESS_KEY_ID , secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY , regionName = process.env.AWS_BUCKET_REGION - , bucketName = process.env.AWS_BUCKET_NAME + , bucketName = process.env.AWS_BUCKET_NAME; var AWS = require("aws-sdk"); AWS.config.setPromisesDependency(Promise); @@ -30,7 +30,7 @@ s3.listObjects({ Bucket: bucketName }).promise().then((data) => { for (let i = 0; i < data.Contents.length; i++) { objectKeys.push({ - Key: data.Contents[i].Key + Key: data.Contents[parseInt(i)].Key }); } diff --git a/index.js b/index.js index 3af224e..a0e91ab 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ -const AWS = require('aws-sdk'); +const AWS = require("aws-sdk"); const defaultOptions = { accessKeyId: null , secretAccessKey: null , bucketName: null , bucketRegion: null - , directory: 'acme-challenge/' -} + , directory: "acme-challenge/" +}; -const s3 = new AWS.S3({ apiVersion: '2006-03-01' }); +const s3 = new AWS.S3({ apiVersion: "2006-03-01" }); module.exports.create = (createOptions) => { const options = Object.assign({}, defaultOptions, createOptions); @@ -30,15 +30,15 @@ module.exports.create = (createOptions) => { const handlers = { set: (opts) => { - return require('./lib/set').set(opts, options, s3); + return require("./lib/set").set(opts, options, s3); }, get: (opts) => { - return require('./lib/get').get(opts, options, s3); + return require("./lib/get").get(opts, options, s3); }, remove: (opts) => { - return require('./lib/remove').remove(opts, options, s3); + return require("./lib/remove").remove(opts, options, s3); } }; diff --git a/lib/get.js b/lib/get.js index e6501fd..1fdb7a0 100644 --- a/lib/get.js +++ b/lib/get.js @@ -1,11 +1,11 @@ -const path = require('path'); +const path = require("path"); module.exports.get = (opts, options, s3) => { let challengeKey = path.join(options.directory, opts.challenge.token); - console.log('get', challengeKey); + console.log("get", challengeKey); return s3.getObject({ Key: challengeKey, Bucket: options.bucketName }).promise().then(function (data) { - console.log('Successfully retrieved challenge.' + data.Body.toString()); + console.log("Successfully retrieved challenge." + data.Body.toString()); return { keyAuthorization: data.Body.toString() } @@ -13,4 +13,4 @@ module.exports.get = (opts, options, s3) => { console.error(err.message); return null; }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/lib/remove.js b/lib/remove.js index 8154733..2b9b08b 100644 --- a/lib/remove.js +++ b/lib/remove.js @@ -1,14 +1,14 @@ -const path = require('path'); +const path = require("path"); module.exports.remove = (opts, options, s3) => { let challengeKey = path.join(options.directory, opts.challenge.token); - console.log('remove', challengeKey); + console.log("remove", challengeKey); return s3.deleteObject({ Key: challengeKey, Bucket: options.bucketName }).promise().then(function (data) { - console.log('Successfully deleted challenge.'); + console.log("Successfully deleted challenge."); return data; }).catch(function (err) { - console.error('There was an error deleting your challenge: ', err.message); + console.error("There was an error deleting your challenge: ", err.message); throw err; }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/lib/set.js b/lib/set.js index 359a7e8..f73fe61 100644 --- a/lib/set.js +++ b/lib/set.js @@ -1,14 +1,14 @@ -const path = require('path'); +const path = require("path"); module.exports.set = (opts, options, s3) => { let challengeKey = path.join(options.directory, opts.challenge.token); - console.log('set', challengeKey); + console.log("set", challengeKey); return s3.putObject({ Key: challengeKey, Body: opts.challenge.keyAuthorization, Bucket: options.bucketName }).promise().then(function (data) { - console.log('Successfully created challenge.'); + console.log("Successfully created challenge."); return null; }).catch(function (err) { - console.error('There was an error creating your challenge: ' + err.message); + console.error("There was an error creating your challenge: " + err.message); throw err; }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/test.js b/test.js index 79d9c81..70edfb0 100644 --- a/test.js +++ b/test.js @@ -1,27 +1,27 @@ -console.log('Testing the challenge.'); +console.log("Testing the challenge."); -require('dotenv').config(); +require("dotenv").config(); let accessKeyId = process.env.AWS_ACCESS_KEY_ID -secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY -regionName = process.env.AWS_BUCKET_REGION -bucketName = process.env.AWS_BUCKET_NAME + , secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY + , regionName = process.env.AWS_BUCKET_REGION + , bucketName = process.env.AWS_BUCKET_NAME; -let tester = require('greenlock-challenge-test'); +let tester = require("greenlock-challenge-test"); -let challenger = require('./index').create({ - accessKeyId: accessKeyId - , secretAccessKey: secretAccessKey - , regionName: regionName - , bucketName: bucketName - , directory: 'acme-challenge/' +let challenger = require("./index").create({ + accessKeyId + , secretAccessKey + , regionName + , bucketName + , directory: "acme-challenge/" , debug: true }); -let domain = 'example.com'; +let domain = "example.com"; // All of these tests can pass locally, standalone without any ACME integration. -tester.test('http-01', domain, challenger).then(() => { +tester.test("http-01", domain, challenger).then(() => { console.info("Test completed successfully."); }).catch((err) => { console.error(err.message);