2
0
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:
Cyrille 2019-05-09 12:25:25 +01:00
parent 5044e1bcd5
commit 1714811bf4
7 changed files with 38 additions and 38 deletions

View File

@ -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

View File

@ -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
});
}

View File

@ -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);
}
};

View File

@ -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;
});
}
};

View File

@ -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;
});
}
};

View File

@ -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;
});
}
};

28
test.js
View File

@ -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);