-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prettier): switch to prettier (#2)
- Loading branch information
1 parent
5290336
commit 31b435c
Showing
4 changed files
with
1,527 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,51 @@ | ||
'use strict' | ||
'use strict'; | ||
|
||
const AWS = require('aws-sdk') | ||
const elasticsearch = require('elasticsearch') | ||
const httpAWSESClass = require('http-aws-es') | ||
const AWS = require('aws-sdk'); | ||
const elasticsearch = require('elasticsearch'); | ||
const httpAWSESClass = require('http-aws-es'); | ||
|
||
module.exports = { | ||
createClient: createClient, | ||
getOptions: getOptions | ||
} | ||
}; | ||
|
||
function getOptions (options) { | ||
options = options || {} | ||
function getOptions(options) { | ||
options = options || {}; | ||
|
||
// serverless-offline will set IS_OFFLINE based on whether we're offline | ||
const devMode = Boolean(process.env.IS_OFFLINE) | ||
const devMode = Boolean(process.env.IS_OFFLINE); | ||
|
||
const prefix = options.envPrefix || 'AWS' | ||
const region = options.region || process.env[`${prefix}_REGION`] | ||
const host = options.host || process.env[`${prefix}_HOST`] | ||
const prefix = options.envPrefix || 'AWS'; | ||
const region = options.region || process.env[`${prefix}_REGION`]; | ||
const host = options.host || process.env[`${prefix}_HOST`]; | ||
|
||
delete (options.region) // this doesn't belong in ES options | ||
delete options.region; // this doesn't belong in ES options | ||
|
||
if (!region) { throw new TypeError('region is required') } | ||
if (!host) { throw new TypeError('host is required') } | ||
if (!region) { | ||
throw new TypeError('region is required'); | ||
} | ||
if (!host) { | ||
throw new TypeError('host is required'); | ||
} | ||
|
||
const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix) | ||
const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix); | ||
|
||
const config = Object.assign({}, options, { | ||
host: host, | ||
amazonES: { | ||
region, | ||
credentials | ||
} | ||
}) | ||
}); | ||
|
||
// don't sign the request in offline mode | ||
if (!devMode) { | ||
config.connectionClass = httpAWSESClass | ||
config.connectionClass = httpAWSESClass; | ||
} | ||
|
||
return config | ||
return config; | ||
} | ||
|
||
function createClient (options) { | ||
return new elasticsearch.Client(getOptions(options)) | ||
function createClient(options) { | ||
return new elasticsearch.Client(getOptions(options)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.