Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;