UNPKG

@azure/arm-security

Version:
347 lines (331 loc) 10.9 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 { SubAssessments } 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 { SecuritySubAssessment, SubAssessmentsListAllNextOptionalParams, SubAssessmentsListAllOptionalParams, SubAssessmentsListNextOptionalParams, SubAssessmentsListOptionalParams, SubAssessmentsListAllResponse, SubAssessmentsListResponse, SubAssessmentsGetOptionalParams, SubAssessmentsGetResponse, SubAssessmentsListAllNextResponse, SubAssessmentsListNextResponse } from "../models"; /// <reference lib="esnext.asynciterable" /> /** Class containing SubAssessments operations. */ export class SubAssessmentsImpl implements SubAssessments { private readonly client: SecurityCenter; /** * Initialize a new instance of the class SubAssessments class. * @param client Reference to the service client */ constructor(client: SecurityCenter) { this.client = client; } /** * Get security sub-assessments on all your scanned resources inside a subscription scope * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param options The options parameters. */ public listAll( scope: string, options?: SubAssessmentsListAllOptionalParams ): PagedAsyncIterableIterator<SecuritySubAssessment> { const iter = this.listAllPagingAll(scope, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listAllPagingPage(scope, options); } }; } private async *listAllPagingPage( scope: string, options?: SubAssessmentsListAllOptionalParams ): AsyncIterableIterator<SecuritySubAssessment[]> { let result = await this._listAll(scope, options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listAllNext(scope, continuationToken, options); continuationToken = result.nextLink; yield result.value || []; } } private async *listAllPagingAll( scope: string, options?: SubAssessmentsListAllOptionalParams ): AsyncIterableIterator<SecuritySubAssessment> { for await (const page of this.listAllPagingPage(scope, options)) { yield* page; } } /** * Get security sub-assessments on all your scanned resources inside a scope * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param assessmentName The Assessment Key - Unique key for the assessment type * @param options The options parameters. */ public list( scope: string, assessmentName: string, options?: SubAssessmentsListOptionalParams ): PagedAsyncIterableIterator<SecuritySubAssessment> { const iter = this.listPagingAll(scope, assessmentName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listPagingPage(scope, assessmentName, options); } }; } private async *listPagingPage( scope: string, assessmentName: string, options?: SubAssessmentsListOptionalParams ): AsyncIterableIterator<SecuritySubAssessment[]> { let result = await this._list(scope, assessmentName, options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listNext( scope, assessmentName, continuationToken, options ); continuationToken = result.nextLink; yield result.value || []; } } private async *listPagingAll( scope: string, assessmentName: string, options?: SubAssessmentsListOptionalParams ): AsyncIterableIterator<SecuritySubAssessment> { for await (const page of this.listPagingPage( scope, assessmentName, options )) { yield* page; } } /** * Get security sub-assessments on all your scanned resources inside a subscription scope * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param options The options parameters. */ private _listAll( scope: string, options?: SubAssessmentsListAllOptionalParams ): Promise<SubAssessmentsListAllResponse> { return this.client.sendOperationRequest( { scope, options }, listAllOperationSpec ); } /** * Get security sub-assessments on all your scanned resources inside a scope * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param assessmentName The Assessment Key - Unique key for the assessment type * @param options The options parameters. */ private _list( scope: string, assessmentName: string, options?: SubAssessmentsListOptionalParams ): Promise<SubAssessmentsListResponse> { return this.client.sendOperationRequest( { scope, assessmentName, options }, listOperationSpec ); } /** * Get a security sub-assessment on your scanned resource * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param assessmentName The Assessment Key - Unique key for the assessment type * @param subAssessmentName The Sub-Assessment Key - Unique key for the sub-assessment type * @param options The options parameters. */ get( scope: string, assessmentName: string, subAssessmentName: string, options?: SubAssessmentsGetOptionalParams ): Promise<SubAssessmentsGetResponse> { return this.client.sendOperationRequest( { scope, assessmentName, subAssessmentName, options }, getOperationSpec ); } /** * ListAllNext * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param nextLink The nextLink from the previous successful call to the ListAll method. * @param options The options parameters. */ private _listAllNext( scope: string, nextLink: string, options?: SubAssessmentsListAllNextOptionalParams ): Promise<SubAssessmentsListAllNextResponse> { return this.client.sendOperationRequest( { scope, nextLink, options }, listAllNextOperationSpec ); } /** * ListNext * @param scope Scope of the query, can be subscription * (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group * (/providers/Microsoft.Management/managementGroups/mgName). * @param assessmentName The Assessment Key - Unique key for the assessment type * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( scope: string, assessmentName: string, nextLink: string, options?: SubAssessmentsListNextOptionalParams ): Promise<SubAssessmentsListNextResponse> { return this.client.sendOperationRequest( { scope, assessmentName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listAllOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Security/subAssessments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecuritySubAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion8], urlParameters: [Parameters.$host, Parameters.scope], headerParameters: [Parameters.accept], serializer }; const listOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Security/assessments/{assessmentName}/subAssessments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecuritySubAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion8], urlParameters: [ Parameters.$host, Parameters.scope, Parameters.assessmentName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Security/assessments/{assessmentName}/subAssessments/{subAssessmentName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecuritySubAssessment }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion8], urlParameters: [ Parameters.$host, Parameters.scope, Parameters.assessmentName, Parameters.subAssessmentName ], headerParameters: [Parameters.accept], serializer }; const listAllNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecuritySubAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion8], urlParameters: [Parameters.$host, Parameters.nextLink, Parameters.scope], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecuritySubAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion8], urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.scope, Parameters.assessmentName ], headerParameters: [Parameters.accept], serializer };