module.exports = function()

in digital-shadow/demo-car/js/aws-iot/aws-iot.js [44:110]


module.exports = function(options) {

   if (isUndefined(options.keyPath) && isUndefined(options.privateKey)) {
      throw new Error(exceptions.NO_KEY_OPTION);
   }
   if (isUndefined(options.certPath) && isUndefined(options.clientCert)) {
      throw new Error(exceptions.NO_CERT_OPTION);
   }
   if (isUndefined(options.caPath) && isUndefined(options.caCert)) {
      throw new Error(exceptions.NO_CA_OPTION);
   }
   if (!isUndefined(options.caCert)) {
      if (Buffer.isBuffer(options.caCert)) {
         options.ca = options.caCert;
      } else {
         if (filesys.existsSync(options.caCert)) {
            options.ca = filesys.readFileSync(options.caCert);
         } else {
            throw new Error(exceptions.INVALID_CA_CERT_OPTION);
         }
      }
   }
   if (!isUndefined(options.privateKey)) {
      if (Buffer.isBuffer(options.privateKey)) {
         options.key = options.privateKey;
      } else {
         if (filesys.existsSync(options.privateKey)) {
            options.key = filesys.readFileSync(options.privateKey);
         } else {
            throw new Error(exceptions.INVALID_PRIVATE_KEY_OPTION);
         }
      }
   }
   if (!isUndefined(options.clientCert)) {
      if (Buffer.isBuffer(options.clientCert)) {
         options.cert = options.clientCert;
      } else {
         if (filesys.existsSync(options.clientCert)) {
            options.cert = filesys.readFileSync(options.clientCert);
         } else {
            throw new Error(exceptions.INVALID_CLIENT_CERT_OPTION);
         }
      }
   }


   if (filesys.existsSync(options.keyPath)) {
      options.key = filesys.readFileSync(options.keyPath);
   } else if (!isUndefined(options.keyPath)) {
      throw new Error(exceptions.INVALID_KEY_PATH_OPTION);
   }
   if (filesys.existsSync(options.certPath)) {
      options.cert = filesys.readFileSync(options.certPath);
   } else if (!isUndefined(options.certPath)) {
      throw new Error(exceptions.INVALID_CERT_PATH_OPTION);
   }
   if (filesys.existsSync(options.caPath)) {
      options.ca = filesys.readFileSync(options.caPath);
   } else if (!isUndefined(options.caPath)) {
      throw new Error(exceptions.INVALID_CA_PATH_OPTION);
   }

   options.requestCert = true;

   options.rejectUnauthorized = true;

};