mirror of
https://github.com/cderche/greenlock-challenge-s3
synced 2025-05-10 15:36:33 +00:00
Codacy review
This commit is contained in:
parent
5044e1bcd5
commit
1714811bf4
@ -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
|
To run the tests yourself, create a `.env` file with the following
|
||||||
|
|
||||||
```
|
```console
|
||||||
// .env file
|
// .env file
|
||||||
AWS_ACCESS_KEY_ID=abc // Replace with your accessKeyId
|
AWS_ACCESS_KEY_ID=abc // Replace with your accessKeyId
|
||||||
AWS_SECRET_ACCESS_KEY=abc // Replace with your secretAccessKey
|
AWS_SECRET_ACCESS_KEY=abc // Replace with your secretAccessKey
|
||||||
|
4
clean.js
4
clean.js
@ -5,7 +5,7 @@ require("dotenv").config();
|
|||||||
let accessKeyId = process.env.AWS_ACCESS_KEY_ID
|
let accessKeyId = process.env.AWS_ACCESS_KEY_ID
|
||||||
, secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
|
, secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
|
||||||
, regionName = process.env.AWS_BUCKET_REGION
|
, regionName = process.env.AWS_BUCKET_REGION
|
||||||
, bucketName = process.env.AWS_BUCKET_NAME
|
, bucketName = process.env.AWS_BUCKET_NAME;
|
||||||
|
|
||||||
var AWS = require("aws-sdk");
|
var AWS = require("aws-sdk");
|
||||||
AWS.config.setPromisesDependency(Promise);
|
AWS.config.setPromisesDependency(Promise);
|
||||||
@ -30,7 +30,7 @@ s3.listObjects({ Bucket: bucketName }).promise().then((data) => {
|
|||||||
|
|
||||||
for (let i = 0; i < data.Contents.length; i++) {
|
for (let i = 0; i < data.Contents.length; i++) {
|
||||||
objectKeys.push({
|
objectKeys.push({
|
||||||
Key: data.Contents[i].Key
|
Key: data.Contents[parseInt(i)].Key
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
index.js
14
index.js
@ -1,14 +1,14 @@
|
|||||||
const AWS = require('aws-sdk');
|
const AWS = require("aws-sdk");
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
accessKeyId: null
|
accessKeyId: null
|
||||||
, secretAccessKey: null
|
, secretAccessKey: null
|
||||||
, bucketName: null
|
, bucketName: null
|
||||||
, bucketRegion: 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) => {
|
module.exports.create = (createOptions) => {
|
||||||
const options = Object.assign({}, defaultOptions, createOptions);
|
const options = Object.assign({}, defaultOptions, createOptions);
|
||||||
@ -30,15 +30,15 @@ module.exports.create = (createOptions) => {
|
|||||||
const handlers = {
|
const handlers = {
|
||||||
|
|
||||||
set: (opts) => {
|
set: (opts) => {
|
||||||
return require('./lib/set').set(opts, options, s3);
|
return require("./lib/set").set(opts, options, s3);
|
||||||
},
|
},
|
||||||
|
|
||||||
get: (opts) => {
|
get: (opts) => {
|
||||||
return require('./lib/get').get(opts, options, s3);
|
return require("./lib/get").get(opts, options, s3);
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: (opts) => {
|
remove: (opts) => {
|
||||||
return require('./lib/remove').remove(opts, options, s3);
|
return require("./lib/remove").remove(opts, options, s3);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
module.exports.get = (opts, options, s3) => {
|
module.exports.get = (opts, options, s3) => {
|
||||||
let challengeKey = path.join(options.directory, opts.challenge.token);
|
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) {
|
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 {
|
return {
|
||||||
keyAuthorization: data.Body.toString()
|
keyAuthorization: data.Body.toString()
|
||||||
}
|
}
|
||||||
@ -13,4 +13,4 @@ module.exports.get = (opts, options, s3) => {
|
|||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
};
|
@ -1,14 +1,14 @@
|
|||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
module.exports.remove = (opts, options, s3) => {
|
module.exports.remove = (opts, options, s3) => {
|
||||||
let challengeKey = path.join(options.directory, opts.challenge.token);
|
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) {
|
return s3.deleteObject({ Key: challengeKey, Bucket: options.bucketName }).promise().then(function (data) {
|
||||||
console.log('Successfully deleted challenge.');
|
console.log("Successfully deleted challenge.");
|
||||||
return data;
|
return data;
|
||||||
}).catch(function (err) {
|
}).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;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
};
|
10
lib/set.js
10
lib/set.js
@ -1,14 +1,14 @@
|
|||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
module.exports.set = (opts, options, s3) => {
|
module.exports.set = (opts, options, s3) => {
|
||||||
let challengeKey = path.join(options.directory, opts.challenge.token);
|
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) {
|
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;
|
return null;
|
||||||
}).catch(function (err) {
|
}).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;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
};
|
28
test.js
28
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
|
let accessKeyId = process.env.AWS_ACCESS_KEY_ID
|
||||||
secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
|
, secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
|
||||||
regionName = process.env.AWS_BUCKET_REGION
|
, regionName = process.env.AWS_BUCKET_REGION
|
||||||
bucketName = process.env.AWS_BUCKET_NAME
|
, bucketName = process.env.AWS_BUCKET_NAME;
|
||||||
|
|
||||||
let tester = require('greenlock-challenge-test');
|
let tester = require("greenlock-challenge-test");
|
||||||
|
|
||||||
let challenger = require('./index').create({
|
let challenger = require("./index").create({
|
||||||
accessKeyId: accessKeyId
|
accessKeyId
|
||||||
, secretAccessKey: secretAccessKey
|
, secretAccessKey
|
||||||
, regionName: regionName
|
, regionName
|
||||||
, bucketName: bucketName
|
, bucketName
|
||||||
, directory: 'acme-challenge/'
|
, directory: "acme-challenge/"
|
||||||
, debug: true
|
, debug: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let domain = 'example.com';
|
let domain = "example.com";
|
||||||
|
|
||||||
// All of these tests can pass locally, standalone without any ACME integration.
|
// 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.");
|
console.info("Test completed successfully.");
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user