From 53859a7a01b298e852eea58619395c09aa66f41e Mon Sep 17 00:00:00 2001 From: kking Date: Thu, 11 Feb 2021 08:39:51 -0500 Subject: [PATCH] refactor offline/endpoint queries for readability --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8d8b9ed..11a2584 100644 --- a/index.js +++ b/index.js @@ -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; @@ -83,7 +91,7 @@ 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; } @@ -91,7 +99,7 @@ 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()) { //see: https://github.com/aws/aws-sdk-js/issues/1157 s3Client.shouldDisableBodySigning = () => true }