UNPKG

@azure/arm-security

Version:
328 lines (317 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 { ServerVulnerabilityAssessmentOperations } 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 { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro"; import { LroImpl } from "../lroImpl"; import { ServerVulnerabilityAssessmentListByExtendedResourceOptionalParams, ServerVulnerabilityAssessmentListByExtendedResourceResponse, ServerVulnerabilityAssessmentGetOptionalParams, ServerVulnerabilityAssessmentGetResponse, ServerVulnerabilityAssessmentCreateOrUpdateOptionalParams, ServerVulnerabilityAssessmentCreateOrUpdateResponse, ServerVulnerabilityAssessmentDeleteOptionalParams } from "../models"; /** Class containing ServerVulnerabilityAssessmentOperations operations. */ export class ServerVulnerabilityAssessmentOperationsImpl implements ServerVulnerabilityAssessmentOperations { private readonly client: SecurityCenter; /** * Initialize a new instance of the class ServerVulnerabilityAssessmentOperations class. * @param client Reference to the service client */ constructor(client: SecurityCenter) { this.client = client; } /** * Gets a list of server vulnerability assessment onboarding statuses on a given resource. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param resourceNamespace The Namespace of the resource. * @param resourceType The type of the resource. * @param resourceName Name of the resource. * @param options The options parameters. */ listByExtendedResource( resourceGroupName: string, resourceNamespace: string, resourceType: string, resourceName: string, options?: ServerVulnerabilityAssessmentListByExtendedResourceOptionalParams ): Promise<ServerVulnerabilityAssessmentListByExtendedResourceResponse> { return this.client.sendOperationRequest( { resourceGroupName, resourceNamespace, resourceType, resourceName, options }, listByExtendedResourceOperationSpec ); } /** * Gets a server vulnerability assessment onboarding statuses on a given resource. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param resourceNamespace The Namespace of the resource. * @param resourceType The type of the resource. * @param resourceName Name of the resource. * @param options The options parameters. */ get( resourceGroupName: string, resourceNamespace: string, resourceType: string, resourceName: string, options?: ServerVulnerabilityAssessmentGetOptionalParams ): Promise<ServerVulnerabilityAssessmentGetResponse> { return this.client.sendOperationRequest( { resourceGroupName, resourceNamespace, resourceType, resourceName, options }, getOperationSpec ); } /** * Creating a server vulnerability assessment on a resource, which will onboard a resource for having a * vulnerability assessment on it * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param resourceNamespace The Namespace of the resource. * @param resourceType The type of the resource. * @param resourceName Name of the resource. * @param options The options parameters. */ createOrUpdate( resourceGroupName: string, resourceNamespace: string, resourceType: string, resourceName: string, options?: ServerVulnerabilityAssessmentCreateOrUpdateOptionalParams ): Promise<ServerVulnerabilityAssessmentCreateOrUpdateResponse> { return this.client.sendOperationRequest( { resourceGroupName, resourceNamespace, resourceType, resourceName, options }, createOrUpdateOperationSpec ); } /** * Removing server vulnerability assessment from a resource. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param resourceNamespace The Namespace of the resource. * @param resourceType The type of the resource. * @param resourceName Name of the resource. * @param options The options parameters. */ async beginDelete( resourceGroupName: string, resourceNamespace: string, resourceType: string, resourceName: string, options?: ServerVulnerabilityAssessmentDeleteOptionalParams ): Promise<PollerLike<PollOperationState<void>, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise<void> => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback } }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON() } }; }; const lro = new LroImpl( sendOperation, { resourceGroupName, resourceNamespace, resourceType, resourceName, options }, deleteOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, lroResourceLocationConfig: "location" }); await poller.poll(); return poller; } /** * Removing server vulnerability assessment from a resource. * @param resourceGroupName The name of the resource group within the user's subscription. The name is * case insensitive. * @param resourceNamespace The Namespace of the resource. * @param resourceType The type of the resource. * @param resourceName Name of the resource. * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, resourceNamespace: string, resourceType: string, resourceName: string, options?: ServerVulnerabilityAssessmentDeleteOptionalParams ): Promise<void> { const poller = await this.beginDelete( resourceGroupName, resourceNamespace, resourceType, resourceName, options ); return poller.pollUntilDone(); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByExtendedResourceOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/serverVulnerabilityAssessments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ServerVulnerabilityAssessmentsList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.resourceNamespace, Parameters.resourceType, Parameters.resourceName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/serverVulnerabilityAssessments/{serverVulnerabilityAssessment}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ServerVulnerabilityAssessment }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.resourceNamespace, Parameters.resourceType, Parameters.resourceName, Parameters.serverVulnerabilityAssessment ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/serverVulnerabilityAssessments/{serverVulnerabilityAssessment}", httpMethod: "PUT", responses: { 202: { bodyMapper: Mappers.ServerVulnerabilityAssessment }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.resourceNamespace, Parameters.resourceType, Parameters.resourceName, Parameters.serverVulnerabilityAssessment ], headerParameters: [Parameters.accept], serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.Security/serverVulnerabilityAssessments/{serverVulnerabilityAssessment}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion9], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.resourceNamespace, Parameters.resourceType, Parameters.resourceName, Parameters.serverVulnerabilityAssessment ], headerParameters: [Parameters.accept], serializer };