module.exports = function()

in client.js [29:79]


module.exports = function (options, basic, bearer) {
  // try to extract apihost and key first from whisk property file file and then from process.env
  let apihost
  let apiversion
  let apikey
  let ignorecerts
  let namespace = '_'
  let token
  let authHandler

  try {
    const wskpropsPath = process.env.WSK_CONFIG_FILE || path.join(os.homedir(), '.wskprops')
    const lines = fs.readFileSync(wskpropsPath, { encoding: 'utf8' }).split('\n')

    for (let line of lines) {
      let parts = line.trim().split('=')
      if (parts.length === 2) {
        if (parts[0] === 'APIHOST') {
          apihost = parts[1]
        } else if (parts[0] === 'APIVERSION') {
          apiversion = parts[1]
        } else if (parts[0] === 'AUTH') {
          apikey = parts[1]
        } else if (parts[0] === 'NAMESPACE') {
          namespace = parts[1]
        } else if (parts[0] === 'APIGW_ACCESS_TOKEN') {
          token = parts[1]
        }
      }
    }
  } catch (error) { }

  if (process.env.__OW_API_HOST) apihost = process.env.__OW_API_HOST
  if (process.env.__OW_API_KEY) apikey = process.env.__OW_API_KEY
  if (process.env.__OW_NAMESPACE) namespace = process.env.__OW_NAMESPACE
  if (process.env.__OW_IGNORE_CERTS) ignorecerts = process.env.__OW_IGNORE_CERTS
  if (process.env.__OW_APIGW_TOKEN) token = process.env.__OW_APIGW_TOKEN

  if (bearer || (!basic && namespace !== '_')) {
    // switch from basic auth to bearer token
    authHandler = {
      getAuthHeader: () => {
        return Promise.resolve(`Bearer ${token}`)
      }
    }
  }

  const wsk = openwhisk(Object.assign({ apihost, apiversion, api_key: apikey, auth_handler: authHandler, namespace, ignore_certs: ignorecerts }, options))
  wsk.compositions = new Compositions(wsk)
  return wsk
}