|  | 
| 1 |  | -'use strict' | 
|  | 1 | +'use strict'; | 
| 2 | 2 | 
 | 
| 3 |  | -const AWS = require('aws-sdk') | 
| 4 |  | -const elasticsearch = require('elasticsearch') | 
| 5 |  | -const httpAWSESClass = require('http-aws-es') | 
|  | 3 | +const AWS = require('aws-sdk'); | 
|  | 4 | +const elasticsearch = require('elasticsearch'); | 
|  | 5 | +const httpAWSESClass = require('http-aws-es'); | 
| 6 | 6 | 
 | 
| 7 | 7 | module.exports = { | 
| 8 | 8 |   createClient: createClient, | 
| 9 | 9 |   getOptions: getOptions | 
| 10 |  | -} | 
|  | 10 | +}; | 
| 11 | 11 | 
 | 
| 12 |  | -function getOptions (options) { | 
| 13 |  | -  options = options || {} | 
|  | 12 | +function getOptions(options) { | 
|  | 13 | +  options = options || {}; | 
| 14 | 14 | 
 | 
| 15 | 15 |   // serverless-offline will set IS_OFFLINE based on whether we're offline | 
| 16 |  | -  const devMode = Boolean(process.env.IS_OFFLINE) | 
|  | 16 | +  const devMode = Boolean(process.env.IS_OFFLINE); | 
| 17 | 17 | 
 | 
| 18 |  | -  const prefix = options.envPrefix || 'AWS' | 
| 19 |  | -  const region = options.region || process.env[`${prefix}_REGION`] | 
| 20 |  | -  const host = options.host || process.env[`${prefix}_HOST`] | 
|  | 18 | +  const prefix = options.envPrefix || 'AWS'; | 
|  | 19 | +  const region = options.region || process.env[`${prefix}_REGION`]; | 
|  | 20 | +  const host = options.host || process.env[`${prefix}_HOST`]; | 
| 21 | 21 | 
 | 
| 22 |  | -  delete (options.region) // this doesn't belong in ES options | 
|  | 22 | +  delete options.region; // this doesn't belong in ES options | 
| 23 | 23 | 
 | 
| 24 |  | -  if (!region) { throw new TypeError('region is required') } | 
| 25 |  | -  if (!host) { throw new TypeError('host is required') } | 
|  | 24 | +  if (!region) { | 
|  | 25 | +    throw new TypeError('region is required'); | 
|  | 26 | +  } | 
|  | 27 | +  if (!host) { | 
|  | 28 | +    throw new TypeError('host is required'); | 
|  | 29 | +  } | 
| 26 | 30 | 
 | 
| 27 |  | -  const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix) | 
|  | 31 | +  const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix); | 
| 28 | 32 | 
 | 
| 29 | 33 |   const config = Object.assign({}, options, { | 
| 30 | 34 |     host: host, | 
| 31 | 35 |     amazonES: { | 
| 32 | 36 |       region, | 
| 33 | 37 |       credentials | 
| 34 | 38 |     } | 
| 35 |  | -  }) | 
|  | 39 | +  }); | 
| 36 | 40 | 
 | 
| 37 | 41 |   // don't sign the request in offline mode | 
| 38 | 42 |   if (!devMode) { | 
| 39 |  | -    config.connectionClass = httpAWSESClass | 
|  | 43 | +    config.connectionClass = httpAWSESClass; | 
| 40 | 44 |   } | 
| 41 | 45 | 
 | 
| 42 |  | -  return config | 
|  | 46 | +  return config; | 
| 43 | 47 | } | 
| 44 | 48 | 
 | 
| 45 |  | -function createClient (options) { | 
| 46 |  | -  return new elasticsearch.Client(getOptions(options)) | 
|  | 49 | +function createClient(options) { | 
|  | 50 | +  return new elasticsearch.Client(getOptions(options)); | 
| 47 | 51 | } | 
0 commit comments