azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
260 lines (121 loc) • 11.6 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; var __ = require("underscore");
var fs = require("fs");
var path = require("path");
var util = require("util");
var profile = require("../../util/profile");
var utils = require("../../util/utils");
var WebsitesClient = require("./websites/websitesclient");
var $ = utils.getLocaleString;
exports.init = function(cli) {
var log = cli.output;
var site = cli.category("site");
var diagnostic = site.category("log").description($("Commands to manage your Web Site diagnostics"));
diagnostic.command("download [name]").description($("Download diagnostic log")).option("-o, --output <path>", $("the output path, default is local folder")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __1(name, options, _) { var parsedSiteName, context, repositoryUri; var __frame = { name: "__1", line: 42 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {
parsedSiteName = WebsitesClient.parseSiteName(name);
context = {
subscription: profile.current.getSubscription(options.subscription).id,
path: "",
site: {
name: parsedSiteName.name,
slot: (options.slot ? options.slot : parsedSiteName.slot) } };
if ((options.output && __.isString(options.output))) {
context.path = options.output; } ;
if (!(/[.]zip$/i.test(context.path))) {
context.path = path.join(context.path, "diagnostics.zip"); } ; return (function __$__1(__then) {
if (utils.pathExistsSync(context.path)) {
return util.format($("Replace existing %s ? [y/n] ", context.path), __cb(_, __frame, 20, 42, function ___(__0, __2) { var __1 = !cli.interaction.confirm(__2); return (function __$__1(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$__1() {
return site.ensureRepositoryUri(context, __cb(_, __frame, 25, 31, function ___(__0, __3) { repositoryUri = __3; return (function __$__1(__then) {
if (repositoryUri) {
return doDownloadDiagnostic(context, __cb(_, __frame, 27, 8, __then, true)); } else {
log.error($("Repository is not setup")); __then(); } ; })(_); }, true)); }); }); });
diagnostic.command("tail [name]").description($("Live diagnostic log")).option("-p, --path <path>", $("the log path under LogFiles folder")).option("-f, --filter <filter>", $("the filter matching line")).option("--log", $("indicates to write output as log data")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __2(name, options, _) { var parsedSiteName, context, repositoryUri, buf; var __frame = { name: "__2", line: 82 }; return __func(_, this, arguments, __2, 2, __frame, function __$__2() {
parsedSiteName = WebsitesClient.parseSiteName(name);
context = {
subscription: profile.current.getSubscription(options.subscription).id,
path: (options.path || ""),
filter: (options.filter || ""),
site: {
name: parsedSiteName.name,
slot: (options.slot ? options.slot : parsedSiteName.slot) } };
return site.ensureRepositoryUri(context, __cb(_, __frame, 12, 31, function ___(__0, __1) { repositoryUri = __1; return (function __$__2(__then) {
if (repositoryUri) {
return doLogStream(context, __cb(_, __frame, 14, 18, function ___(__0, __2) { buf = __2;
log.info(buf); __then(); }, true), function(err, line) { if (options.log) { log.data(line); } else { process.stdout.write(line); } ; }); } else {
log.error($("Repository is not setup")); __then(); } ; })(_); }, true)); }); });
diagnostic.command("set [name]").description($("Configure diagnostics")).option("-a, --application", $("use this flag to enable application diagnostics.")).option("-A, --disable-application", $("use this flag to disable application diagnostics.")).option("-w, --web-server-logging", $("use this flag to enable web server logging.")).option("-W, --disable-web-server-logging", $("use this flag to disable web server logging.")).option("-e, --detailed-error-messages", $("use this flag to enable detailed error messages.")).option("-E, --disable-detailed-error-messages", $("use this flag to disable detailed error messages.")).option("-f, --failed-request-tracing", $("use this flag to enable failed request tracing.")).option("-F, --disable-failed-request-tracing", $("use this flag to disable failed request tracing.")).option("-o, --out <out>", $("takes file or storage. When -a is specified, use this parameter to specify the output of the log.")).option("-l, --level <level>", $("takes error, warning, verbose or info. When -a is specified, use this parameter to specify the log level. But default is error.")).option("-t, --storage-account <storage-account>", $("use this parameter to specify the storage account where the log will be stored.")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __3(name, options, _) { var subscriptionId, websitesClient, parsedSiteName, context, config; var __frame = { name: "__3", line: 124 }; return __func(_, this, arguments, __3, 2, __frame, function __$__3() {
if (!((((((((options.webServerLogging || options.disableWebServerLogging) || options.detailedErrorMessages) || options.disableDetailedErrorMessages) || options.failedRequestTracing) || options.disableFailedRequestTracing) || options.application) || options.disableApplication))) {
return _(new Error($("Command needs to perform at least one diagnostic change"))); } ; return (function __$__3(__then) {
if ((options.application || options.disableApplication)) { return (function __$__3(__then) {
if (options.application) {
return cli.interaction.chooseIfNotGiven($("Output: "), "Getting output options", options.out, function(cb) {
return cb(null, ["file","storage",]); }, __cb(_, __frame, 14, 40, function ___(__0, __1) { options.out = __1; return (function __$__3(__then) {
if ((options.out === "storage")) {
return cli.interaction.chooseIfNotGiven($("Storage account: "), $("Getting storage accounts"), options.storageAccount, function(cb) {
var storageService = utils.createStorageClient(profile.current.getSubscription(options.subscription));
storageService.storageAccounts.list(function(err, accounts) {
if (err) { return cb(err); } ;
cb(null, accounts.storageServices.map(function(a) {
return a.serviceName; })); }); }, __cb(_, __frame, 20, 53, function ___(__0, __2) { options.storageAccount = __2; __then(); }, true)); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$__3() {
if (options.level) {
options.level = options.level.toLowerCase();
if ((options.level === "error")) {
options.level = "Error"; } else {
if ((options.level === "warning")) {
options.level = "Warning"; } else {
if ((options.level === "verbose")) {
options.level = "Verbose"; } else {
if ((options.level === "info")) {
options.level = "Information"; }
else {
return _(new Error($("Invalid error level"))); } ; } ; } ; } ; }
else {
options.level = "Error"; } ;
subscriptionId = profile.current.getSubscription(options.subscription).id;
websitesClient = new WebsitesClient(cli, subscriptionId); return (function __$__3(__then) {
if ((options.application === true)) {
return websitesClient.enableApplicationDiagnostic(name, options.out, { level: options.level, storageAccount: options.storageAccount }, __cb(_, __frame, 54, 25, __then, true)); } else { return (function __$__3(__then) {
if ((options.disableApplication === true)) {
return websitesClient.disableApplicationDiagnostic(name, options.out, { level: options.level, storageAccount: options.storageAccount }, __cb(_, __frame, 56, 25, __then, true)); } else { __then(); } ; })(__then); } ; })(__then); }); } else { __then(); } ; })(function __$__3() { return (function __$__3(__then) {
if ((((((options.webServerLogging || options.disableWebServerLogging) || options.detailedErrorMessages) || options.disableDetailedErrorMessages) || options.failedRequestTracing) || options.disableFailedRequestTracing)) {
parsedSiteName = WebsitesClient.parseSiteName(name);
context = {
subscription: profile.current.getSubscription(options.subscription).id,
site: {
name: parsedSiteName.name,
slot: (options.slot ? options.slot : parsedSiteName.slot) } };
return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 76, 13, function __$__3() {
config = { };
if ((options.webServerLogging || options.disableWebServerLogging)) {
config.httpLoggingEnabled = ((options.webServerLogging === true)).toString(); } ;
if ((options.detailedErrorMessages || options.disableDetailedErrorMessages)) {
config.detailedErrorLoggingEnabled = ((options.detailedErrorMessages === true)).toString(); } ;
if ((options.failedRequestTracing || options.disableFailedRequestTracing)) {
config.requestTracingEnabled = ((options.failedRequestTracing === true)).toString(); } ;
return site.doSiteConfigPUT(config, context, __cb(_, __frame, 91, 13, __then, true)); }, true)); } else { __then(); } ; })(_); }); }); });
function doDownloadDiagnostic(context, done) {
var service = utils.createScmManagementService(context.repositoryUri, context.repositoryAuth, log);
var progress = cli.interaction.progress(util.format($("Downloading diagnostic log to %s"), context.path));
var logStream = fs.createWriteStream(context.path);
var isDone = false;
service.getDumpToStream(logStream, function(err) {
if (err) {
progress.end();
if (!isDone) {
isDone = true;
done(err); } ; } ; });
logStream.on("error", function(err) {
if (!isDone) {
progress.end();
isDone = true;
done(err); } ; });
logStream.on("close", function() {
if (!isDone) {
progress.end();
isDone = true;
done(); } ; }); };
function doLogStream(context, _, chunkcb) { var service, options; var __frame = { name: "doLogStream", line: 251 }; return __func(_, this, arguments, doLogStream, 1, __frame, function __$doLogStream() {
service = utils.createScmManagementService(context.repositoryUri, context.repositoryAuth, log);
options = { };
if (context.filter) {
options["filter"] = context.filter; } ;
return service.getLogStream(context.path, { filter: context.filter }, chunkcb, __cb(_, __frame, 8, 19, _, true)); }); };};