Skip to content
This repository was archived by the owner on Jun 15, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions setup2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This script was built for the Azure CLI 2.0 preview
// for more information: http://github.com/azure/azure-cli

var uuid = require('node-uuid');
var fs = require('fs');
var spawn = require('child_process').spawn;

var uuidrg = uuid.v4().toLowerCase().replace(/-/g, '');
var resourceGroup = "rg" + uuidrg.substring(0,19);
var storageAccountName = "sa" + uuidrg.substring(0,19);
var location = "westus";
var errorHasOccurred = false;
var connectionData = "";

// az resource group create -n $resourceGroup -l $location
executeAzureCLI(['resource','group','create', '-n', resourceGroup, '-l', location], function() {

// az storage account create -l $location -g $resourceGroup -n $storageAccountName --sku Standard_RAGRS
executeAzureCLI(['storage','account','create', '-g', resourceGroup, '-l', location
, '-n', storageAccountName, '--sku', 'Standard_RAGRS' ], function()
{
//az storage account show-connection-string -g $resourceGroup -n $storageAccountName
executeAzureCLI(['storage','account','show-connection-string', '-g', resourceGroup, '-n', storageAccountName, '--output', 'json'], function(code)
{
var connectionString = JSON.parse(connectionData).string;
var stream = fs.createWriteStream("resources/config.properties");
stream.once('open', function(fd) {
stream.write('#{"uuid":"' + uuidrg + '"}\n');
stream.write('#StorageConnectionString = UseDevelopmentStorage=true\n');
stream.write('StorageConnectionString = ' + connectionString + '\n');
stream.end();
});
console.log('Setup complete.');
}, function(data)
{
connectionData += data;
});
});
});

function executeAzureCLI(params, closeCallback, stdOutCallback) {
var prc = spawn('az', params);
prc.stderr.on('data', (data) => {
errorHasOccurred = true;

process.stdout.write(`stderr: ${data}`);
});

prc.stdout.on('data', (data) => {
var outData = `${data}`;
process.stdout.write(outData);
if(stdOutCallback) {
stdOutCallback(outData);
}
});

prc.on('close', (code) => {
if(!errorHasOccurred && closeCallback) {
closeCallback(code);
}
});
}
19 changes: 19 additions & 0 deletions setup2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# This script was built for the Azure CLI 2.0 preview
# for more information: http://github.com/azure/azure-cli

uuidrg=$(uuidgen)
uuidrg=${uuidrg//-/}
uuidrg="$(tr '[:upper:]' '[:lower:]' <<< "$uuidrg")"
resourceGroup="rg${uuidrg:0:20}"
storageAccountName="sa${uuidrg:0:20}"
location="westus"

az resource group create -n $resourceGroup -l $location
az storage account create -l $location -g $resourceGroup -n $storageAccountName --sku Standard_RAGRS
connStr=$(az storage account show-connection-string -g $resourceGroup -n $storageAccountName --out tsv)
echo "#$uuidrg" > config.properties
echo '#StorageConnectionString = UseDevelopmentStorage=true' >> config.properties
echo "StorageConnectionString=${connStr:11}" >> config.properties
mv config.properties resources/
echo "Created config.properties files and placed in ./resources"
58 changes: 58 additions & 0 deletions teardown2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This script was built for the Azure CLI 2.0 preview
// for more information: http://github.com/azure/azure-cli

var fs = require("fs");
var spawn = require('child_process').spawn;
var errorHasOccurred = false;
var connectionData = "";

readUUIDFromConfigFile();

function readUUIDFromConfigFile() {
fs.readFile('resources/config.properties', (err, data) => {
if (err) throw err;
var fileData = `${data}`;
var firstLineIndex = fileData.indexOf("\n");
if(firstLineIndex > 0) {
var uuidrg = JSON.parse(fileData.substring(1, firstLineIndex + 1)).uuid;
var resourceGroup = "rg" + uuidrg.substring(0,19);

executeAzureCLI(['resource', 'group', 'delete', '-n', resourceGroup], function() {
var stream = fs.createWriteStream("resources/config.properties");
stream.once('open', function(fd) {
stream.write('#By default we are assuming you will use the Azure Storage Emulator. If you have an Azure Subscription, you can alternatively\n');
stream.write('#create a Storage Account and run against the storage service by commenting out the connection string below and using the\n');
stream.write('#second connection string - in which case you must also insert your storage account name and key in the line below.\n\n');
stream.write('StorageConnectionString = UseDevelopmentStorage=true\n');
stream.write('#StorageConnectionString = DefaultEndpointsProtocol=https;AccountName=[AccountName];AccountKey=[AccountKey]\n');
stream.end();
console.log('Teardown complete.');
});
});
}else {
console.log('unable to teardown');
}
});
}

function executeAzureCLI(params, closeCallback, stdOutCallback) {
var prc = spawn('az', params);
prc.stderr.on('data', (data) => {
errorHasOccurred = true;
process.stdout.write(`stderr: ${data}`);
});

prc.stdout.on('data', (data) => {
var outData = `${data}`;
process.stdout.write(outData);
if(stdOutCallback) {
stdOutCallback(outData);
}
});

prc.on('close', (code) => {
if(!errorHasOccurred && closeCallback) {
closeCallback(code);
}
});
}
8 changes: 8 additions & 0 deletions teardown2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# This script was built for the Azure CLI 2.0 preview
# for more information: http://github.com/azure/azure-cli

uuid=$(head -n 1 resources/config.properties)
resourceGroup="rg${uuid:1:20}"
echo "Deleting resource group: $resourceGroup..."
az resource group delete -n $resourceGroup