Skip to content

Commit

Permalink
refactor offline/endpoint queries for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
kking-biometrica committed Feb 11, 2021
1 parent f8d15cc commit 53859a7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class ServerlessS3Sync {
};
}

isOffline() {
return String(this.options.offline).toUpperCase() === 'TRUE' || process.env.IS_OFFLINE;
}

getEndpoint() {
return this.serverless.service.custom.s3Sync.hasOwnProperty('endpoint') ? this.serverless.service.custom.s3Sync.endpoint : null;
}

client() {
const provider = this.serverless.getProvider('aws');
let awsCredentials, region;
Expand All @@ -83,15 +91,15 @@ class ServerlessS3Sync {
region: region,
credentials: awsCredentials
};
if(this.serverless.service.custom.s3Sync.hasOwnProperty('endpoint') && (String(this.options.offline).toUpperCase() === 'TRUE' || process.env.IS_OFFLINE)) {
if(this.getEndpoint() && this.isOffline()) {
s3Options.endpoint = new provider.sdk.Endpoint(this.serverless.service.custom.s3Sync.endpoint);
s3Options.s3ForcePathStyle = true;
}
const s3Client = new provider.sdk.S3({
region: region,
credentials: awsCredentials
});
if(this.serverless.service.custom.s3Sync.hasOwnProperty('endpoint') && String(this.options.offline).toUpperCase() === 'TRUE' || process.env.IS_OFFLINE) {
if(this.getEndpoint() && this.isOffline()) {
//see: https://github.com/aws/aws-sdk-js/issues/1157
s3Client.shouldDisableBodySigning = () => true
}
Expand Down

0 comments on commit 53859a7

Please sign in to comment.