UNPKG

@azure/arm-security

Version:
419 lines (401 loc) 14.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 { PagedAsyncIterableIterator } from "@azure/core-paging"; import { CustomAssessmentAutomations } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { SecurityCenter } from "../securityCenter"; import { CustomAssessmentAutomation, CustomAssessmentAutomationsListByResourceGroupNextOptionalParams, CustomAssessmentAutomationsListByResourceGroupOptionalParams, CustomAssessmentAutomationsListBySubscriptionNextOptionalParams, CustomAssessmentAutomationsListBySubscriptionOptionalParams, CustomAssessmentAutomationsGetOptionalParams, CustomAssessmentAutomationsGetResponse, CustomAssessmentAutomationRequest, CustomAssessmentAutomationsCreateOptionalParams, CustomAssessmentAutomationsCreateResponse, CustomAssessmentAutomationsDeleteOptionalParams, CustomAssessmentAutomationsListByResourceGroupResponse, CustomAssessmentAutomationsListBySubscriptionResponse, CustomAssessmentAutomationsListByResourceGroupNextResponse, CustomAssessmentAutomationsListBySubscriptionNextResponse } from "../models"; /// <reference lib="esnext.asynciterable" /> /** Class containing CustomAssessmentAutomations operations. */ export class CustomAssessmentAutomationsImpl implements CustomAssessmentAutomations { private readonly client: SecurityCenter; /** * Initialize a new instance of the class CustomAssessmentAutomations class. * @param client Reference to the service client */ constructor(client: SecurityCenter) { this.client = client; } /** * List custom assessment automations by provided subscription and resource group * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param options The options parameters. */ public listByResourceGroup( resourceGroupName: string, options?: CustomAssessmentAutomationsListByResourceGroupOptionalParams ): PagedAsyncIterableIterator<CustomAssessmentAutomation> { const iter = this.listByResourceGroupPagingAll(resourceGroupName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listByResourceGroupPagingPage(resourceGroupName, options); } }; } private async *listByResourceGroupPagingPage( resourceGroupName: string, options?: CustomAssessmentAutomationsListByResourceGroupOptionalParams ): AsyncIterableIterator<CustomAssessmentAutomation[]> { let result = await this._listByResourceGroup(resourceGroupName, options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listByResourceGroupNext( resourceGroupName, continuationToken, options ); continuationToken = result.nextLink; yield result.value || []; } } private async *listByResourceGroupPagingAll( resourceGroupName: string, options?: CustomAssessmentAutomationsListByResourceGroupOptionalParams ): AsyncIterableIterator<CustomAssessmentAutomation> { for await (const page of this.listByResourceGroupPagingPage( resourceGroupName, options )) { yield* page; } } /** * List custom assessment automations by provided subscription * @param options The options parameters. */ public listBySubscription( options?: CustomAssessmentAutomationsListBySubscriptionOptionalParams ): PagedAsyncIterableIterator<CustomAssessmentAutomation> { const iter = this.listBySubscriptionPagingAll(options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listBySubscriptionPagingPage(options); } }; } private async *listBySubscriptionPagingPage( options?: CustomAssessmentAutomationsListBySubscriptionOptionalParams ): AsyncIterableIterator<CustomAssessmentAutomation[]> { let result = await this._listBySubscription(options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listBySubscriptionNext(continuationToken, options); continuationToken = result.nextLink; yield result.value || []; } } private async *listBySubscriptionPagingAll( options?: CustomAssessmentAutomationsListBySubscriptionOptionalParams ): AsyncIterableIterator<CustomAssessmentAutomation> { for await (const page of this.listBySubscriptionPagingPage(options)) { yield* page; } } /** * Gets a single custom assessment automation by name for the provided subscription and resource group. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param customAssessmentAutomationName Name of the Custom Assessment Automation. * @param options The options parameters. */ get( resourceGroupName: string, customAssessmentAutomationName: string, options?: CustomAssessmentAutomationsGetOptionalParams ): Promise<CustomAssessmentAutomationsGetResponse> { return this.client.sendOperationRequest( { resourceGroupName, customAssessmentAutomationName, options }, getOperationSpec ); } /** * Creates or updates a custom assessment automation for the provided subscription. Please note that * providing an existing custom assessment automation will replace the existing record. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param customAssessmentAutomationName Name of the Custom Assessment Automation. * @param customAssessmentAutomationBody Custom Assessment Automation body * @param options The options parameters. */ create( resourceGroupName: string, customAssessmentAutomationName: string, customAssessmentAutomationBody: CustomAssessmentAutomationRequest, options?: CustomAssessmentAutomationsCreateOptionalParams ): Promise<CustomAssessmentAutomationsCreateResponse> { return this.client.sendOperationRequest( { resourceGroupName, customAssessmentAutomationName, customAssessmentAutomationBody, options }, createOperationSpec ); } /** * Deletes a custom assessment automation by name for a provided subscription * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param customAssessmentAutomationName Name of the Custom Assessment Automation. * @param options The options parameters. */ delete( resourceGroupName: string, customAssessmentAutomationName: string, options?: CustomAssessmentAutomationsDeleteOptionalParams ): Promise<void> { return this.client.sendOperationRequest( { resourceGroupName, customAssessmentAutomationName, options }, deleteOperationSpec ); } /** * List custom assessment automations by provided subscription and resource group * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param options The options parameters. */ private _listByResourceGroup( resourceGroupName: string, options?: CustomAssessmentAutomationsListByResourceGroupOptionalParams ): Promise<CustomAssessmentAutomationsListByResourceGroupResponse> { return this.client.sendOperationRequest( { resourceGroupName, options }, listByResourceGroupOperationSpec ); } /** * List custom assessment automations by provided subscription * @param options The options parameters. */ private _listBySubscription( options?: CustomAssessmentAutomationsListBySubscriptionOptionalParams ): Promise<CustomAssessmentAutomationsListBySubscriptionResponse> { return this.client.sendOperationRequest( { options }, listBySubscriptionOperationSpec ); } /** * ListByResourceGroupNext * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param nextLink The nextLink from the previous successful call to the ListByResourceGroup method. * @param options The options parameters. */ private _listByResourceGroupNext( resourceGroupName: string, nextLink: string, options?: CustomAssessmentAutomationsListByResourceGroupNextOptionalParams ): Promise<CustomAssessmentAutomationsListByResourceGroupNextResponse> { return this.client.sendOperationRequest( { resourceGroupName, nextLink, options }, listByResourceGroupNextOperationSpec ); } /** * ListBySubscriptionNext * @param nextLink The nextLink from the previous successful call to the ListBySubscription method. * @param options The options parameters. */ private _listBySubscriptionNext( nextLink: string, options?: CustomAssessmentAutomationsListBySubscriptionNextOptionalParams ): Promise<CustomAssessmentAutomationsListBySubscriptionNextResponse> { return this.client.sendOperationRequest( { nextLink, options }, listBySubscriptionNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Security/customAssessmentAutomations/{customAssessmentAutomationName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomation }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.customAssessmentAutomationName ], headerParameters: [Parameters.accept], serializer }; const createOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Security/customAssessmentAutomations/{customAssessmentAutomationName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomation }, 201: { bodyMapper: Mappers.CustomAssessmentAutomation }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.customAssessmentAutomationBody, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.customAssessmentAutomationName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Security/customAssessmentAutomations/{customAssessmentAutomationName}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.customAssessmentAutomationName ], headerParameters: [Parameters.accept], serializer }; const listByResourceGroupOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Security/customAssessmentAutomations", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomationsListResult }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName ], headerParameters: [Parameters.accept], serializer }; const listBySubscriptionOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/providers/Microsoft.Security/customAssessmentAutomations", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomationsListResult }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [Parameters.$host, Parameters.subscriptionId], headerParameters: [Parameters.accept], serializer }; const listByResourceGroupNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomationsListResult }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer }; const listBySubscriptionNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CustomAssessmentAutomationsListResult }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };