@azure/arm-resources
Version:
A generated SDK for ResourceManagementClient.
422 lines • 16.5 kB
JavaScript
;
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceGroupsImpl = void 0;
const tslib_1 = require("tslib");
const pagingHelper_js_1 = require("../pagingHelper.js");
const coreClient = tslib_1.__importStar(require("@azure/core-client"));
const Mappers = tslib_1.__importStar(require("../models/mappers.js"));
const Parameters = tslib_1.__importStar(require("../models/parameters.js"));
const core_lro_1 = require("@azure/core-lro");
const lroImpl_js_1 = require("../lroImpl.js");
/// <reference lib="esnext.asynciterable" />
/** Class containing ResourceGroups operations. */
class ResourceGroupsImpl {
/**
* Initialize a new instance of the class ResourceGroups class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Gets all the resource groups for a subscription.
* @param options The options parameters.
*/
list(options) {
const iter = this.listPagingAll(options);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage: (settings) => {
if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
throw new Error("maxPageSize is not supported by this operation.");
}
return this.listPagingPage(options, settings);
},
};
}
listPagingPage(options, settings) {
return tslib_1.__asyncGenerator(this, arguments, function* listPagingPage_1() {
let result;
let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken;
if (!continuationToken) {
result = yield tslib_1.__await(this._list(options));
let page = result.value || [];
continuationToken = result.nextLink;
(0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
yield yield tslib_1.__await(page);
}
while (continuationToken) {
result = yield tslib_1.__await(this._listNext(continuationToken, options));
continuationToken = result.nextLink;
let page = result.value || [];
(0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
yield yield tslib_1.__await(page);
}
});
}
listPagingAll(options) {
return tslib_1.__asyncGenerator(this, arguments, function* listPagingAll_1() {
var _a, e_1, _b, _c;
try {
for (var _d = true, _e = tslib_1.__asyncValues(this.listPagingPage(options)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const page = _c;
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
}
finally { if (e_1) throw e_1.error; }
}
});
}
/**
* Checks whether a resource group exists.
* @param resourceGroupName The name of the resource group to check. The name is case insensitive.
* @param options The options parameters.
*/
checkExistence(resourceGroupName, options) {
return this.client.sendOperationRequest({ resourceGroupName, options }, checkExistenceOperationSpec);
}
/**
* Creates or updates a resource group.
* @param resourceGroupName The name of the resource group to create or update. Can include
* alphanumeric, underscore, parentheses, hyphen, period (except at end), and Unicode characters that
* match the allowed characters.
* @param parameters Parameters supplied to the create or update a resource group.
* @param options The options parameters.
*/
createOrUpdate(resourceGroupName, parameters, options) {
return this.client.sendOperationRequest({ resourceGroupName, parameters, options }, createOrUpdateOperationSpec);
}
/**
* When you delete a resource group, all of its resources are also deleted. Deleting a resource group
* deletes all of its template deployments and currently stored operations.
* @param resourceGroupName The name of the resource group to delete. The name is case insensitive.
* @param options The options parameters.
*/
async beginDelete(resourceGroupName, options) {
const directSendOperation = async (args, spec) => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperationFn = async (args, spec) => {
var _a;
let currentRawResponse = undefined;
const providedCallback = (_a = args.options) === null || _a === void 0 ? void 0 : _a.onResponse;
const callback = (rawResponse, flatResponse) => {
currentRawResponse = rawResponse;
providedCallback === null || providedCallback === void 0 ? void 0 : providedCallback(rawResponse, flatResponse);
};
const updatedArgs = Object.assign(Object.assign({}, args), { options: Object.assign(Object.assign({}, args.options), { onResponse: callback }) });
const flatResponse = await directSendOperation(updatedArgs, spec);
return {
flatResponse,
rawResponse: {
statusCode: currentRawResponse.status,
body: currentRawResponse.parsedBody,
headers: currentRawResponse.headers.toJSON(),
},
};
};
const lro = (0, lroImpl_js_1.createLroSpec)({
sendOperationFn,
args: { resourceGroupName, options },
spec: deleteOperationSpec,
});
const poller = await (0, core_lro_1.createHttpPoller)(lro, {
restoreFrom: options === null || options === void 0 ? void 0 : options.resumeFrom,
intervalInMs: options === null || options === void 0 ? void 0 : options.updateIntervalInMs,
});
await poller.poll();
return poller;
}
/**
* When you delete a resource group, all of its resources are also deleted. Deleting a resource group
* deletes all of its template deployments and currently stored operations.
* @param resourceGroupName The name of the resource group to delete. The name is case insensitive.
* @param options The options parameters.
*/
async beginDeleteAndWait(resourceGroupName, options) {
const poller = await this.beginDelete(resourceGroupName, options);
return poller.pollUntilDone();
}
/**
* Gets a resource group.
* @param resourceGroupName The name of the resource group to get. The name is case insensitive.
* @param options The options parameters.
*/
get(resourceGroupName, options) {
return this.client.sendOperationRequest({ resourceGroupName, options }, getOperationSpec);
}
/**
* Resource groups can be updated through a simple PATCH operation to a group address. The format of
* the request is the same as that for creating a resource group. If a field is unspecified, the
* current value is retained.
* @param resourceGroupName The name of the resource group to update. The name is case insensitive.
* @param parameters Parameters supplied to update a resource group.
* @param options The options parameters.
*/
update(resourceGroupName, parameters, options) {
return this.client.sendOperationRequest({ resourceGroupName, parameters, options }, updateOperationSpec);
}
/**
* Captures the specified resource group as a template.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param parameters Parameters for exporting the template.
* @param options The options parameters.
*/
async beginExportTemplate(resourceGroupName, parameters, options) {
const directSendOperation = async (args, spec) => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperationFn = async (args, spec) => {
var _a;
let currentRawResponse = undefined;
const providedCallback = (_a = args.options) === null || _a === void 0 ? void 0 : _a.onResponse;
const callback = (rawResponse, flatResponse) => {
currentRawResponse = rawResponse;
providedCallback === null || providedCallback === void 0 ? void 0 : providedCallback(rawResponse, flatResponse);
};
const updatedArgs = Object.assign(Object.assign({}, args), { options: Object.assign(Object.assign({}, args.options), { onResponse: callback }) });
const flatResponse = await directSendOperation(updatedArgs, spec);
return {
flatResponse,
rawResponse: {
statusCode: currentRawResponse.status,
body: currentRawResponse.parsedBody,
headers: currentRawResponse.headers.toJSON(),
},
};
};
const lro = (0, lroImpl_js_1.createLroSpec)({
sendOperationFn,
args: { resourceGroupName, parameters, options },
spec: exportTemplateOperationSpec,
});
const poller = await (0, core_lro_1.createHttpPoller)(lro, {
restoreFrom: options === null || options === void 0 ? void 0 : options.resumeFrom,
intervalInMs: options === null || options === void 0 ? void 0 : options.updateIntervalInMs,
resourceLocationConfig: "location",
});
await poller.poll();
return poller;
}
/**
* Captures the specified resource group as a template.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param parameters Parameters for exporting the template.
* @param options The options parameters.
*/
async beginExportTemplateAndWait(resourceGroupName, parameters, options) {
const poller = await this.beginExportTemplate(resourceGroupName, parameters, options);
return poller.pollUntilDone();
}
/**
* Gets all the resource groups for a subscription.
* @param options The options parameters.
*/
_list(options) {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* ListNext
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
_listNext(nextLink, options) {
return this.client.sendOperationRequest({ nextLink, options }, listNextOperationSpec);
}
}
exports.ResourceGroupsImpl = ResourceGroupsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const checkExistenceOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}",
httpMethod: "HEAD",
responses: {
204: {},
404: {},
default: {
bodyMapper: Mappers.CloudError,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
],
headerParameters: [Parameters.accept],
serializer,
};
const createOrUpdateOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.ResourceGroup,
},
201: {
bodyMapper: Mappers.ResourceGroup,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
requestBody: Parameters.parameters6,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer,
};
const deleteOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}",
httpMethod: "DELETE",
responses: {
200: {},
201: {},
202: {},
204: {},
default: {
bodyMapper: Mappers.CloudError,
},
},
queryParameters: [Parameters.apiVersion, Parameters.forceDeletionTypes],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
],
headerParameters: [Parameters.accept],
serializer,
};
const getOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ResourceGroup,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
],
headerParameters: [Parameters.accept],
serializer,
};
const updateOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: Mappers.ResourceGroup,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
requestBody: Parameters.parameters7,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer,
};
const exportTemplateOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/exportTemplate",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.ResourceGroupExportResult,
},
201: {
bodyMapper: Mappers.ResourceGroupExportResult,
},
202: {
bodyMapper: Mappers.ResourceGroupExportResult,
},
204: {
bodyMapper: Mappers.ResourceGroupExportResult,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
requestBody: Parameters.parameters8,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName1,
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer,
};
const listOperationSpec = {
path: "/subscriptions/{subscriptionId}/resourcegroups",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ResourceGroupListResult,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
queryParameters: [Parameters.apiVersion, Parameters.filter, Parameters.top],
urlParameters: [Parameters.$host, Parameters.subscriptionId],
headerParameters: [Parameters.accept],
serializer,
};
const listNextOperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ResourceGroupListResult,
},
default: {
bodyMapper: Mappers.CloudError,
},
},
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.subscriptionId,
],
headerParameters: [Parameters.accept],
serializer,
};
//# sourceMappingURL=resourceGroups.js.map