/* * 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 { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { ArmTemplates } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevTestLabsClient } from "../devTestLabsClient"; import { ArmTemplate, ArmTemplatesListNextOptionalParams, ArmTemplatesListOptionalParams, ArmTemplatesListResponse, ArmTemplatesGetOptionalParams, ArmTemplatesGetResponse, ArmTemplatesListNextResponse } from "../models"; /// /** Class containing ArmTemplates operations. */ export class ArmTemplatesImpl implements ArmTemplates { private readonly client: DevTestLabsClient; /** * Initialize a new instance of the class ArmTemplates class. * @param client Reference to the service client */ constructor(client: DevTestLabsClient) { this.client = client; } /** * List azure resource manager templates in a given artifact source. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param artifactSourceName The name of the artifact source. * @param options The options parameters. */ public list( resourceGroupName: string, labName: string, artifactSourceName: string, options?: ArmTemplatesListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll( resourceGroupName, labName, artifactSourceName, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listPagingPage( resourceGroupName, labName, artifactSourceName, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, labName: string, artifactSourceName: string, options?: ArmTemplatesListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ArmTemplatesListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list( resourceGroupName, labName, artifactSourceName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, labName, artifactSourceName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, labName: string, artifactSourceName: string, options?: ArmTemplatesListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, labName, artifactSourceName, options )) { yield* page; } } /** * List azure resource manager templates in a given artifact source. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param artifactSourceName The name of the artifact source. * @param options The options parameters. */ private _list( resourceGroupName: string, labName: string, artifactSourceName: string, options?: ArmTemplatesListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, artifactSourceName, options }, listOperationSpec ); } /** * Get azure resource manager template. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param artifactSourceName The name of the artifact source. * @param name The name of the azure resource manager template. * @param options The options parameters. */ get( resourceGroupName: string, labName: string, artifactSourceName: string, name: string, options?: ArmTemplatesGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, artifactSourceName, name, options }, getOperationSpec ); } /** * ListNext * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param artifactSourceName The name of the artifact source. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, labName: string, artifactSourceName: string, nextLink: string, options?: ArmTemplatesListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, artifactSourceName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ArmTemplateList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName, Parameters.artifactSourceName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates/{name}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ArmTemplate }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion, Parameters.expand], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName, Parameters.artifactSourceName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ArmTemplateList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName, Parameters.artifactSourceName ], headerParameters: [Parameters.accept], serializer };