How to use the ms-rest.homeDir function in ms-rest

To help you get started, we’ve selected a few ms-rest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / login.js View on Github external
options = {};
  }
  if (!options) options = { filePath: '' };
  if (!callback) {
    throw new Error('callback cannot be null or undefined.');
  }

  let filePath = options.filePath || process.env[azureConstants.AZURE_AUTH_LOCATION];
  let subscriptionEnvVariableName = options.subscriptionEnvVariableName || 'AZURE_SUBSCRIPTION_ID';
  if (!filePath) {
    let msg = `Either provide an absolute file path to the auth file or set/export the environment variable - ${azureConstants.AZURE_AUTH_LOCATION}.`;
    return callback(new Error(msg));
  }
  //expand ~ to user's home directory.
  if (filePath.startsWith('~')) {
    filePath = msRest.homeDir(filePath.slice(1));
  }

  let content = null, credsObj = {}, optionsForSpSecret = {};
  try {
    content = fs.readFileSync(filePath, { encoding: 'utf8' });
    credsObj = JSON.parse(content);
    _validateAuthFileContent(credsObj, filePath);
  } catch (err) {
    return callback(err);
  }

  if (!credsObj.managementEndpointUrl) {
    credsObj.managementEndpointUrl = credsObj.resourceManagerEndpointUrl;
  }
  //setting the subscriptionId from auth file to the environment variable
  process.env[subscriptionEnvVariableName] = credsObj.subscriptionId;