UNPKG

@azure/arm-security

Version:
277 lines (262 loc) 8.5 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 { SecureScoreControls } 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 { SecureScoreControlDetails, SecureScoreControlsListBySecureScoreNextOptionalParams, SecureScoreControlsListBySecureScoreOptionalParams, SecureScoreControlsListNextOptionalParams, SecureScoreControlsListOptionalParams, SecureScoreControlsListBySecureScoreResponse, SecureScoreControlsListResponse, SecureScoreControlsListBySecureScoreNextResponse, SecureScoreControlsListNextResponse } from "../models"; /// <reference lib="esnext.asynciterable" /> /** Class containing SecureScoreControls operations. */ export class SecureScoreControlsImpl implements SecureScoreControls { private readonly client: SecurityCenter; /** * Initialize a new instance of the class SecureScoreControls class. * @param client Reference to the service client */ constructor(client: SecurityCenter) { this.client = client; } /** * Get all security controls for a specific initiative within a scope * @param secureScoreName The initiative name. For the ASC Default initiative, use 'ascScore' as in the * sample request below. * @param options The options parameters. */ public listBySecureScore( secureScoreName: string, options?: SecureScoreControlsListBySecureScoreOptionalParams ): PagedAsyncIterableIterator<SecureScoreControlDetails> { const iter = this.listBySecureScorePagingAll(secureScoreName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listBySecureScorePagingPage(secureScoreName, options); } }; } private async *listBySecureScorePagingPage( secureScoreName: string, options?: SecureScoreControlsListBySecureScoreOptionalParams ): AsyncIterableIterator<SecureScoreControlDetails[]> { let result = await this._listBySecureScore(secureScoreName, options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listBySecureScoreNext( secureScoreName, continuationToken, options ); continuationToken = result.nextLink; yield result.value || []; } } private async *listBySecureScorePagingAll( secureScoreName: string, options?: SecureScoreControlsListBySecureScoreOptionalParams ): AsyncIterableIterator<SecureScoreControlDetails> { for await (const page of this.listBySecureScorePagingPage( secureScoreName, options )) { yield* page; } } /** * Get all security controls within a scope * @param options The options parameters. */ public list( options?: SecureScoreControlsListOptionalParams ): PagedAsyncIterableIterator<SecureScoreControlDetails> { const iter = this.listPagingAll(options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listPagingPage(options); } }; } private async *listPagingPage( options?: SecureScoreControlsListOptionalParams ): AsyncIterableIterator<SecureScoreControlDetails[]> { let result = await this._list(options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listNext(continuationToken, options); continuationToken = result.nextLink; yield result.value || []; } } private async *listPagingAll( options?: SecureScoreControlsListOptionalParams ): AsyncIterableIterator<SecureScoreControlDetails> { for await (const page of this.listPagingPage(options)) { yield* page; } } /** * Get all security controls for a specific initiative within a scope * @param secureScoreName The initiative name. For the ASC Default initiative, use 'ascScore' as in the * sample request below. * @param options The options parameters. */ private _listBySecureScore( secureScoreName: string, options?: SecureScoreControlsListBySecureScoreOptionalParams ): Promise<SecureScoreControlsListBySecureScoreResponse> { return this.client.sendOperationRequest( { secureScoreName, options }, listBySecureScoreOperationSpec ); } /** * Get all security controls within a scope * @param options The options parameters. */ private _list( options?: SecureScoreControlsListOptionalParams ): Promise<SecureScoreControlsListResponse> { return this.client.sendOperationRequest({ options }, listOperationSpec); } /** * ListBySecureScoreNext * @param secureScoreName The initiative name. For the ASC Default initiative, use 'ascScore' as in the * sample request below. * @param nextLink The nextLink from the previous successful call to the ListBySecureScore method. * @param options The options parameters. */ private _listBySecureScoreNext( secureScoreName: string, nextLink: string, options?: SecureScoreControlsListBySecureScoreNextOptionalParams ): Promise<SecureScoreControlsListBySecureScoreNextResponse> { return this.client.sendOperationRequest( { secureScoreName, nextLink, options }, listBySecureScoreNextOperationSpec ); } /** * ListNext * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( nextLink: string, options?: SecureScoreControlsListNextOptionalParams ): Promise<SecureScoreControlsListNextResponse> { return this.client.sendOperationRequest( { nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listBySecureScoreOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/providers/Microsoft.Security/secureScores/{secureScoreName}/secureScoreControls", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecureScoreControlList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9, Parameters.expand1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.secureScoreName ], headerParameters: [Parameters.accept], serializer }; const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/providers/Microsoft.Security/secureScoreControls", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecureScoreControlList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9, Parameters.expand1], urlParameters: [Parameters.$host, Parameters.subscriptionId], headerParameters: [Parameters.accept], serializer }; const listBySecureScoreNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecureScoreControlList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9, Parameters.expand1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink, Parameters.secureScoreName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecureScoreControlList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9, Parameters.expand1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };