UNPKG

@azure/arm-resources

Version:
418 lines 16.1 kB
/* * 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. */ import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib"; import { setContinuationToken } from "../pagingHelper.js"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers.js"; import * as Parameters from "../models/parameters.js"; import { createHttpPoller, } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl.js"; /// <reference lib="esnext.asynciterable" /> /** Class containing ResourceGroups operations. */ export 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 __asyncGenerator(this, arguments, function* listPagingPage_1() { let result; let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken; if (!continuationToken) { result = yield __await(this._list(options)); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield yield __await(page); } while (continuationToken) { result = yield __await(this._listNext(continuationToken, options)); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield yield __await(page); } }); } listPagingAll(options) { return __asyncGenerator(this, arguments, function* listPagingAll_1() { var _a, e_1, _b, _c; try { for (var _d = true, _e = __asyncValues(this.listPagingPage(options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const page = _c; yield __await(yield* __asyncDelegator(__asyncValues(page))); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield __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 = createLroSpec({ sendOperationFn, args: { resourceGroupName, options }, spec: deleteOperationSpec, }); const poller = await 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 = createLroSpec({ sendOperationFn, args: { resourceGroupName, parameters, options }, spec: exportTemplateOperationSpec, }); const poller = await 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); } } // 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