/* * 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 { IncidentComments } 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 { IncidentComment, IncidentCommentsListNextOptionalParams, IncidentCommentsListOptionalParams, IncidentCommentsListResponse, IncidentCommentsGetOptionalParams, IncidentCommentsGetResponse, IncidentCommentsCreateOrUpdateOptionalParams, IncidentCommentsCreateOrUpdateResponse, IncidentCommentsDeleteOptionalParams, IncidentCommentsListNextResponse } from "../models"; /// /** Class containing IncidentComments operations. */ export class IncidentCommentsImpl implements IncidentComments { private readonly client: SecurityInsights; /** * Initialize a new instance of the class IncidentComments class. * @param client Reference to the service client */ constructor(client: SecurityInsights) { this.client = client; } /** * Gets all incident comments. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param options The options parameters. */ public list( resourceGroupName: string, workspaceName: string, incidentId: string, options?: IncidentCommentsListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll( resourceGroupName, workspaceName, incidentId, 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, workspaceName, incidentId, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, workspaceName: string, incidentId: string, options?: IncidentCommentsListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: IncidentCommentsListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list( resourceGroupName, workspaceName, incidentId, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, workspaceName, incidentId, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, workspaceName: string, incidentId: string, options?: IncidentCommentsListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, workspaceName, incidentId, options )) { yield* page; } } /** * Gets all incident comments. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param options The options parameters. */ private _list( resourceGroupName: string, workspaceName: string, incidentId: string, options?: IncidentCommentsListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, incidentId, options }, listOperationSpec ); } /** * Gets an incident comment. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param incidentCommentId Incident comment ID * @param options The options parameters. */ get( resourceGroupName: string, workspaceName: string, incidentId: string, incidentCommentId: string, options?: IncidentCommentsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, incidentId, incidentCommentId, options }, getOperationSpec ); } /** * Creates or updates the incident comment. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param incidentCommentId Incident comment ID * @param incidentComment The incident comment * @param options The options parameters. */ createOrUpdate( resourceGroupName: string, workspaceName: string, incidentId: string, incidentCommentId: string, incidentComment: IncidentComment, options?: IncidentCommentsCreateOrUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, incidentId, incidentCommentId, incidentComment, options }, createOrUpdateOperationSpec ); } /** * Delete the incident comment. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param incidentCommentId Incident comment ID * @param options The options parameters. */ delete( resourceGroupName: string, workspaceName: string, incidentId: string, incidentCommentId: string, options?: IncidentCommentsDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, incidentId, incidentCommentId, options }, deleteOperationSpec ); } /** * ListNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param workspaceName The name of the workspace. * @param incidentId Incident ID * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, workspaceName: string, incidentId: string, nextLink: string, options?: IncidentCommentsListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, workspaceName, incidentId, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.IncidentCommentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.filter, Parameters.orderby, Parameters.top, Parameters.skipToken ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.incidentId ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments/{incidentCommentId}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.IncidentComment }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.incidentId, Parameters.incidentCommentId ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments/{incidentCommentId}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.IncidentComment }, 201: { bodyMapper: Mappers.IncidentComment }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.incidentComment, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.incidentId, Parameters.incidentCommentId ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/comments/{incidentCommentId}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.incidentId, Parameters.incidentCommentId ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.IncidentCommentList }, default: { bodyMapper: Mappers.CloudError } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.workspaceName, Parameters.nextLink, Parameters.incidentId ], headerParameters: [Parameters.accept], serializer };