UNPKG

@azure/arm-security

Version:
283 lines (270 loc) 8.71 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 { Assessments } 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 { SecurityAssessmentResponse, AssessmentsListNextOptionalParams, AssessmentsListOptionalParams, AssessmentsListResponse, AssessmentsGetOptionalParams, AssessmentsGetResponse, SecurityAssessment, AssessmentsCreateOrUpdateOptionalParams, AssessmentsCreateOrUpdateResponse, AssessmentsDeleteOptionalParams, AssessmentsListNextResponse } from "../models"; /// <reference lib="esnext.asynciterable" /> /** Class containing Assessments operations. */ export class AssessmentsImpl implements Assessments { private readonly client: SecurityCenter; /** * Initialize a new instance of the class Assessments class. * @param client Reference to the service client */ constructor(client: SecurityCenter) { this.client = client; } /** * Get security 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 options The options parameters. */ public list( scope: string, options?: AssessmentsListOptionalParams ): PagedAsyncIterableIterator<SecurityAssessmentResponse> { const iter = this.listPagingAll(scope, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: () => { return this.listPagingPage(scope, options); } }; } private async *listPagingPage( scope: string, options?: AssessmentsListOptionalParams ): AsyncIterableIterator<SecurityAssessmentResponse[]> { let result = await this._list(scope, options); yield result.value || []; let continuationToken = result.nextLink; while (continuationToken) { result = await this._listNext(scope, continuationToken, options); continuationToken = result.nextLink; yield result.value || []; } } private async *listPagingAll( scope: string, options?: AssessmentsListOptionalParams ): AsyncIterableIterator<SecurityAssessmentResponse> { for await (const page of this.listPagingPage(scope, options)) { yield* page; } } /** * Get security 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 options The options parameters. */ private _list( scope: string, options?: AssessmentsListOptionalParams ): Promise<AssessmentsListResponse> { return this.client.sendOperationRequest( { scope, options }, listOperationSpec ); } /** * Get a security assessment on your scanned resource * @param resourceId The identifier of the resource. * @param assessmentName The Assessment Key - Unique key for the assessment type * @param options The options parameters. */ get( resourceId: string, assessmentName: string, options?: AssessmentsGetOptionalParams ): Promise<AssessmentsGetResponse> { return this.client.sendOperationRequest( { resourceId, assessmentName, options }, getOperationSpec ); } /** * Create a security assessment on your resource. An assessment metadata that describes this assessment * must be predefined with the same name before inserting the assessment result * @param resourceId The identifier of the resource. * @param assessmentName The Assessment Key - Unique key for the assessment type * @param assessment Calculated assessment on a pre-defined assessment metadata * @param options The options parameters. */ createOrUpdate( resourceId: string, assessmentName: string, assessment: SecurityAssessment, options?: AssessmentsCreateOrUpdateOptionalParams ): Promise<AssessmentsCreateOrUpdateResponse> { return this.client.sendOperationRequest( { resourceId, assessmentName, assessment, options }, createOrUpdateOperationSpec ); } /** * Delete a security assessment on your resource. An assessment metadata that describes this assessment * must be predefined with the same name before inserting the assessment result * @param resourceId The identifier of the resource. * @param assessmentName The Assessment Key - Unique key for the assessment type * @param options The options parameters. */ delete( resourceId: string, assessmentName: string, options?: AssessmentsDeleteOptionalParams ): Promise<void> { return this.client.sendOperationRequest( { resourceId, assessmentName, options }, deleteOperationSpec ); } /** * 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 nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( scope: string, nextLink: string, options?: AssessmentsListNextOptionalParams ): Promise<AssessmentsListNextResponse> { return this.client.sendOperationRequest( { scope, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Security/assessments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecurityAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion10], urlParameters: [Parameters.$host, Parameters.scope], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/{resourceId}/providers/Microsoft.Security/assessments/{assessmentName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecurityAssessmentResponse }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion10, Parameters.expand], urlParameters: [ Parameters.$host, Parameters.resourceId, Parameters.assessmentName ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/{resourceId}/providers/Microsoft.Security/assessments/{assessmentName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.SecurityAssessmentResponse }, 201: { bodyMapper: Mappers.SecurityAssessmentResponse }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.assessment, queryParameters: [Parameters.apiVersion10], urlParameters: [ Parameters.$host, Parameters.resourceId, Parameters.assessmentName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/{resourceId}/providers/Microsoft.Security/assessments/{assessmentName}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion10], urlParameters: [ Parameters.$host, Parameters.resourceId, Parameters.assessmentName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SecurityAssessmentList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion10], urlParameters: [Parameters.$host, Parameters.nextLink, Parameters.scope], headerParameters: [Parameters.accept], serializer };