/* * 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 { SourceControlOperations } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { SecurityInsights } from "../securityInsights"; import { Repo, RepoType, SourceControlListRepositoriesNextOptionalParams, SourceControlListRepositoriesOptionalParams, SourceControlListRepositoriesResponse, SourceControlListRepositoriesNextResponse } from "../models"; /// /** Class containing SourceControlOperations operations. */ export class SourceControlOperationsImpl implements SourceControlOperations { private readonly client: SecurityInsights; /** * Initialize a new instance of the class SourceControlOperations class. * @param client Reference to the service client */ constructor(client: SecurityInsights) { this.client = client; } /** * Gets a list of repositories metadata. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param repoType The repo type. * @param options The options parameters. */ public listRepositories( resourceGroupName: string, workspaceName: string, repoType: RepoType, options?: SourceControlListRepositoriesOptionalParams ): PagedAsyncIterableIterator { const iter = this.listRepositoriesPagingAll( resourceGroupName, workspaceName, repoType, 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.listRepositoriesPagingPage( resourceGroupName, workspaceName, repoType, options, settings ); } }; } private async *listRepositoriesPagingPage( resourceGroupName: string, workspaceName: string, repoType: RepoType, options?: SourceControlListRepositoriesOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: SourceControlListRepositoriesResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listRepositories( resourceGroupName, workspaceName, repoType, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listRepositoriesNext( resourceGroupName, workspaceName, repoType, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listRepositoriesPagingAll( resourceGroupName: string, workspaceName: string, repoType: RepoType, options?: SourceControlListRepositoriesOptionalParams ): AsyncIterableIterator { for await (const page of this.listRepositoriesPagingPage( resourceGroupName, workspaceName, repoType, options )) { yield* page; } } /** * Gets a list of repositories metadata. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param repoType The repo type. * @param options The options parameters. */ private _listRepositories( resourceGroupName: string, workspaceName: string, repoType: RepoType, options?: SourceControlListRepositoriesOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, repoType, options }, listRepositoriesOperationSpec ); } /** * ListRepositoriesNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param repoType The repo type. * @param nextLink The nextLink from the previous successful call to the ListRepositories method. * @param options The options parameters. */ private _listRepositoriesNext( resourceGroupName: string, workspaceName: string, repoType: RepoType, nextLink: string, options?: SourceControlListRepositoriesNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, repoType, nextLink, options }, listRepositoriesNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listRepositoriesOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/listRepositories", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.RepoList }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.repoType, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const listRepositoriesNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.RepoList }, default: { bodyMapper: Mappers.CloudError } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.nextLink ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer };