/*
* 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 { Incidents } 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 {
Incident,
IncidentsListNextOptionalParams,
IncidentsListOptionalParams,
IncidentsListResponse,
IncidentsRunPlaybookOptionalParams,
IncidentsRunPlaybookResponse,
IncidentsGetOptionalParams,
IncidentsGetResponse,
IncidentsCreateOrUpdateOptionalParams,
IncidentsCreateOrUpdateResponse,
IncidentsDeleteOptionalParams,
TeamProperties,
IncidentsCreateTeamOptionalParams,
IncidentsCreateTeamResponse,
IncidentsListAlertsOptionalParams,
IncidentsListAlertsResponse,
IncidentsListBookmarksOptionalParams,
IncidentsListBookmarksResponse,
IncidentsListEntitiesOptionalParams,
IncidentsListEntitiesResponse,
IncidentsListNextResponse
} from "../models";
///
/** Class containing Incidents operations. */
export class IncidentsImpl implements Incidents {
private readonly client: SecurityInsights;
/**
* Initialize a new instance of the class Incidents class.
* @param client Reference to the service client
*/
constructor(client: SecurityInsights) {
this.client = client;
}
/**
* Gets all incidents.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param options The options parameters.
*/
public list(
resourceGroupName: string,
workspaceName: string,
options?: IncidentsListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(resourceGroupName, workspaceName, 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,
options,
settings
);
}
};
}
private async *listPagingPage(
resourceGroupName: string,
workspaceName: string,
options?: IncidentsListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: IncidentsListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(resourceGroupName, workspaceName, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
resourceGroupName,
workspaceName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
resourceGroupName: string,
workspaceName: string,
options?: IncidentsListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(
resourceGroupName,
workspaceName,
options
)) {
yield* page;
}
}
/**
* Triggers playbook on a specific incident
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param incidentIdentifier
* @param options The options parameters.
*/
runPlaybook(
resourceGroupName: string,
workspaceName: string,
incidentIdentifier: string,
options?: IncidentsRunPlaybookOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentIdentifier, options },
runPlaybookOperationSpec
);
}
/**
* Gets all incidents.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param options The options parameters.
*/
private _list(
resourceGroupName: string,
workspaceName: string,
options?: IncidentsListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, options },
listOperationSpec
);
}
/**
* Gets an incident.
* @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.
*/
get(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
options?: IncidentsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, options },
getOperationSpec
);
}
/**
* Creates or updates the incident.
* @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 incident The incident
* @param options The options parameters.
*/
createOrUpdate(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
incident: Incident,
options?: IncidentsCreateOrUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, incident, options },
createOrUpdateOperationSpec
);
}
/**
* Delete the incident.
* @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.
*/
delete(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
options?: IncidentsDeleteOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, options },
deleteOperationSpec
);
}
/**
* Creates a Microsoft team to investigate the incident by sharing information and insights between
* participants.
* @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 teamProperties Team properties
* @param options The options parameters.
*/
createTeam(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
teamProperties: TeamProperties,
options?: IncidentsCreateTeamOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, teamProperties, options },
createTeamOperationSpec
);
}
/**
* Gets all incident alerts.
* @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.
*/
listAlerts(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
options?: IncidentsListAlertsOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, options },
listAlertsOperationSpec
);
}
/**
* Gets all incident bookmarks.
* @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.
*/
listBookmarks(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
options?: IncidentsListBookmarksOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, options },
listBookmarksOperationSpec
);
}
/**
* Gets all incident related entities.
* @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.
*/
listEntities(
resourceGroupName: string,
workspaceName: string,
incidentId: string,
options?: IncidentsListEntitiesOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, incidentId, options },
listEntitiesOperationSpec
);
}
/**
* ListNext
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
resourceGroupName: string,
workspaceName: string,
nextLink: string,
options?: IncidentsListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const runPlaybookOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentIdentifier}/runPlaybook",
httpMethod: "POST",
responses: {
204: {
bodyMapper: {
type: { name: "Dictionary", value: { type: { name: "any" } } }
}
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.requestBody,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentIdentifier
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.IncidentList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.filter,
Parameters.orderby,
Parameters.top,
Parameters.skipToken
],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Incident
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Incident
},
201: {
bodyMapper: Mappers.Incident
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.incident,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
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}",
httpMethod: "DELETE",
responses: {
200: {},
204: {},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept],
serializer
};
const createTeamOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/createTeam",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.TeamInformation
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.teamProperties,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listAlertsOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/alerts",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.IncidentAlertList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept],
serializer
};
const listBookmarksOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/bookmarks",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.IncidentBookmarkList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept],
serializer
};
const listEntitiesOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/incidents/{incidentId}/entities",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.IncidentEntitiesResponse
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.incidentId
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.IncidentList
},
default: {
bodyMapper: Mappers.CloudError
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};