UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

231 lines (95 loc) 13.2 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var util = require("util"); var profile = require("../../../util/profile"); var utils = require("../../../util/utils"); var $ = utils.getLocaleString; exports.init = function(cli) { var log = cli.output; var withProgress = cli.interaction.withProgress.bind(cli.interaction); var policy = cli.category("policy").description($("Commands to manage your policies on ARM Resources.")); var definition = policy.category("assignment").description($("Commands to manage your policy assignments.")); definition.command("create [name] [policyDefinitionId] [scope]").description($("Creates a new policy assignment")).usage("[options] <name> <policyDefinitionId> <scope>").option("-n --name <name>", $("the policy assignment name")).option("-p --policy-definition-id <policyDefinitionId>", $("the fully qualified id of existing policy definition. For example: /subscriptions/{mySubId}/providers/Microsoft.Authorization/policyDefinitions/{myPolicy}. Use policy definition list to get a list of existing policy definitions. More information here: https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/")).option("-s --scope <scope>", $("the scope for policy assignment. For example, /subscriptions/{mySubId}/resourceGroups/{myGroup}")).option("-d --display-name <display-name>", $("the display name for policy assignment.")).option("--subscription <subscription>", $("the subscription identifier")).execute(function __1(name, policyDefinitionId, scope, options, _) { var subscription, client, policyAssignmentParameters, policyAssignment; var __frame = { name: "__1", line: 42 }; return __func(_, this, arguments, __1, 4, __frame, function __$__1() { if (!name) { return _(null, cli.missingArgument("name")); } ; if (!policyDefinitionId) { return _(null, cli.missingArgument("policyDefinitionId")); } ; if (!scope) { return _(null, cli.missingArgument("scope")); } ; subscription = profile.current.getSubscription(options.subscription); client = utils.createPolicyClient(subscription); policyAssignmentParameters = { policyDefinitionId: policyDefinitionId, scope: scope }; if (options.displayName) { policyAssignmentParameters.displayName = options.displayName; } ; policyAssignment = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return withProgress(util.format($("Creating policy assignment %s"), name), function __1(log, _) { var __frame = { name: "__1", line: 68 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return client.policyAssignments.create(scope, name, policyAssignmentParameters, __cb(_, __frame, 1, 42, _, true)); }); }, __cb(_, __frame, 25, 27, function ___(__0, __2) { policyAssignment = __2; __then(); }, true)); }); })(function ___(ex, __result) { __catch(function __$__1() { if (ex) { return _(new Error(util.format($("Policy assignment creation failed: %s"), ex))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__1() { cli.interaction.formatOutput(policyAssignment, function(data) { if (data) { displayAPolicyAssignment(data, log); } ; }); _(); }); }); }); }); definition.command("set [name] [scope]").description($("Updates a policy assignment")).usage("[options] <name> <scope>").option("-n --name <name>", $("the policy assignment name")).option("-p --policy-definition-id <policyDefinitionId>", $("the fully qualified id of existing policy definition. For example: /subscriptions/{mySubId}/providers/Microsoft.Authorization/policyDefinitions/{myPolicy}. Use policy definition list to get a list of existing policy definitions. More information here: https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/")).option("-s --scope <scope>", $("the scope for policy assignment. For example, /subscriptions/{mySubId}/resourceGroups/{myGroup}")).option("-d --display-name <display-name>", $("the display name for policy assignment.")).option("--subscription <subscription>", $("the subscription identifier")).execute(function __2(name, scope, options, _) { var subscription, client, policyAssignment, policyAssignmentParameters, policyAssignmentUpdated; var __frame = { name: "__2", line: 90 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() { if (!name) { return _(null, cli.missingArgument("name")); } ; if (!scope) { return _(null, cli.missingArgument("scope")); } ; subscription = profile.current.getSubscription(options.subscription); client = utils.createPolicyClient(subscription); policyAssignment = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return withProgress(util.format($("Getting existing policy assignment %s"), name), function __1(log, _) { var __frame = { name: "__1", line: 104 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return client.policyAssignments.get(scope, name, null, __cb(_, __frame, 1, 42, _, true)); }); }, __cb(_, __frame, 13, 27, function ___(__0, __3) { policyAssignment = __3; __then(); }, true)); }); })(function ___(ex, __result) { __catch(function __$__2() { if (ex) { return _(new Error(util.format($("Policy assignment get failed: %s"), ex))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__2() { policyAssignmentParameters = { policyDefinitionId: (options.policyDefinitionId ? options.policyDefinitionId : policyAssignment.policyDefinitionId), scope: scope, displayName: (options.displayName ? options.displayName : policyAssignment.displayName) }; policyAssignmentUpdated = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return withProgress(util.format($("Updating policy assignment %s"), name), function __2(log, _) { var __frame = { name: "__2", line: 120 }; return __func(_, this, arguments, __2, 1, __frame, function __$__2() { return client.policyAssignments.create(scope, name, policyAssignmentParameters, __cb(_, __frame, 1, 42, _, true)); }); }, __cb(_, __frame, 29, 34, function ___(__0, __4) { policyAssignmentUpdated = __4; __then(); }, true)); }); })(function ___(ex, __result) { __catch(function __$__2() { if (ex) { return _(new Error(util.format($("Policy assignment update failed: %s"), ex))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__2() { cli.interaction.formatOutput(policyAssignmentUpdated, function(data) { if (data) { displayAPolicyAssignment(data, log); } ; }); _(); }); }); }); }); }); }); definition.command("list").description($("Lists all the policy assignments in the subscription.")).option("--subscription <subscription>", $("the subscription identifier")).execute(function __3(options, _) { var subscription, client, policyAssignments; var __frame = { name: "__3", line: 137 }; return __func(_, this, arguments, __3, 1, __frame, function __$__3() { subscription = profile.current.getSubscription(options.subscription); client = utils.createPolicyClient(subscription); policyAssignments = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return withProgress($("Listing all policy assignments"), function __1(log, _) { var __frame = { name: "__1", line: 144 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return client.policyAssignments.list(null, __cb(_, __frame, 1, 42, _, true)); }); }, __cb(_, __frame, 6, 28, function ___(__0, __2) { policyAssignments = __2; __then(); }, true)); }); })(function ___(ex, __result) { __catch(function __$__3() { if (ex) { return _(new Error(util.format($("Policy assignment list failed: %s"), ex))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__3() { cli.interaction.formatOutput(policyAssignments, function(data) { if (data) { for (var i = 0; (i < data.length); i++) { displayAPolicyAssignment(data[i], log); log.data(""); }; } ; }); _(); }); }); }); }); definition.command("show [name] [scope]").description($("Shows a policy assignment")).usage("[options] <name> <scope>").option("-n --name <name>", $("the policy assignment name")).option("-s --scope <scope>", $("the scope for policy assignment. For example, /subscriptions/{mySubId}/resourceGroups/{myGroup}")).option("--subscription <subscription>", $("the subscription identifier")).execute(function __4(name, scope, options, _) { var subscription, client, policyAssignment; var __frame = { name: "__4", line: 167 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() { if (!name) { return _(null, cli.missingArgument("name")); } ; if (!scope) { return _(null, cli.missingArgument("scope")); } ; subscription = profile.current.getSubscription(options.subscription); client = utils.createPolicyClient(subscription); policyAssignment = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return withProgress(util.format($("Getting policy assignment %s"), name), function __1(log, _) { var __frame = { name: "__1", line: 181 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return client.policyAssignments.get(scope, name, null, __cb(_, __frame, 1, 42, _, true)); }); }, __cb(_, __frame, 13, 27, function ___(__0, __2) { policyAssignment = __2; __then(); }, true)); }); })(function ___(ex, __result) { __catch(function __$__4() { if (ex) { return _(new Error(util.format($("Policy assignment get failed: %s"), ex))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__4() { cli.interaction.formatOutput(policyAssignment, function(data) { if (data) { displayAPolicyAssignment(data, log); } ; }); _(); }); }); }); }); definition.command("delete [name] [scope]").description($("Deletes a policy assignment")).usage("[options] <name> <scope>").option("-n --name <name>", $("the policy definition name")).option("-s --scope <scope>", $("the scope for policy assignment. For example, /subscriptions/{mySubId}/resourceGroups/{myGroup}")).option("-q, --quiet", $("quiet mode (do not ask for delete confirmation)")).option("--subscription <subscription>", $("the subscription identifier")).execute(function __5(name, scope, options, _) { var subscription, client, progress; var __frame = { name: "__5", line: 202 }; return __func(_, this, arguments, __5, 3, __frame, function __$__5() { if (!name) { return _(null, cli.missingArgument("name")); } ; if (!scope) { return _(null, cli.missingArgument("scope")); } ; return (function __$__5(_) { var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete policy assignment %s? [y/n] "), name), __cb(_, __frame, 8, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -201, 17, function ___(__0, __2) { return (function __$__5(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__5() { subscription = profile.current.getSubscription(options.subscription); client = utils.createPolicyClient(subscription); progress = cli.interaction.progress(util.format($("Deleting policy definition %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return client.policyAssignments.deleteMethod(scope, name, __cb(_, __frame, 17, 33, function __$__5() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__5() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__5() { _(); }); }); }); }, true)); }); }); function displayAPolicyAssignment(policyAssignment, log) { log.data($("PolicyAssignmentName: "), policyAssignment.name); log.data($("Type: "), policyAssignment.type); log.data($("DisplayName: "), policyAssignment.displayName); log.data($("PolicyDefinitionId: "), policyAssignment.policyDefinitionId); log.data($("Scope: "), policyAssignment.scope); };};