{"size": 2085, "ext": "js", "max_stars_repo_path": "dev-utils/saucelabs.js", "max_stars_repo_name": "elastic/apm-agent-js-core", "max_stars_repo_stars_event_min_datetime": "2018-01-04T14:12:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-17T17:11:41.000Z", "max_issues_repo_path": "dev-utils/saucelabs.js", "max_issues_repo_name": "elastic/apm-agent-js-core", "max_issues_repo_issues_event_min_datetime": "2018-02-09T11:11:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T22:33:16.000Z", "max_forks_repo_path": "dev-utils/saucelabs.js", "max_forks_repo_name": "elastic/apm-agent-js-core", "max_forks_repo_forks_event_min_datetime": "2017-11-14T09:30:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T17:45:08.000Z"}
{"max_stars_count": 17, "max_issues_count": 23, "max_forks_count": 11, "avg_line_length": 35.9482758621, "max_line_length": 90, "alphanum_fraction": 0.6992805755}
/**
 * MIT License
 *
 * Copyright (c) 2017-present, Elasticsearch BV
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

function launchSauceConnect (userConfig, done) {
  var sauceConnectLauncher = require('sauce-connect-launcher')

  var config = {
    username: userConfig && (userConfig.username || process.env.SAUCE_USERNAME),
    accessKey: userConfig && (userConfig.accessKey || process.env.SAUCE_ACCESS_KEY),
    logger: console.log,
    noSslBumpDomains: 'all'
  }

  var tryConnect = function (maxAttempts, currAttempts, done) {
    sauceConnectLauncher(config, function (err) {
      if (err) {
        console.error(err.message)
        if (currAttempts <= maxAttempts) {
          console.log('Retrying... (attempt ' + currAttempts + ' of ' + maxAttempts + ')')
          tryConnect(maxAttempts, ++currAttempts, done)
        } else {
          return process.exit(1)
        }
      } else {
        console.log('Sauce Connect ready')
        done()
      }
    })
  }

  tryConnect(3, 1, done)
}
module.exports = {
  launchSauceConnect
}
