azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
829 lines (490 loc) • 55.9 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 __ = require("underscore");
var constants = require("./constants");
var fs = require("fs");
var util = require("util");
var utils = require("../../../util/utils");
var validation = require("../../../util/validation");
var $ = utils.getLocaleString;
var recordSetUtils = require("./recordSetUtils");
var tagUtils = require("../tag/tagUtils");
var ZoneFile = require("./zoneFile");
function DnsZone(cli, dnsManagementClient) {
this.dnsManagementClient = dnsManagementClient;
this.zoneFile = new ZoneFile(cli.output);
this.output = cli.output;
this.interaction = cli.interaction;};
__.extend(DnsZone.prototype, {
create: function create__1(resourceGroupName, zoneName, options, _) { var self, parameters, progress, __this = this; var __frame = { name: "create__1", line: 39 }; return __func(_, this, arguments, create__1, 3, __frame, function __$create__1() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, ".");
parameters = {
zone: {
properties: { },
location: constants.dnsZone.defLocation },
ifNoneMatch: "*" };
if (options.tags) {
tagUtils.appendTags(parameters.zone, options); } ;
progress = self.interaction.progress(util.format($("Creating dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$create__1() {
return self.dnsManagementClient.zones.createOrUpdate(resourceGroupName, zoneName, parameters, __cb(_, __frame, 18, 37, function __$create__1() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$create__1() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$create__1() {
return self.show(resourceGroupName, zoneName, options, __cb(_, __frame, 22, 9, function __$create__1() { _(); }, true)); }); }); }); },
list: function list__2(resourceGroupName, params, _) { var self, progress, dnsZones, nextLink, nextZones, __this = this; var __frame = { name: "list__2", line: 64 }; return __func(_, this, arguments, list__2, 2, __frame, function __$list__2() { self = __this;
progress = self.interaction.progress($("Getting the dns zones"));
dnsZones = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$list__2() {
return self.dnsManagementClient.zones.list(resourceGroupName, __cb(_, __frame, 6, 48, function ___(__0, __1) { dnsZones = __1;
nextLink = dnsZones.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$list__2() { __more = false;
var __4 = (nextLink !== undefined); if (__4) {
self.output.silly("Following nextLink");
return self.dnsManagementClient.zones.listNext(nextLink, __cb(_, __frame, 10, 55, function ___(__0, __2) { nextZones = __2;
dnsZones.zones = dnsZones.zones.concat(nextZones.zones);
nextLink = nextZones.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$list__2() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$list__2() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$list__2() {
self.interaction.formatOutput(dnsZones.zones, function(outputData) {
if ((outputData.length === 0)) {
self.output.warn($("No dns zones found")); }
else {
self.output.table(outputData, function(row, zone) {
row.cell($("Name"), zone.name);
row.cell($("Resource group"), resourceGroupName); }); } ; }); _(); }); }); }); },
get: function get__3(resourceGroupName, zoneName, _) { var self, progress, dnsZone, __this = this; var __frame = { name: "get__3", line: 94 }; return __func(_, this, arguments, get__3, 2, __frame, function __$get__3() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, ".");
progress = self.interaction.progress(util.format($("Looking up the dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__3() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__3() {
return self.dnsManagementClient.zones.get(resourceGroupName, zoneName, __cb(_, __frame, 5, 51, function ___(__0, __1) { dnsZone = __1;
return _(null, dnsZone.zone); }, true)); }); })(function ___(e, __result) { __catch(function __$get__3() { if (e) {
if ((e.statusCode === 404)) {
return _(null, null); } ;
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$get__3() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$get__3() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$get__3() { _(); }); }); }); },
set: function set__4(resourceGroupName, zoneName, options, _) { var self, dnsZone, __this = this; var __frame = { name: "set__4", line: 111 }; return __func(_, this, arguments, set__4, 3, __frame, function __$set__4() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, ".");
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 3, 23, function ___(__0, __1) { dnsZone = __1;
if (!dnsZone) {
return _(new Error(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;
if (options.tags) {
if (utils.argHasValue(options.tags)) {
tagUtils.appendTags(dnsZone, options); }
else {
dnsZone.tags = { }; } ; } ;
return self.update(resourceGroupName, zoneName, dnsZone, __cb(_, __frame, 16, 9, function __$set__4() {
return self.show(resourceGroupName, zoneName, options, __cb(_, __frame, 17, 9, function __$set__4() { _(); }, true)); }, true)); }, true)); }); },
show: function show__5(resourceGroupName, zoneName, options, _) { var self, dnsZone, __this = this; var __frame = { name: "show__5", line: 131 }; return __func(_, this, arguments, show__5, 3, __frame, function __$show__5() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, ".");
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 23, function ___(__0, __1) { dnsZone = __1;
self.interaction.formatOutput(dnsZone, function(zone) {
if ((zone === null)) {
self.output.warn(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName)); }
else {
self.output.nameValue($("Id"), zone.id);
self.output.nameValue($("Name"), zone.name);
self.output.nameValue($("Type"), zone.type);
self.output.nameValue($("Location"), zone.location);
self.output.nameValue($("Number of record sets"), zone.properties.numberOfRecordSets);
self.output.nameValue($("Max number of record sets"), zone.properties.maxNumberOfRecordSets);
self.output.nameValue($("Tags"), tagUtils.getTagsInfo(zone.tags)); } ; }); _(); }, true)); }); },
delete: function delete__6(resourceGroupName, zoneName, options, _) { var self, parameters, progress, response, __this = this; var __frame = { name: "delete__6", line: 151 }; return __func(_, this, arguments, delete__6, 3, __frame, function __$delete__6() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, "."); return (function __$delete__6(_) {
var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete dns zone \"%s\"? [y/n] "), zoneName), __cb(_, __frame, 4, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -150, 17, function ___(__0, __2) { return (function __$delete__6(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$delete__6() {
parameters = {
ifMatch: "*" };
progress = self.interaction.progress(util.format($("Deleting dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$delete__6() {
return self.dnsManagementClient.zones.deleteMethod(resourceGroupName, zoneName, parameters, __cb(_, __frame, 15, 48, function ___(__0, __3) { response = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$delete__6() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$delete__6() {
if ((response.statusCode === 204)) {
return _(new Error(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ; _(); }); }); }); }, true)); }); },
update: function update__7(resourceGroupName, zoneName, dnsZone, _) { var self, progress, __this = this; var __frame = { name: "update__7", line: 176 }; return __func(_, this, arguments, update__7, 3, __frame, function __$update__7() { self = __this;
zoneName = utils.trimTrailingChar(zoneName, ".");
progress = self.interaction.progress(util.format($("Updating dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$update__7() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$update__7() {
return self.dnsManagementClient.zones.createOrUpdate(resourceGroupName, zoneName, { zone: dnsZone }, __cb(_, __frame, 5, 37, __then, true)); }); })(function ___(e, __result) { __catch(function __$update__7() { if (e) {
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$update__7() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$update__7() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$update__7() { _(); }); }); }); },
import: function import__8(resourceGroupName, zoneName, options, _) { var self, text, zfile, dnsZone, totalSetsCount, importedSetsCount, i, recordSet, __this = this; var __frame = { name: "import__8", line: 189 }; return __func(_, this, arguments, import__8, 3, __frame, function __$import__8() { self = __this;
zoneName = zoneName.toLowerCase();
if (options.debug) { console.time("Time elapsed"); } ;
text = fs.readFileSync(options.fileName, "utf8");
zfile = self.zoneFile.parse(zoneName, text);
if ((options.parseOnly && self.output.format().json)) {
self.output.json(zfile); } ;
if (options.parseOnly) { return _(null); } ;
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 14, 23, function ___(__0, __1) { dnsZone = __1; return (function __$import__8(__then) {
if (!dnsZone) {
return self.create(resourceGroupName, zoneName, options, __cb(_, __frame, 16, 11, __then, true)); } else { __then(); } ; })(function __$import__8() {
totalSetsCount = zfile.sets.length;
importedSetsCount = 0;
i = 0; var __6 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$import__8() { __more = false; if (__6) { i++; } else { __6 = true; } ; var __5 = (i < zfile.sets.length); if (__5) {
recordSet = zfile.sets[i];
return self.importRecordSet(resourceGroupName, zoneName, recordSet, options, __cb(_, __frame, 24, 32, function ___(__0, __2) { importedSetsCount += __2;
self.output.info(util.format($("%d record sets of %d imported"), importedSetsCount, totalSetsCount)); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$import__8() {
if (options.debug) { console.timeEnd("Time elapsed"); } ; _(); }); }); }, true)); }); },
export: function export__9(resourceGroupName, zoneName, options, _) { var self, dnsZone, recordSets, nextLink, nextRecordSets, fileData, progress, __this = this; var __frame = { name: "export__9", line: 220 }; return __func(_, this, arguments, export__9, 3, __frame, function __$export__9() { self = __this;
zoneName = zoneName.toLowerCase();
zoneName = utils.trimTrailingChar(zoneName, "."); return (function __$export__9(__then) {
if (fs.existsSync(options.fileName)) { return (function __$export__9(_) {
var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Overwrite file \"%s\"? [y/n] "), options.fileName), __cb(_, __frame, 6, 46, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -219, 17, function ___(__0, __2) { return (function __$export__9(__then) { if (__2) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$export__9() {
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 11, 23, function ___(__0, __3) { dnsZone = __3;
if (!dnsZone) {
return _(new Error(util.format($("DNS zone \"%s\" not found in resource group \"%s\""), zoneName, resourceGroupName))); } ;
return self.dnsManagementClient.recordSets.listAll(resourceGroupName, zoneName, options, __cb(_, __frame, 15, 57, function ___(__0, __4) { recordSets = __4;
nextLink = recordSets.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$export__9() { __more = false;
var __9 = (nextLink !== undefined); if (__9) {
self.output.silly("Following nextLink");
return self.dnsManagementClient.recordSets.listNext(nextLink, __cb(_, __frame, 20, 63, function ___(__0, __5) { nextRecordSets = __5;
recordSets.recordSets = recordSets.recordSets.concat(nextRecordSets.recordSets);
nextLink = nextRecordSets.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$export__9() {
fileData = self.zoneFile.generate(resourceGroupName, zoneName, recordSets);
progress = self.interaction.progress(util.format($("Exporting dns zone \"%s\" from resource group \"%s\""), zoneName, resourceGroupName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$export__9() {
fs.writeFileSync(options.fileName, fileData); _(null, null, true); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$export__9() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$export__9() { _(); }); }); }); }, true)); }, true)); }); }); },
importRecordSet: function importRecordSet__10(resourceGroupName, zoneName, recordSet, options, _) { var self, zoneSuffix, relativeName, parameters, progress, res, existingSet, __this = this; var __frame = { name: "importRecordSet__10", line: 258 }; return __func(_, this, arguments, importRecordSet__10, 4, __frame, function __$importRecordSet__10() { self = __this;
zoneSuffix = zoneName;
if (!utils.stringEndsWith(zoneName, ".", true)) { zoneSuffix += "."; } ;
if ((recordSet.name === zoneSuffix)) {
recordSet.name = "@"; }
else {
relativeName = recordSet.name.replace(("." + zoneSuffix), "");
recordSet.name = relativeName; } ;
zoneName = utils.trimTrailingChar(zoneName, ".");
parameters = recordSetUtils.covertToAzureFormat(recordSet);
if (options.force) {
parameters.ifNoneMatch = undefined; }
else {
parameters.ifNoneMatch = "*"; } ;
progress = self.interaction.progress(util.format($("Importing record set \"%s\" of type \"%s\""), recordSet.name, recordSet.type));
return self.tryImportRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet.type, parameters, __cb(_, __frame, 24, 19, function ___(__0, __1) { res = __1; return (function __$importRecordSet__10(__then) {
if ((res.statusCode === 412)) {
return self.getRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet.type, __cb(_, __frame, 26, 29, function ___(__0, __2) { existingSet = __2;
parameters = recordSetUtils.merge(parameters, existingSet, recordSet.type, options, self.output);
return self.tryImportRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet.type, parameters, __cb(_, __frame, 28, 11, __then, true)); }, true)); } else { __then(); } ; })(function __$importRecordSet__10() {
progress.end();
return _(null, 1); }); }, true)); }); },
tryImportRecordSet: function tryImportRecordSet__11(resourceGroupName, zoneName, setName, setType, parameters, _) { var self, res, __this = this; var __frame = { name: "tryImportRecordSet__11", line: 293 }; return __func(_, this, arguments, tryImportRecordSet__11, 5, __frame, function __$tryImportRecordSet__11() { self = __this;
res = { }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$tryImportRecordSet__11() {
return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, setType, parameters, __cb(_, __frame, 4, 42, function __$tryImportRecordSet__11() {
res.statusCode = 200; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$tryImportRecordSet__11() { if (e) {
res.statusCode = e.statusCode;
if ((e.statusCode !== 412)) {
self.output.warn(e.message); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$tryImportRecordSet__11() {
return _(null, res); }); }); }); },
createRecordSet: function createRecordSet__12(resourceGroupName, zoneName, setName, options, _) { var self, parameters, progress, recordSet, __this = this; var __frame = { name: "createRecordSet__12", line: 308 }; return __func(_, this, arguments, createRecordSet__12, 4, __frame, function __$createRecordSet__12() { self = __this;
parameters = { ifNoneMatch: "*" };
self._handleRecordSetOptions(parameters, options, true);
progress = self.interaction.progress(util.format($("Creating DNS record set \"%s\""), setName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createRecordSet__12() {
return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, options.type, parameters, __cb(_, __frame, 9, 54, function ___(__0, __1) { recordSet = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createRecordSet__12() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createRecordSet__12() {
self._showRecordSet(recordSet.recordSet); _(); }); }); }); },
setRecordSet: function setRecordSet__13(resourceGroupName, zoneName, setName, options, _) { var self, dnsZone, existingSet, __this = this; var __frame = { name: "setRecordSet__13", line: 324 }; return __func(_, this, arguments, setRecordSet__13, 4, __frame, function __$setRecordSet__13() { self = __this;
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 2, 23, function ___(__0, __1) { dnsZone = __1;
if (!dnsZone) {
return _(new Error(util.format($("A DNS zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;
options.type = self._validateType(options.type);
return self.getRecordSet(resourceGroupName, zoneName, setName, options.type, __cb(_, __frame, 9, 27, function ___(__0, __2) { existingSet = __2;
if (!existingSet) {
return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the resource group \"%s\""), setName, options.type, resourceGroupName))); } ;
self._handleRecordSetOptions(existingSet, options, false);
return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, existingSet, __cb(_, __frame, 16, 23, function ___(__0, __3) { existingSet = __3;
self._showRecordSet(existingSet.recordSet); _(); }, true)); }, true)); }, true)); }); },
deleteRecordSet: function deleteRecordSet__14(resourceGroupName, zoneName, setName, options, _) { var self, progress, result, __this = this; var __frame = { name: "deleteRecordSet__14", line: 344 }; return __func(_, this, arguments, deleteRecordSet__14, 4, __frame, function __$deleteRecordSet__14() { self = __this;
options.type = self._validateType(options.type); return (function __$deleteRecordSet__14(_) {
var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete DNS record set \"%s\"? [y/n] "), setName), __cb(_, __frame, 4, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -343, 17, function ___(__0, __2) { return (function __$deleteRecordSet__14(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$deleteRecordSet__14() {
progress = self.interaction.progress(util.format($("Deleting DNS record set \"%s\""), setName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteRecordSet__14() {
return self.dnsManagementClient.recordSets.deleteMethod(resourceGroupName, zoneName, setName, options.type, options, __cb(_, __frame, 11, 51, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteRecordSet__14() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteRecordSet__14() {
if ((result.code === 204)) {
return _(new Error(util.format($("DNS Record set \"%s\" of type \"%s\" not found in the resource group \"%s\""), setName, options.type, resourceGroupName))); } ; _(); }); }); }); }, true)); }); },
listRecordSets: function listRecordSets__15(resourceGroupName, zoneName, options, _) { var self, dnsRecords, progress, nextLink, nextRecordSets, __this = this; var __frame = { name: "listRecordSets__15", line: 365 }; return __func(_, this, arguments, listRecordSets__15, 3, __frame, function __$listRecordSets__15() { self = __this;
dnsRecords = null;
progress = self.interaction.progress($("Looking up the DNS Record Sets")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listRecordSets__15() { return (function __$listRecordSets__15(__then) {
if (options.type) {
options.type = self._validateType(options.type);
return self.dnsManagementClient.recordSets.list(resourceGroupName, zoneName, options.type, options, __cb(_, __frame, 8, 57, function ___(__0, __1) { dnsRecords = __1; __then(); }, true)); } else {
return self.dnsManagementClient.recordSets.listAll(resourceGroupName, zoneName, options, __cb(_, __frame, 10, 57, function ___(__0, __2) { dnsRecords = __2; __then(); }, true)); } ; })(function __$listRecordSets__15() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listRecordSets__15() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listRecordSets__15() {
nextLink = dnsRecords.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$listRecordSets__15() { __more = false;
var __6 = (nextLink !== undefined); if (__6) {
self.output.silly("Following nextLink");
return self.dnsManagementClient.recordSets.listNext(nextLink, __cb(_, __frame, 19, 63, function ___(__0, __3) { nextRecordSets = __3;
dnsRecords.recordSets = dnsRecords.recordSets.concat(nextRecordSets.recordSets);
nextLink = nextRecordSets.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$listRecordSets__15() {
self.interaction.formatOutput(dnsRecords.recordSets, function(outputData) {
if ((outputData.length === 0)) {
self.output.warn($("No DNS records sets found")); }
else {
var printable = recordSetUtils.convertToListFormat(outputData);
self.output.table(printable, function(row, recordSet) {
row.cell($("Name"), (recordSet.name || ""));
row.cell($("TTL"), (recordSet.ttl || ""));
row.cell($("Type"), (recordSet.type || ""));
row.cell($("Records"), recordSet.record);
row.cell($("Tags"), (tagUtils.getTagsInfo(recordSet.tags) || "")); }); } ; }); _(); }); }); }); }); },
getRecordSet: function getRecordSet__16(resourceGroupName, zoneName, setName, type, _) { var self, progress, recordSet, __this = this; var __frame = { name: "getRecordSet__16", line: 406 }; return __func(_, this, arguments, getRecordSet__16, 4, __frame, function __$getRecordSet__16() { self = __this;
type = self._validateType(type);
progress = self.interaction.progress(util.format($("Looking up the DNS Record Set \"%s\" of type \"%s\""), setName, type)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getRecordSet__16() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getRecordSet__16() {
return self.dnsManagementClient.recordSets.get(resourceGroupName, zoneName, setName, type, __cb(_, __frame, 5, 58, function ___(__0, __1) { recordSet = __1;
recordSetUtils.removeEmptyRecords(recordSet.recordSet);
return _(null, recordSet); }, true)); }); })(function ___(e, __result) { __catch(function __$getRecordSet__16() { if (e) {
if ((e.statusCode === 404)) {
return _(null, null); } ;
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getRecordSet__16() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getRecordSet__16() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getRecordSet__16() { _(); }); }); }); },
showRecordSet: function showRecordSet__17(resourceGroupName, zoneName, setName, options, _) { var self, recordSet, __this = this; var __frame = { name: "showRecordSet__17", line: 424 }; return __func(_, this, arguments, showRecordSet__17, 4, __frame, function __$showRecordSet__17() { self = __this;
options.type = self._validateType(options.type);
return self.getRecordSet(resourceGroupName, zoneName, setName, options.type, __cb(_, __frame, 4, 25, function ___(__0, __1) { recordSet = __1;
if ((recordSet === null)) { recordSet = { recordSet: null }; } ;
self.interaction.formatOutput(recordSet.recordSet, function(recordSet) {
if ((recordSet === null)) {
self.output.warn(util.format($("A DNS record with name \"%s\" not found in the resource group \"%s\""), setName, resourceGroupName)); }
else {
self._showRecordSet(recordSet); } ; }); _(); }, true)); }); },
addRecord: function addRecord__18(resourceGroupName, zoneName, setName, options, _) { var self, dnsZone, existingSet, __this = this; var __frame = { name: "addRecord__18", line: 439 }; return __func(_, this, arguments, addRecord__18, 4, __frame, function __$addRecord__18() { self = __this;
options.type = self._validateType(options.type);
return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 23, function ___(__0, __1) { dnsZone = __1;
if (!dnsZone) {
return _(new Error(util.format($("A DNS zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;
return self.getRecordSet(resourceGroupName, zoneName, setName, options.type, __cb(_, __frame, 9, 27, function ___(__0, __2) { existingSet = __2;
if (!existingSet) {
return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the DNS zone with name \"%s\""), setName, options.type, zoneName))); } ;
self._handleRecordSetOptions(existingSet, options, false);
self._handleRecordParameters(existingSet.recordSet, options, true);
return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, existingSet, __cb(_, __frame, 17, 23, function ___(__0, __3) { existingSet = __3;
self._showRecordSet(existingSet.recordSet); _(); }, true)); }, true)); }, true)); }); },
deleteRecord: function deleteRecord__19(resourceGroupName, zoneName, setName, options, _) { var self, existingSet, __this = this; var __frame = { name: "deleteRecord__19", line: 460 }; return __func(_, this, arguments, deleteRecord__19, 4, __frame, function __$deleteRecord__19() { self = __this;
options.type = self._validateType(options.type);
return self.getRecordSet(resourceGroupName, zoneName, setName, options.type, __cb(_, __frame, 4, 27, function ___(__0, __2) { existingSet = __2;
if (!existingSet) {
return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the resource group \"%s\""), setName, options.type, resourceGroupName))); } ;
self._handleRecordParameters(existingSet.recordSet, options, false); return (function __$deleteRecord__19(_) {
var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm($("Delete DNS Record? [y/n] "), __cb(_, __frame, 11, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -459, 17, function ___(__0, __3) { return (function __$deleteRecord__19(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteRecord__19() {
return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, existingSet, __cb(_, __frame, 15, 23, function ___(__0, __4) { existingSet = __4;
self._showRecordSet(existingSet.recordSet); _(); }, true)); }); }, true)); }, true)); }); },
updateRecordSet: function updateRecordSet__20(resourceGroupName, zoneName, setName, setType, parameters, _) { var self, progress, recordSet, __this = this; var __frame = { name: "updateRecordSet__20", line: 479 }; return __func(_, this, arguments, updateRecordSet__20, 5, __frame, function __$updateRecordSet__20() { self = __this;
progress = self.interaction.progress(util.format($("Updating record set \"%s\""), setName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateRecordSet__20() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateRecordSet__20() {
return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, setType, parameters, __cb(_, __frame, 4, 58, function ___(__0, __1) { recordSet = __1;
return _(null, recordSet); }, true)); }); })(function ___(e, __result) { __catch(function __$updateRecordSet__20() { if (e) {
if ((e.statusCode === 404)) {
return _(null, null); } ;
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$updateRecordSet__20() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$updateRecordSet__20() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$updateRecordSet__20() { _(); }); }); }); },
promptRecordParameters: function promptRecordParameters__21(type, options, _) { var self, lowerType, __this = this; var __frame = { name: "promptRecordParameters__21", line: 495 }; return __func(_, this, arguments, promptRecordParameters__21, 2, __frame, function __$promptRecordParameters__21() { self = __this;
lowerType = type.toLowerCase(); return (function __$promptRecordParameters__21(__break) {
switch (lowerType) {
case "a": return self.interaction.promptIfNotGiven($("IPv4 address for A record type: "), options.ipv4Address, __cb(_, __frame, 5, 47, function ___(__0, __1) {
options.ipv4Address = __1; return __break(); }, true));
case "aaaa": return self.interaction.promptIfNotGiven($("IPv6 address for AAAA record type: "), options.ipv6Address, __cb(_, __frame, 8, 47, function ___(__0, __2) {
options.ipv6Address = __2; return __break(); }, true));
case "cname": return self.interaction.promptIfNotGiven($("Canonical name for CNAME record type: "), options.cname, __cb(_, __frame, 11, 41, function ___(__0, __3) {
options.cname = __3; return __break(); }, true));
case "mx": return self.interaction.promptIfNotGiven($("Preference for MX record type: "), options.preference, __cb(_, __frame, 14, 46, function ___(__0, __4) {
options.preference = __4; return self.interaction.promptIfNotGiven($("Exchange for MX record type: "), options.exchange, __cb(_, __frame, 15, 44, function ___(__0, __5) {
options.exchange = __5; return __break(); }, true)); }, true));
case "ns": return self.interaction.promptIfNotGiven($("Domain name for NS record type: "), options.nsdname, __cb(_, __frame, 18, 43, function ___(__0, __6) {
options.nsdname = __6; return __break(); }, true));
case "srv": return self.interaction.promptIfNotGiven($("Priority for SRV record type: "), options.priority, __cb(_, __frame, 21, 44, function ___(__0, __7) {
options.priority = __7; return self.interaction.promptIfNotGiven($("Weight for SRV record type: "), options.weight, __cb(_, __frame, 22, 42, function ___(__0, __8) {
options.weight = __8; return self.interaction.promptIfNotGiven($("Port for SRV record type: "), options.port, __cb(_, __frame, 23, 40, function ___(__0, __9) {
options.port = __9; return self.interaction.promptIfNotGiven($("Target for SRV record type: "), options.target, __cb(_, __frame, 24, 42, function ___(__0, __10) {
options.target = __10; return __break(); }, true)); }, true)); }, true)); }, true));
case "soa": return self.interaction.promptIfNotGiven($("Email for SOA record type: "), options.email, __cb(_, __frame, 27, 41, function ___(__0, __11) {
options.email = __11; return self.interaction.promptIfNotGiven($("Expire time for SOA record type: "), options.expireTime, __cb(_, __frame, 28, 46, function ___(__0, __12) {
options.expireTime = __12; return self.interaction.promptIfNotGiven($("Serial number for SOA record type: "), options.serialNumber, __cb(_, __frame, 29, 48, function ___(__0, __13) {
options.serialNumber = __13; return self.interaction.promptIfNotGiven($("Host for SOA record type: "), options.host, __cb(_, __frame, 30, 40, function ___(__0, __14) {
options.host = __14; return self.interaction.promptIfNotGiven($("Minimum TTL for SOA record type: "), options.minimumTtl, __cb(_, __frame, 31, 46, function ___(__0, __15) {
options.minimumTtl = __15; return self.interaction.promptIfNotGiven($("Refresh time for SOA record type: "), options.refreshTime, __cb(_, __frame, 32, 47, function ___(__0, __16) {
options.refreshTime = __16; return self.interaction.promptIfNotGiven($("Retry time for SOA record type: "), options.retryTime, __cb(_, __frame, 33, 45, function ___(__0, __17) {
options.retryTime = __17; return __break(); }, true)); }, true)); }, true)); }, true)); }, true)); }, true)); }, true));
case "txt": return self.interaction.promptIfNotGiven($("Text for TXT record type: "), options.text, __cb(_, __frame, 36, 40, function ___(__0, __18) {
options.text = __18; return __break(); }, true));
case "ptr": return self.interaction.promptIfNotGiven($("Ptr domain name for PTR record type: "), options.ptrdName, __cb(_, __frame, 39, 44, function ___(__0, __19) {
options.ptrdName = __19; return __break(); }, true)); default:
return __break(); }; })(_); }); },
_handleRecordSetOptions: function(recordSet, options, useDefaults) {
var self = this;
options.type = self._validateType(options.type, useDefaults);
if (((recordSet.recordSet === null) || (recordSet.recordSet === undefined))) {
recordSet.recordSet = {
location: constants.dnsZone.defLocation,
properties: { } };
switch (options.type) {
case constants.dnsZone.A: recordSet.recordSet.properties.aRecords = [];
break;
case constants.dnsZone.AAAA:
recordSet.recordSet.properties.aaaaRecords = [];
break;
case constants.dnsZone.MX:
recordSet.recordSet.properties.mxRecords = [];
break;
case constants.dnsZone.NS:
recordSet.recordSet.properties.nsRecords = [];
break;
case constants.dnsZone.TXT:
recordSet.recordSet.properties.txtRecords = [];
break;
case constants.dnsZone.SRV:
recordSet.recordSet.properties.srvRecords = [];
break;
case constants.dnsZone.PTR:
recordSet.recordSet.properties.ptrRecords = [];
break;
}; } ;
if (!recordSet.recordSet.location) {
recordSet.recordSet.location = constants.dnsZone.defLocation;
self.output.warn(util.format($("using default record set location \"%s\""), constants.dnsZone.defLocation)); } ;
if (options.ttl) {
var ttlAsInt = utils.parseInt(options.ttl);
if ((isNaN(ttlAsInt) || ((ttlAsInt < 0)))) {
throw new Error($("--ttl value must be positive integer")); } ;
recordSet.recordSet.properties.ttl = ttlAsInt; }
else if (useDefaults) {
var defTtl = constants.dnsZone.defTtl;
self.output.warn(util.format($("using default TTL of %s seconds"), defTtl));
recordSet.recordSet.properties.ttl = defTtl; } ;
if (options.tags) {
if (utils.argHasValue(options.tags)) {
tagUtils.appendTags(recordSet.recordSet, options); }
else {
recordSet.recordSet.tags = { }; } ; } ; },
_validateType: function(type, useDefaults) {
var self = this;
if (type) {
validation.isIn(type, constants.dnsZone.recordTypes, "--type"); }
else if (useDefaults) {
type = constants.dnsZone.A;
self.output.info(util.format($("Using default type of \"%s\""), type)); } ;
return type; },
_handleRecordParameters: function(recordSet, options, isAddingRecord) {
var self = this;
if ((options.type.toUpperCase() !== constants.dnsZone.A)) {
if (options.ipv4Address) {
self.output.info(util.format($("--ipv4-address parameter will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.aRecords; }
else if (options.ipv4Address) {
if (isAddingRecord) {
recordSet.properties.aRecords.push({ ipv4Address: options.ipv4Address }); }
else {
var aRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.aRecords, { ipv4Address: options.ipv4Address });
if ((aRecordIndex === -1)) {
self.output.warn($("Record A not found in the record set with parameters specified.")); }
else {
recordSet.properties.aRecords.splice(aRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.AAAA)) {
if (options.ipv6Address) {
self.output.info(util.format($("--ipv6-address parameter will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.aaaaRecords; }
else if (options.ipv6Address) {
if (isAddingRecord) {
recordSet.properties.aaaaRecords.push({ ipv6Address: options.ipv6Address }); }
else {
var aaaaRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.aaaaRecords, { ipv6Address: options.ipv6Address });
if ((aaaaRecordIndex === -1)) {
self.output.warn($("Record AAAA not found in the record set with parameters specified.")); }
else {
recordSet.properties.aaaaRecords.splice(aaaaRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.CNAME)) {
if (options.cname) {
self.output.info(util.format($("--cname parameter will be ignored due to type of this DNS record - \"%s\""), options.type)); } ; }
else if (options.cname) {
if (isAddingRecord) {
options.cname = utils.trimTrailingChar(options.cname, ".");
recordSet.properties.cnameRecord = { cname: options.cname }; }
else {
var cnameRecord = (recordSet.properties.cnameRecord.cname === options.cname);
if (!cnameRecord) {
self.output.warn($("Record CNAME not found in the record set with parameters specified.")); }
else {
delete recordSet.properties.cnameRecord; } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.MX)) {
if ((options.preference || options.exchange)) {
self.output.info(util.format($("MX parameters will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.mxRecords; }
else if ((options.preference || options.exchange)) {
if (!((options.preference && options.exchange))) {
throw new Error($("--preference and --exchange parameters must be specified together")); } ;
if ((isNaN(options.preference) || (options.preference < 0))) {
throw new Error($("--preference parameter must be positive integer")); } ;
options.exchange = utils.trimTrailingChar(options.exchange, ".");
if (isAddingRecord) {
recordSet.properties.mxRecords.push({ preference: options.preference, exchange: options.exchange }); }
else {
var mxRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.mxRecords, {
preference: parseInt(options.preference),
exchange: options.exchange });
if ((mxRecordIndex === -1)) {
self.output.warn($("Record MX not found in the record set with parameters specified.")); }
else {
recordSet.properties.mxRecords.splice(mxRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.NS)) {
if (options.nsdname) {
self.output.info(util.format($("--nsdname parameter will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.nsRecords; }
else if (options.nsdname) {
if (isAddingRecord) {
recordSet.properties.nsRecords.push({ nsdname: options.nsdname }); }
else {
var nsRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.nsRecords, { nsdname: options.nsdname });
if ((nsRecordIndex === -1)) {
self.output.warn($("Record NS not found in the record set with parameters specified.")); }
else {
recordSet.properties.nsRecords.splice(nsRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.SRV)) {
if ((((options.priority || options.weight) || options.port) || options.target)) {
self.output.info(util.format($("SRV parameters will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.srvRecords; }
else if ((((options.priority || options.weight) || options.port) || options.target)) {
if (!((((options.priority && options.weight) && options.port) && options.target))) {
throw new Error($("You must specify all SRV parameters if even one is specified")); } ;
if ((isNaN(options.priority) || (options.priority < 0))) {
throw new Error($("--priority parameter must be positive integer")); } ;
if ((isNaN(options.weight) || (options.weight < 0))) {
throw new Error($("--weight parameter must be positive integer")); } ;
if ((isNaN(options.port) || (options.port < 0))) {
throw new Error($("--port parameter must be positive integer")); } ;
options.target = utils.trimTrailingChar(options.target, ".");
if (isAddingRecord) {
recordSet.properties.srvRecords.push({
priority: options.priority,
weight: options.weight,
port: options.port,
target: options.target }); }
else {
var srvRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.srvRecords, {
priority: parseInt(options.priority),
weight: parseInt(options.weight),
port: parseInt(options.port),
target: options.target });
if ((srvRecordIndex === -1)) {
self.output.warn($("Record SRV not found in the record set with parameters specified.")); }
else {
recordSet.properties.srvRecords.splice(srvRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.TXT)) {
if (options.text) {
self.output.info(util.format($("--text parameter will be ignored due to type of this DNS record - \"%s\""), options.type)); } ;
delete recordSet.properties.txtRecords; }
else if (options.text) {
if (isAddingRecord) {
recordSet.properties.txtRecords.push({ value: options.text }); }
else {
var txtRecordIndex = utils.indexOfCaseIgnore(recordSet.properties.txtRecords, { value: options.text });
if ((txtRecordIndex === -1)) {
self.output.warn($("Record TXT not found in the record set with parameters specified.")); }
else {
recordSet.properties.txtRecords.splice(txtRecordIndex, 1); } ; } ; } ;
if ((options.type.toUpperCase() !== constants.dnsZone.SOA)) {
if ((((((options.email || options.expireTime) || options.host) || options.minimumTtl) || options.refreshTime) || options.retryTime)) {
self.output.info(util.format($("SOA parameters will be ignored due to type of this DNS record - \"%s\""), options.type)); } ; }
else if ((((((options.email || options.expireTime) || options.host) || options.minimumTtl) || options.refreshTime) || options.retryTime)) {
if ((((((options.email && options.expireTime) && options.host) && options.minimumTtl) && options.refreshTime) && options.retryTime)) {
throw new Error($("You must specify all SOA parameters if even one is specified")); } ;
if ((isNaN(options.expireTime) || (options.expireTime < 0))) {
throw new Error($("--expire-time parameter must be positive integer")); } ;
if ((isNaN(options.refreshTime) || (options.refreshTime < 0))) {
throw new Error($("--refresh-time parameter must be positive integer")); } ;
if ((isNaN(options.retryTime) || (options.retryTime < 0))) {
throw new Error($("--retry-time parameter must be positive integer")); } ;
if ((isNaN(options.minimumTtl) || (options.minimumTtl < 255))) {
throw new Error($("--minimumTtl parameter must be in the range [0,255]")); } ;
if (isAddingRecord) {
recordSet.properties.soaRecord = {
email: options.email,
expireTime: options.expireTime,
host: options.host,
minimumTtl: options.minumumTtl,
refreshTime: options.refreshTime,
retryTime: options.retryTime }; }
else {