Skip to content

Commit

Permalink
fix: enable to use s3 compatible (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
tk3fftk authored and tkyi committed Feb 5, 2019
1 parent fce6524 commit 8226747
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
17 changes: 12 additions & 5 deletions helpers/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ class AwsClient {
* Construct a Client
* @method constructor
* @param {Object} config
* @param {String} config.accessKeyId AWS access key ID.
* @param {String} config.secretAccessKey AWS secret access key.
* @param {String} config.endpoint S3 compatible endpoint
* @param {String} config.accessKeyId S3 access key ID.
* @param {String} config.secretAccessKey S3 secret access key.
* @param {String} config.region the region to send service requests to
* @param {String} config.forcePathStyle whether to force path style URLs for S3 objects
* @param {String} config.bucket s3 bucket
* @param {String} config.bucket S3 bucket
*/
constructor(config) {
this.client = new AWS.S3({
const options = {
accessKeyId: config.accessKeyId,
secretAccessKey: config.secretAccessKey,
region: config.region,
s3ForcePathStyle: config.forcePathStyle
});
};

if (config.endpoint) {
options.endpoint = config.endpoint;
}

this.client = new AWS.S3(options);
this.bucket = config.bucket;
}

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"pretest": "eslint .",
"test": "jenkins-mocha --recursive --timeout 3000",
"test": "jenkins-mocha --recursive --timeout 3000 --exit",
"start": "./bin/server",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand Down Expand Up @@ -45,15 +45,15 @@
}
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"chai": "^4.0.0",
"chai-as-promised": "^7.1.1",
"eslint": "^4.3.0",
"eslint-config-screwdriver": "^3.0.0",
"jenkins-mocha": "^4.0.0",
"jenkins-mocha": "^6.0.0",
"js-yaml": "^3.6.1",
"jsonwebtoken": "^8.4.0",
"mockery": "^2.0.0",
"sinon": "^4.5.0"
"sinon": "^7.0.0"
},
"dependencies": {
"aws-sdk": "^2.361.0",
Expand All @@ -75,6 +75,6 @@
"request": "^2.88.0",
"screwdriver-data-schema": "^18.34.2",
"vision": "^5.4.3",
"winston": "^2.2.0"
"winston": "^3.2.1"
}
}
28 changes: 18 additions & 10 deletions plugins/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ exports.plugin = {
// Update last modified timestamp to reset the lifecycle
await awsClient.updateLastModified(cacheKey, (e) => {
if (e) {
console.log('Failed to update last modified timestamp: ', e);
request.log([cacheName, 'error'],
`Failed to update last modified timestamp: ${e}`);
}
});
} catch (err) {
Expand Down Expand Up @@ -306,10 +307,13 @@ exports.plugin = {

try {
await cache.drop(cacheKey);
request.log([cacheKey, 'info'], 'Successfully deleted a cache');

return h.response();
return h.response().code(204);
} catch (err) {
throw err;
request.log([cacheKey, 'error'], `Failed to delete a cache: ${err}`);

throw boom.serverUnavailable(err.message, err);
}
},
options: {
Expand Down Expand Up @@ -404,14 +408,18 @@ exports.plugin = {
}

return reject(err);
})).then(() => h.response().code(200))
.catch((err) => {
if (err === 'Permission denied') {
return boom.forbidden(err);
}
})).then(() => {
request.log([cachePath, 'info'], 'Successfully deleted a cache');

return h.response().code(500);
});
return h.response().code(204);
}).catch((err) => {
if (err === 'Permission denied') {
return boom.forbidden(err);
}
request.log([cachePath, 'error'], `Failed to delete a cache: ${err}`);

return h.response().code(500);
});
},
options: {
description: 'Invalidate cache folder',
Expand Down
7 changes: 5 additions & 2 deletions plugins/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ exports.plugin = {

try {
await cache.drop(id);
request.log([id, 'info'], 'Successfully deleted a command');

return h.response();
return h.response().code(204);
} catch (err) {
throw err;
request.log([id, 'error'], `Failed to delete a command: ${err}`);

throw boom.serverUnavailable(err.message, err);
}
},
options: {
Expand Down
10 changes: 5 additions & 5 deletions test/plugins/caches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ describe('events plugin test', () => {
assert.equal(getResponse.statusCode, 404);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);
});
}));

Expand All @@ -586,7 +586,7 @@ describe('events plugin test', () => {
assert.equal(getResponse.statusCode, 200);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);

return server.inject(getOptions).then((getResponse2) => {
assert.equal(getResponse2.statusCode, 404);
Expand Down Expand Up @@ -645,7 +645,7 @@ describe('events plugin test', () => {
assert.equal(getResponse.statusCode, 404);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);
});
}));

Expand All @@ -664,7 +664,7 @@ describe('events plugin test', () => {
assert.equal(getResponse.statusCode, 200);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);

return server.inject(getOptions).then((getResponse2) => {
assert.equal(getResponse2.statusCode, 404);
Expand Down Expand Up @@ -700,7 +700,7 @@ describe('events plugin test', () => {
});

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/plugins/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('commands plugin test', () => {
assert.equal(getResponse.statusCode, 404);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);
});
}));

Expand All @@ -243,7 +243,7 @@ describe('commands plugin test', () => {
assert.equal(getResponse.statusCode, 200);

return server.inject(deleteOptions).then((deleteResponse) => {
assert.equal(deleteResponse.statusCode, 200);
assert.equal(deleteResponse.statusCode, 204);

return server.inject(getOptions).then((getResponse2) => {
assert.equal(getResponse2.statusCode, 404);
Expand Down

0 comments on commit 8226747

Please sign in to comment.