azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
1,691 lines (726 loc) • 237 kB
JavaScript
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var fs = require("fs");
var path = require("path");
var uuid = require("node-uuid");
var async = require("async");
var azureCommon = require("azure-common");
var profile = require("../../util/profile");
var utils = require("../../util/utils");
var PipelineChannel = require("./mobile/pipelineChannel");
var WebResource = azureCommon.WebResource;
var util = require("util");
var __ = require("underscore");
var $ = utils.getLocaleString;
exports.init = function(cli) {
var log = cli.output;
function serviceFilter(service, platform, externalPushEntity) {
servicePlatform = (service.platform || "node");
servicePushEntity = (service.enableExternalPushEntity || "false");
if (((platform != "any") && (servicePlatform != platform))) {
return false; } ;
if (((externalPushEntity != "any") && (servicePushEntity != externalPushEntity))) {
return false; } ;
return true; };
function nodeFilter(service) {
return serviceFilter(service, "node", "any"); };
function defaultFilter(service) {
return serviceFilter(service, "any", "any"); };
function promptServiceNameIfNotGiven(options, servicename, serviceFilter, _) { var result; var __frame = { name: "promptServiceNameIfNotGiven", line: 59 }; return __func(_, this, arguments, promptServiceNameIfNotGiven, 3, __frame, function __$promptServiceNameIfNotGiven() {
return cli.interaction.chooseIfNotGiven($("Mobile Service: "), $("Retrieving choices"), servicename, function(cb) {
mobile.listServices(options, function(error, services) {
if (error) { cb(error); } ;
cb(null, services.filter(serviceFilter).map(function(service) { return service.name; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
return _(null, result); }, true)); }); };
function promptTableNameIfNotGiven(options, tableName, _) { var result; var __frame = { name: "promptTableNameIfNotGiven", line: 71 }; return __func(_, this, arguments, promptTableNameIfNotGiven, 2, __frame, function __$promptTableNameIfNotGiven() {
return cli.interaction.chooseIfNotGiven($("Table: "), $("Retrieving choices"), tableName, function(cb) {
mobile.listTables(options, function(error, tables) {
if (error) { cb(error); } ;
cb(null, tables.map(function(table) { return table.name; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
return _(null, result); }, true)); }); };
function promptDomainIfNotGiven(options, domain, _) { var result; var __frame = { name: "promptDomainIfNotGiven", line: 83 }; return __func(_, this, arguments, promptDomainIfNotGiven, 2, __frame, function __$promptDomainIfNotGiven() {
return cli.interaction.chooseIfNotGiven($("Domain: "), $("Retrieving choices"), domain, function(cb) {
mobile.getDomains(options, function(error, domains) {
if (error) { cb(error); } ;
cb(null, domains.map(function(domain) { return domain; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
return _(null, result); }, true)); }); };
function promptThumbprintIfNotGiven(options, thumbprint, _) { var result; var __frame = { name: "promptThumbprintIfNotGiven", line: 95 }; return __func(_, this, arguments, promptThumbprintIfNotGiven, 2, __frame, function __$promptThumbprintIfNotGiven() {
return cli.interaction.chooseIfNotGiven($("Thumbprint: "), $("Retrieving choices"), thumbprint, function(cb) {
mobile.getCertificates(options, function(error, certificates) {
if (error) { cb(error); } ;
cb(null, certificates.map(function(certificate) { return certificate.thumbprint; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
return _(null, result); }, true)); }); };
function promptIfNotGiven(prompt, value, _) { var result; var __frame = { name: "promptIfNotGiven", line: 107 }; return __func(_, this, arguments, promptIfNotGiven, 2, __frame, function __$promptIfNotGiven() {
return cli.interaction.promptIfNotGiven(prompt, value, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
if ((result.length === 0)) {
return _(new Error(util.format($("%s must be specified"), prompt.split(":")[0]))); } ;
return _(null, result); }, true)); }); };
function promptString(prompt, callback) {
cli.prompt(prompt, function(text) {
if ((text.length > 0)) {
callback(text); }
else {
throw (new Error(util.format($("%s must be specified"), prompt.split(":")[0]))); } ; }); };
function getWebResource(options) {
var currentSubscription = profile.current.getSubscription(options.subscription), httpRequest = new WebResource();
options.subscription = currentSubscription.id;
httpRequest.url = ((currentSubscription.managementEndpointUrl + "/") + options.subscription);
httpRequest = httpRequest.withHeader("x-ms-version", "2014-01-01");
return httpRequest; };
function createClient(options) {
var currentSubscription = profile.current.getSubscription(options.subscription);
return utils.createMobileClient(currentSubscription); };
function getMobileChannel(options) {
var client = createClient(options), webResource = getWebResource(options);
webResource.json = true;
var channel = new PipelineChannel(client, webResource, log).path("services").path("mobileservices").header("Accept", "application/json");
return channel; };
function getAppManagerChannel(options) {
var client = createClient(options), webResource = getWebResource(options);
webResource.json = false;
var channel = new PipelineChannel(client, webResource, log).header("Accept", "application/xml").path("applications");
return channel; };
function getOperationChannel(options, requestId) {
var client = createClient(options), webResource = getWebResource(options);
webResource.json = true;
var channel = new PipelineChannel(client, webResource, log).path("operations").path(requestId).header("Accept", "application/json");
return channel; };
var mobile = cli.category("mobile").description($("Commands to manage your Mobile Services"));
mobile.getRegions = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("regions");
channel.get(callback); };
mobile.listServices = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices");
channel.get(callback); };
mobile.getService = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename);
channel.get(callback); };
mobile.recover = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("recover").query("targetMobileService", options.targetservicename);
channel.post(null, callback); };
mobile.migrate = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("migrate").query("targetMobileService", options.targetservicename);
channel.post(null, callback); };
mobile.getMigrationState = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("migrate").query("operationId", options.orchestrationId);
channel.get(callback); };
mobile.getScaleSettings = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scalesettings");
channel.get(function(error, scalesettings) {
if (scalesettings) {
scalesettings.numberOfInstances = (scalesettings.numberOfInstances || 1);
scalesettings.tier = findScale((scalesettings.tier || "tier1"), true); } ;
callback(error, scalesettings); }); };
mobile.setScaleSettings = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scalesettings").header("Content-Type", "application/json");
log.silly($("New scale settings:"));
log.json("silly", settings);
channel.put(JSON.stringify(settings), callback); };
mobile.getServiceSettings = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("settings");
channel.get(callback); };
function formatCrossDomainWhitelistForDisplay(crossDomainWhitelist) {
var result = "";
if (crossDomainWhitelist) {
if (Array.isArray(crossDomainWhitelist)) {
var data = [];
crossDomainWhitelist.forEach(function(host) { data.push(host.host); });
result = data.join(","); } ; }
else {
result = "localhost"; } ;
return result; };
function formatCrossDomainWhitelistForSaving(crossDomainWhitelist) {
var result = [];
crossDomainWhitelist.split(",").forEach(function(host) {
result.push({ host: host }); });
return result; };
mobile.setServiceSettings = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("settings").header("Content-Type", "application/json");
log.silly($("New service settings:"));
log.json("silly", settings);
channel.patch(JSON.stringify(settings), callback); };
mobile.getAuthSettings = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("authsettings");
channel.get(callback); };
mobile.setAuthSettings = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("authsettings").header("Content-Type", "application/json");
log.silly($("New auth settings:"));
log.json("silly", settings);
channel.put(JSON.stringify(settings), callback); };
mobile.getApnsSettings = function(options, callback) {
mobile.getPushSettings(options, function(err, settings) {
if (err) {
callback(err); }
else {
var apns = settings.apnsCredentials;
var result = {
mode: "none" };
if (apns.apnsCertificate) {
if ((apns.endpoint === "gateway.push.apple.com")) {
result.mode = "prod"; }
else if ((apns.endpoint === "gateway.sandbox.push.apple.com")) {
result.mode = "dev"; } ; } ;
callback(null, result); } ; }); };
mobile.setApnsSettings = function(options, settings, callback) {
var apnsSettings = {
apnsCredentials: {
endpoint: "None",
apnsCertificate: settings.data,
certificateKey: settings.password } };
if ((settings.mode === "dev")) {
apnsSettings.apnsCredentials.endpoint = "gateway.sandbox.push.apple.com"; }
else if ((settings.mode === "prod")) {
apnsSettings.apnsCredentials.endpoint = "gateway.push.apple.com"; } ;
mobile.patchPushSettings(options, apnsSettings, callback); };
mobile.getPushSettings = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushsettings");
channel.get(callback); };
mobile.patchPushSettings = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushsettings").header("Content-Type", "application/json");
log.silly($("patch push settings:"));
log.json("silly", settings);
channel.patch(JSON.stringify(settings), callback); };
mobile.getPushEntity = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity");
channel.get(callback); };
mobile.waitForPushEnabling = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity");
channel.poll(function(error, body) {
var retry = false;
if (error) {
callback(new Error($("Unable to determine the status of the async operation. Please check the status on the management portal."))); }
else {
log.silly($("push entity status"));
log.json("silly", body);
var status = body.externalPushEntitySettingsPropertyBag.externalPushEntityState;
if ((status === "healthy")) {
callback(); }
else if ((status === "unhealthy")) {
callback(new Error($("Operation failed. Please confirm the status on the management portal"))); }
else {
retry = true; } ; } ;
return retry; }); };
mobile.setPushEntity = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity").header("Content-Type", "application/json");
log.silly($("push entity settings"));
log.json("silly", settings);
channel.put(JSON.stringify(settings), callback); };
mobile.getPreviews = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("previewfeatures");
channel.get(callback); };
mobile.enablePreview = function(options, feature, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("previewfeatures").header("Content-Type", "application/json");
log.silly($("Enabling preview feature"));
log.json("silly", feature);
channel.post(JSON.stringify(feature), callback); };
mobile.regenerateKey = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("regenerateKey").query("type", options.type);
channel.post(null, callback); };
mobile.setKey = function(options, key, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("keys").header("Content-Type", "application/json");
log.silly($("Setting key"));
log.json("silly", key);
channel.put(JSON.stringify(key), callback); };
mobile.restartService = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("restart");
channel.post(null, callback); };
mobile.redeployService = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("redeploy");
channel.post(null, callback); };
mobile.getLogs = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("logs");
if (options.query) {
options.query.split("&").forEach(function(keyvalue) {
var kv = keyvalue.split("=");
if ((kv.length === 2)) {
channel.query(kv[0], kv[1]); }
else {
return callback(new Error($("Invalid format of query parameter"))); } ; }); }
else {
if (options.continuationToken) {
channel.query("continuationToken", options.continuationToken); } ;
channel.query("$top", (options.top || 10));
var filter = [];
if (options.type) {
filter.push((("Type eq '" + options.type) + "'")); } ;
if (options.source) {
filter.push((("Source eq '" + options.source) + "'")); } ;
if ((filter.length > 0)) {
channel.query("$filter", filter.join(" and ")); } ; } ;
channel.get(callback); };
mobile.listTables = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables");
channel.get(callback); };
mobile.getRepositorySharedFolder = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared");
channel.get(callback); };
mobile.getSharedScripts = function mobile_getSharedScripts__1(options, _) { var files; var __frame = { name: "mobile_getSharedScripts__1", line: 606 }; return __func(_, this, arguments, mobile_getSharedScripts__1, 1, __frame, function __$mobile_getSharedScripts__1() {
return mobile.getRepositorySharedFolder(options, __cb(_, __frame, 1, 23, function ___(__0, __1) { files = __1;
return _(null, __.filter(files, function(file) { return (file.name.indexOf(".js", (file.length - 3)) !== -1); })); }, true)); }); };
mobile.getSharedScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js"));
channel.get(callback); };
mobile.setSharedScript = function(options, script, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js")).header("Content-Type", "text/plain").header("If-Match", "*");
channel.put(script, callback); };
mobile.loadAllScripts = function mobile_loadAllScripts__2(options, _) { var results; var __frame = { name: "mobile_loadAllScripts__2", line: 639 }; return __func(_, this, arguments, mobile_loadAllScripts__2, 1, __frame, function __$mobile_loadAllScripts__2() {
return async.parallel({
table: function table__1(_) { var __frame = { name: "table__1", line: 641 }; return __func(_, this, arguments, table__1, 0, __frame, function __$table__1() { return mobile.getAllTableScripts(options, __cb(_, __frame, 0, 42, _, true)); }); },
shared: function shared__2(_) { var __frame = { name: "shared__2", line: 642 }; return __func(_, this, arguments, shared__2, 0, __frame, function __$shared__2() { return mobile.getSharedScripts(options, __cb(_, __frame, 0, 43, _, true)); }); },
scheduler: function scheduler__3(_) { var __frame = { name: "scheduler__3", line: 643 }; return __func(_, this, arguments, scheduler__3, 0, __frame, function __$scheduler__3() { return mobile.getSchedulerScripts(options, __cb(_, __frame, 0, 46, _, true)); }); },
api: function api__4(_) { var __frame = { name: "api__4", line: 644 }; return __func(_, this, arguments, api__4, 0, __frame, function __$api__4() { return mobile.getCustomApis(options, __cb(_, __frame, 0, 40, _, true)); }); } }, __cb(_, __frame, 1, 24, function ___(__0, __5) { results = __5;
return _(null, results); }, true)); }); };
mobile.deleteSharedScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js")).header("If-Match", "*");
channel.delete(callback); };
mobile.getCustomApis = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis");
channel.get(callback); };
mobile.createApi = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").header("Content-Type", "application/json");
log.silly($("New api settings:"));
log.json("silly", settings);
channel.post(JSON.stringify(settings), callback); };
mobile.getCustomApi = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name));
channel.get(callback); };
mobile.setCustomApi = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).header("Content-Type", "application/json");
log.silly($("Updated api settings:"));
log.json("silly", settings);
channel.put(JSON.stringify(settings), callback); };
mobile.getCustomApiScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).path("script");
channel.get(callback); };
mobile.setCustomApiScript = function(options, script, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).path("script").header("Content-Type", "text/plain");
channel.put(script, callback); };
mobile.deleteCustomApi = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name));
channel.delete(callback); };
mobile.getSchedulerScripts = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs");
channel.get(callback); };
mobile.getJob = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.jobname);
channel.get(callback); };
mobile.getSchedulerScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.script.scheduler.name).path("script");
channel.get(callback); };
mobile.setSchedulerScript = function(options, script, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.script.scheduler.name).path("script").header("Content-Type", "text/plain");
channel.put(script, callback); };
mobile.deleteSchedulerScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path((options.jobname || options.script.scheduler.name));
channel.delete(callback); };
mobile.createJob = function(options, job, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").header("Content-Type", "application/json");
channel.post(job, callback); };
mobile.setJob = function(options, job, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.jobname).header("Content-Type", "application/json");
log.silly($("New job settings:"));
log.json("silly", job);
channel.put(JSON.stringify(job), callback); };
mobile.getTableScripts = function(options, table, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(table).path("scripts");
channel.get(callback); };
mobile.getTableScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation).path("code");
channel.get(callback); };
mobile.setTableScript = function(options, script, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation).path("code").header("Content-Type", "text/plain");
channel.put(script, callback); };
mobile.deleteTableScript = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation);
channel.delete(callback); };
mobile.getAllTableScripts = function(options, callback) {
log.verbose("Subscription", options.subscription);
var results = [];
mobile.listTables(options, function(error, tables) {
if ((error || (tables.length === 0))) {
return callback(error, tables); } ;
var resultCount = 0;
var finalError;
tables.forEach(function(table) {
mobile.getTableScripts(options, table.name, function(error, scripts) {
finalError = (finalError || error);
if (Array.isArray(scripts)) {
scripts.forEach(function(script) {
script.table = table.name;
results.push(script); }); } ;
if ((++resultCount == tables.length)) {
callback(finalError, results); } ; }); }); }); };
mobile.getTable = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename);
channel.get(callback); };
mobile.createTable = function(options, settings, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").header("Content-Type", "application/json");
log.silly($("Create table:"));
log.json("silly", settings);
channel.post(JSON.stringify(settings), callback); };
mobile.deleteTable = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename);
channel.delete(callback); };
mobile.truncateTable = function(options, payload, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("truncate").header("Content-Type", "application/json");
channel.post(payload, callback); };
mobile.deleteTableRecord = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("data").query("id", options.recordid);
channel.delete(callback); };
mobile.getPermissions = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("permissions");
channel.get(callback); };
mobile.updatePermissions = function(options, newPermissions, callback) {
log.verbose("Subscription", options.subscription);
mobile.getPermissions(options, function(error, currentPermissions) {
if (error) {
return callback(error); } ;
for (var i in currentPermissions) {
if (!newPermissions[i]) {
newPermissions[i] = currentPermissions[i]; } ; };
log.silly(util.format($("Update table permissions for %s:"), options.tablename));
log.json("silly", newPermissions);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("permissions").header("Content-Type", "application/json");
channel.put(JSON.stringify(newPermissions), callback); }); };
mobile.getScripts = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("scripts");
channel.get(callback); };
mobile.getColumns = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns");
channel.get(callback); };
mobile.addColumn = function(options, column, payload, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns").path(column).header("Content-Type", "application/json");
log.silly(util.format($("Adding column %s:"), column));
log.json("silly", payload);
channel.post(JSON.stringify(payload), callback); };
mobile.deleteColumn = function(options, column, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns").path(column);
channel.delete(callback); };
mobile.createIndex = function(options, column, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("indexes").path(column);
channel.put(null, callback); };
mobile.deleteIndex = function(options, column, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("indexes").path(column);
channel.delete(callback); };
mobile.getMobileServiceApplication = function(options, callback) {
var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice")).header("Content-Type", "application/xml");
channel.get(callback); };
mobile.deleteMobileServiceApplication = function(options, callback) {
var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice")).header("Content-Type", "application/xml");
channel.delete(function(error, body, res) {
if (error) {
log.silly(util.format($("Delete mobile service application error: %s"), JSON.stringify(error, null, 2)));
return callback(error); } ;
mobile.trackAsyncOperation(options, res.headers["x-ms-request-id"], function(error) {
log.silly(util.format($("Delete mobile service application result: %s"), (error ? JSON.stringify(error, null, 2) : "ok")));
callback(error); }); }); };
mobile.getData = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("data");
if (options.query) {
options.query.split("&").forEach(function(keyvalue) {
var kv = keyvalue.split("=");
if ((kv.length === 2)) {
channel.query(kv[0], kv[1]); }
else {
return callback(new Error($("Invalid format of query parameter"))); } ; }); }
else {
channel.query("$top", (options.top || 10));
if (options.skip) {
channel.query("$skip", options.skip); } ; } ;
channel.get(callback); };
mobile.trackAsyncOperation = function(options, requestId, callback) {
var channel = getOperationChannel(options, requestId);
var errorCounter = 0;
channel.poll(function(error, body) {
var retry = false;
if (error) {
if ((++errorCounter < 3)) {
retry = true; }
else {
callback(new Error($("Unable to determine the status of the async operation. Please check the status on the management portal."))); } ; }
else {
log.silly(util.format($("Operation status: %s"), body.Status));
if ((body.Status === "Failed")) {
callback(new Error($("Operation failed. Please confirm the status on the management portal"))); }
else if ((body.Status === "InProgress")) {
retry = true; }
else if ((body.Status === "Succeeded")) {
callback(); }
else {
callback(new Error($(("Unexpected response from Microsoft Azure. " + "Please confirm the status of the mobile service in the management portal")))); } ; } ;
return retry; }); };
var resourceTypeView = {
"Microsoft.WindowsAzure.MobileServices.MobileService": "Mobile service",
"Microsoft.WindowsAzure.SQLAzure.DataBase": "SQL database",
"Microsoft.WindowsAzure.SQLAzure.Server": "SQL server" };
mobile.getFlatApplicationDescription = function(description) {
var result = {
State: description.State,
Name: description.Name,
Label: description.Label,
Resources: [] };
function flatten(resource) {
var list;
if (Array.isArray(resource)) {
list = resource; } else {
if ((typeof resource == "object")) {
list = [resource,]; } };
if (list) {
list.forEach(function(item) {
result.Resources.push(item);
item.TypeView = resourceTypeView[item.Type];
item.NameView = (item.Label || item.Name);
if ((typeof item.FailureCode === "string")) {
var match = item.FailureCode.match(/<Message\>([^<]*)<\/Message\>/);
item.Error = (match ? match[1] : item.FailureCode); } ; }); } ; };
flatten(description.InternalResources.InternalResource);
flatten(description.ExternalResources.ExternalResource);
return result; };
mobile.deleteService = function(options, callback) {
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename);
if (options.deleteData) {
channel.query("deletedata", "true"); } ;
if (options.deleteNotificationHubNamespace) {
channel.query("deleteServiceBusNamespace", "true"); } ;
channel.delete(function(error, body, response) {
log.silly($("Delete mobile service:"));
log.silly(JSON.stringify(error, null, 2));
log.silly(JSON.stringify(body, null, 2));
if (((error && response) && (response.statusCode === 404))) {
error = null; } ;
callback(error); }); };
mobile.deleteSqlServer = function(options, resource, callback) {
var sqlService = utils.createSqlClient(profile.current.getSubscription(options.subscription));
sqlService.servers.deleteMethod(resource.Name, callback); };
mobile.register = function mobile_register__3(options, _) { var subscription, progress; var __frame = { name: "mobile_register__3", line: 1267 }; return __func(_, this, arguments, mobile_register__3, 1, __frame, function __$mobile_register__3() {
subscription = profile.current.getSubscription(options.subscription);
progress = cli.interaction.progress($("Registering for mobile services")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$mobile_register__3() {
return subscription.registerAsmProvider("mobileservice", __cb(_, __frame, 5, 19, function __$mobile_register__3() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$mobile_register__3() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$mobile_register__3() { _(); }); }); }); };
mobile.getDomains = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames");
channel.get(callback); };
mobile.addDomain = function(options, domain, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain);
channel.post(null, callback); };
mobile.deleteDomain = function(options, domain, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain);
channel.delete(callback); };
mobile.getSslState = function(options, domain, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl");
channel.get(callback); };
mobile.enableSsl = function(options, domain, thumbprint, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl").path(thumbprint);
channel.post(null, callback); };
mobile.disableSsl = function(options, domain, thumbprint, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl").path(thumbprint);
channel.delete(callback); };
mobile.getCertificates = function(options, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates");
channel.get(callback); };
mobile.addCertificate = function(options, certificate, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates").header("Content-Type", "application/json");
channel.post(JSON.stringify(certificate), callback); };
mobile.deleteCertificate = function(options, thumbprint, callback) {
log.verbose("Subscription", options.subscription);
var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates").path(thumbprint);
channel.delete(callback); };
var createMobileServiceApplicationTemplate = (((((("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<Application xmlns=\"http://schemas.microsoft.com/windowsazure\">") + "<Name>##name##</Name>") + "<Label>##label##</Label>") + "<Description>##description##</Description>") + "<Configuration>##spec##</Configuration>") + "</Application>");
mobile.createService = function(options, callback) {
var subscription = profile.current.getSubscription(options.subscription);
var channel = getAppManagerChannel(options).header("Content-Type", "application/xml");
var serverRefName = ("ZumoSqlServer_" + uuid.v4().replace(/-/g, ""));
var serverSpec;
if (options.sqlServer) {
serverSpec = {
Name: serverRefName,
Type: "Microsoft.WindowsAzure.SQLAzure.Server",
URI: (((subscription.sqlManagementEndpointUrl + subscription.id) + "/services/sqlservers/servers/") + options.sqlServer) }; }
else {
serverSpec = {
ProvisioningParameters: {
AdministratorLogin: options.username,
AdministratorLoginPassword: options.password,
Location: options.sqlLocation },
ProvisioningConfigParameters: {
FirewallRules: [{
Name: "AllowAllWindowsAzureIps",
StartIPAddress: "0.0.0.0",
EndIPAddress: "0.0.0.0" },] },
Version: "1.0",
Name: serverRefName,
Type: "Microsoft.WindowsAzure.SQLAzure.Server" }; } ;
var dbRefName = ("ZumoSqlDatabase_" + uuid.v4().replace(/-/g, ""));
var dbSpec;
if (options.sqlDb) {
dbSpec = {
Name: dbRefName,
Type: "Microsoft.WindowsAzure.SQLAzure.DataBase",
URI: (((((subscription.sqlManagementEndpointUrl + subscription.id) + "/services/sqlservers/servers/") + options.sqlServer) + "/databases/") + options.sqlDb) }; }
else {
dbSpec = {
ProvisioningParameters: {
Name: (options.servicename + "_db"),
Edition: "WEB",
MaxSizeInGB: "1",
DBServer: {
ResourceReference: (serverRefName + ".Name") },
CollationName: "SQL_Latin1_General_CP1_CI_AS" },
Version: "1.0",
Name: dbRefName,
Type: "Microsoft.WindowsAzure.SQLAzure.DataBase" }; } ;
var spec = {
SchemaVersion: "2012-05.1.0",
Location: "West US",
ExternalResources: { },
InternalResources: {
ZumoMobileService: {
ProvisioningParameters: {
Name: options.servicename,
Location: options.location,
Platform: options.backend,
ProvisioningVersion: "2014-1-1",
EnableExternalPush: options.enhancedPush },
ProvisioningConfigParameters: {
Server: {
StringConcat: [{
ResourceReference: (serverRefName + ".Name")
},subscription.sqlServerHostnameSuffix,] },
Database: {
ResourceReference: (dbRefName + ".Name") },
AdministratorLogin: options.username,
AdministratorLoginPassword: options.password },
Version: "2012-05-21.1.0",
Name: "ZumoMobileService",
Type: "Microsoft.WindowsAzure.MobileServices.MobileService" } } };
if (options.sqlServer) {
spec.ExternalResources[serverRefName] = serverSpec; }
else {
spec.InternalResources[serverRefName] = serverSpec; } ;
if (options.sqlDb) {
spec.ExternalResources[dbRefName] = dbSpec; }
else {
spec.InternalResources[dbRefName] = dbSpec; } ;
log.silly($("New mobile service application specification:"));
log.silly(JSON.stringify(spec, null, 2));
var encodedSpec = new Buffer(JSON.stringify(spec)).toString("base64");
var payload = createMobileServiceApplicationTemplate.replace("##name##", (options.servicename + "mobileservice")).replace("##label##", options.servicename).replace("##description##", options.servicename).replace("##spec##", encodedSpec);
log.silly($("New mobile service request body:"));
log.silly(payload);
var progress = cli.interaction.progress($("Creating mobile service"));
try {
channel.post(payload, function(error, body, res) {
if (error) {
progress.end();
return callback(error); } ;
log.silly(util.format($("Create mobile app HTTP response: %s"), res.statusCode));
log.silly(JSON.stringify(res.headers, null, 2));
mobile.trackAsyncOperation(options, res.headers["x-ms-request-id"], function(error) {
if (error) {
progress.end();
return callback(error); } ;
var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice"));
channel.get(function(error, body) {
progress.end();
if (error) {
return callback(error); } ;
if (log.format().json) {
log.json(body); }
else {
log.silly(JSON.stringify(body, null, 2));
var flat = mobile.getFlatApplicationDescription(body);
var logger = ((flat.State == "Healthy") ? log.info : log.error);
log.silly(JSON.stringify(flat, null, 2));
logger(util.format($("Overall application state: %s"), flat.State));
flat.Resources.forEach(function(resource) {
logger((((resource.TypeView + ((resource.NameView ? ((" (" + resource.NameView) + ")") : ""))) + " state: ") + resource.State));
if (resource.Error) {
logger(resource.Error); } ; }); } ;
callback(((body.State === "Healthy") ? null : new Error($("Creation of a mobile service failed")))); }); }); });
} catch (e) {
progress.end();
throw e; }; };
mobile.command("locations").description($("List available mobile service locations")).option("-s, --subscription <id>", $("the subscription id")).execute(function __4(options, _) { var progress, result; var __frame = { name: "__4", line: 1583 }; return __func(_, this, arguments, __4, 1, __frame, function __$__4() {
progress = cli.interaction.progress($("Getting mobile service locations")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {
return mobile.getRegions(options, __cb(_, __frame, 4, 28, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__4() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__4() {
cli.interaction.formatOutput(result, function(locations) {
locations.forEach(function(region, index) {
log.info((region.region + (((index === 0) ? " (default)" : "")))); }); }); _(); }); }); }); });
mobile.command("create [servicename] [username] [password]").usage("[options] [servicename] [sqlAdminUsername] [sqlAdminPassword]").description($("Create a new mobile service")).option("-r, --sqlServer <sqlServer>", $("use existing SQL server")).option("-d, --sqlDb <sqlDb>", $("use existing SQL database")).option("-l, --location <location>", $("create the service in a particular location; run azure mobile locations to get available locations")).option("--sqlLocation <location>", $("create the SQL server in a particular location; defaults to mobile service location")).option("-s, --subscription <id>", $("the subscription id")).option("-b, --backend <backend>", $("backend of mobile service. \"node\" and \"dotnet\" are examples.")).option("-p, --push <push>", $("type of push; \"nh\" or \"legacy\" are allowed. \"nh\" will soon be the default for node service. ignored for dotnet services.")).execute(function __5(servicename, username, password, options, _) { var result;
function isPasswordValid(username, password) {
var matches = 0;
[new RegExp("[A-Z]"),new RegExp("[a-z]"),new RegExp("[0-9]"),new RegExp("[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\[\\}\\]\\|\\\\:\\;\\\"\\'\\<\\,\\>\\.\\?\\/]"),].forEach(function(regex) {
if (password.match(regex)) {
matches++; }; });
if ((((password.length >= 8) && (password.indexOf(username) == -1)) && (matches > 2))) {
return true; }
else {
log.warn($("Password must:"));
log.warn($("- be 8 or m