Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var ComputeManagementClient = require('azure-arm-compute');
var StorageManagementClient = require('azure-arm-storage');
var NetworkManagementClient = require('azure-arm-network');
var ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient;
var SubscriptionManagementClient = require('azure-arm-resource').SubscriptionClient;
var FileTokenCache = require('../../lib/util/fileTokenCache');
var tokenCache = new FileTokenCache(path.resolve(path.join(__dirname, '../../test/tmp/tokenstore.json')));
//Environment Setup
_validateEnvironmentVariables();
var clientId = process.env['CLIENT_ID'];
var domain = process.env['DOMAIN'];
var secret = process.env['APPLICATION_SECRET'];
var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
var credentials = new msRestAzure.ApplicationTokenCredentials(clientId, domain, secret, { 'tokenCache': tokenCache });
//Sample Config
var randomIds = [];
var location = 'westus';
var resourceGroupName = _generateRandomId('testrg', randomIds);
var vmName = _generateRandomId('testvm', randomIds);
var storageAccountName = _generateRandomId('testac', randomIds);
var vnetName = _generateRandomId('testvnet', randomIds);
var subnetName = _generateRandomId('testsubnet', randomIds);
var publicIPName = _generateRandomId('testpip', randomIds);
var networkInterfaceName = _generateRandomId('testnic', randomIds);
var ipConfigName = _generateRandomId('testcrpip', randomIds);
var domainNameLabel = _generateRandomId('testdomainname', randomIds);
var osDiskName = _generateRandomId('testosdisk', randomIds);
// Ubuntu config
var async = require('async');
var msRestAzure = require('ms-rest-azure');
var ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient;
var SubscriptionManagementClient = require('azure-arm-resource').SubscriptionClient;
var WebSiteManagement = require('azure-arm-website');
var FileTokenCache = require('../../../lib/util/fileTokenCache');
var tokenCache = new FileTokenCache(path.resolve(path.join(__dirname, '../../../test/tmp/tokenstore.json')));
//Environment Setup
_validateEnvironmentVariables();
var clientId = process.env['CLIENT_ID'];
var domain = process.env['DOMAIN'];
var secret = process.env['APPLICATION_SECRET'];
var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
var credentials = new msRestAzure.ApplicationTokenCredentials(clientId, domain, secret, { 'tokenCache': tokenCache });
//Sample Config
var randomIds = {};
var location = 'westus';
var resourceGroupName = _generateRandomId('testrg', randomIds);
var hostingPlanName = _generateRandomId('plan', randomIds);
var webSiteName = _generateRandomId('testweb', randomIds);
var resourceClient = new ResourceManagementClient(credentials, subscriptionId);
var webSiteClient = new WebSiteManagement(credentials, subscriptionId);
// Work flow of this sample:
// 1. create a resource group
// 2. create a hosting plan
// 3. create a website
// 4. list websites for given subscription
_createApplicationCredentials: function() {
if(process.env['AZURE_ENVIRONMENT'] && process.env['AZURE_ENVIRONMENT'].toUpperCase() === 'DOGFOOD') {
var df = {
name: 'Dogfood',
portalUrl: 'https://windows.azure-test.net/',
activeDirectoryEndpointUrl: 'https://login.windows-ppe.net/',
activeDirectoryResourceId: 'https://management.core.windows.net/',
managementEndpointUrl: 'https://management-preview.core.windows-int.net/',
resourceManagerEndpointUrl: 'https://api-dogfood.resources.windows-int.net/'
};
var env = msRestAzure.AzureEnvironment.add(df);
return new msRestAzure.ApplicationTokenCredentials(this.clientId, this.domain, this.secret, {
'tokenCache': this.tokenCache,
'environment': env
});
}
return new msRestAzure.ApplicationTokenCredentials(this.clientId, this.domain, this.secret, {
'tokenCache': this.tokenCache
});
},
function cleanup(logger) {
const clientId = process.env['AZURE_CLIENT_ID'];
const clientSecret = process.env['AZURE_CLIENT_SECRET'];
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
const tenantId = process.env['AZURE_TENANT_ID'];
let resClientCached;
let deletedResourceGroups = [];
let deleteApplications = [];
const credsForGraph = new msrest.ApplicationTokenCredentials(
clientId,
tenantId,
clientSecret,
{ tokenAudience: 'graph' }
);
const graphClient = new GraphRbacManagementClient(credsForGraph, tenantId);
return msrest.loginWithServicePrincipalSecret(clientId, clientSecret, tenantId)
.then(creds => {
const resClient = new azurerm.ResourceManagementClient(creds, subscriptionId);
resClientCached = resClient;
return resClient.resourceGroups.list();
})
.then(resourceGroups => {
let deleteResourceGroupOperations = [];
constructor(resourceGroupName, functionAppName, subscriptionDetails) {
debug(subscriptionDetails);
this.resourceGroupName = resourceGroupName;
this._subscriptionDetails = subscriptionDetails;
this.functionAppName = functionAppName;
this.subscriptionDetails = subscriptionDetails;
this._credentials = new msRestAzure.ApplicationTokenCredentials(subscriptionDetails.clientId,
subscriptionDetails.domain,
subscriptionDetails.clientSecret);
this._rmClient = BbPromise.promisifyAll(
new resourceManagement.ResourceManagementClient(this._credentials,
subscriptionDetails.subscriptionId), {
multiArgs: true
});
this._rmClient.apiVersion = '2015-08-01';
}
function deleteSandboxEnvironment(rgPrefix, logger) {
const clientId = process.env['AZURE_CLIENT_ID'];
const clientSecret = process.env['AZURE_CLIENT_SECRET'];
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
const tenantId = process.env['AZURE_TENANT_ID'];
let resClientCached;
let deletedResourceGroups = [];
let deleteApplications = [];
let rowsCached;
let rgPrefixEntriesToDeleteCachedOperations = [];
const credsForGraph = new msrest.ApplicationTokenCredentials(
clientId,
tenantId,
clientSecret,
{ tokenAudience: 'graph' }
);
const graphClient = new GraphRbacManagementClient(credsForGraph, tenantId);
return resourceGroupMetaData(rgPrefix)
.then(rows => {
rowsCached = rows;
return msrest.loginWithServicePrincipalSecret(clientId, clientSecret, tenantId);
})
.then(creds => {
const resClient = new azurerm.ResourceManagementClient(creds, subscriptionId);
resClientCached = resClient;
accessKeyId: settings.keyId,
secretAccessKey: settings.key,
region: settings.region,
maxRetries: CONST.SDK_CLIENT.AWS.MAX_RETRIES
};
if (Number.isInteger(settings.max_retries) &&
settings.max_retries > 0) {
ec2Config = _.assign(ec2Config, {
maxRetries: settings.max_retries
});
}
return new AWS.EC2(ec2Config);
}
case 'azure':
{
const credentials = new MsRestAzure.ApplicationTokenCredentials(
settings.client_id,
settings.tenant_id,
settings.client_secret);
return new ComputeManagementClient(
credentials, settings.subscription_id);
}
default:
return new BaseComputeClient(settings);
}
});
}
.try(() => {
switch (settings.provider) {
case 'amazon':
return new AWS.EC2({
accessKeyId: settings.keyId,
secretAccessKey: settings.key,
region: settings.region
});
case 'azure':
{
const credentials = new MsRestAzure.ApplicationTokenCredentials(
settings.client_id,
settings.tenant_id,
settings.client_secret);
return new ComputeManagementClient(
credentials, settings.subscription_id);
}
default:
return new BaseComputeClient(settings);
}
});
}
return new Promise((resolve, reject) => {
const clientId = process.env['AZURE_CLIENT_ID'];
const clientSecret = process.env['AZURE_CLIENT_SECRET'];
const tenantId = process.env['AZURE_TENANT_ID'];
const identityStorageAccount = process.env['SHERLOCK_IDENTITY_STORAGE_ACCOUNT'];
const identityStorageKey = process.env['SHERLOCK_IDENTITY_STORAGE_KEY'];
const queueName = 'identity';
const desiredSpCount = process.env['SHERLOCK_DESIRED_SP_COUNT'] || 10;
logger(`Populating ${queueName} with a desired count of ${desiredSpCount} service principals(s)`);
const credsForGraph = new msrest.ApplicationTokenCredentials(
clientId,
tenantId,
clientSecret,
{ tokenAudience: 'graph' }
);
const graphClient = new GraphRbacManagementClient(
credsForGraph,
tenantId
);
const queueService = azureStorage.createQueueService(
identityStorageAccount,
identityStorageKey
);
queueService.createQueueIfNotExists(queueName, err => {