/* * 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, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { DatabaseSqlVulnerabilityAssessmentsSettings } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { SqlManagementClient } from "../sqlManagementClient"; import { SqlVulnerabilityAssessment, DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseNextOptionalParams, DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseOptionalParams, DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseResponse, SqlVulnerabilityAssessmentName, DatabaseSqlVulnerabilityAssessmentsSettingsGetOptionalParams, DatabaseSqlVulnerabilityAssessmentsSettingsGetResponse, DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseNextResponse } from "../models"; /// /** Class containing DatabaseSqlVulnerabilityAssessmentsSettings operations. */ export class DatabaseSqlVulnerabilityAssessmentsSettingsImpl implements DatabaseSqlVulnerabilityAssessmentsSettings { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class DatabaseSqlVulnerabilityAssessmentsSettings class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Lists SQL Vulnerability Assessment policies associated with a database. * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param options The options parameters. */ public listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByDatabasePagingAll( resourceGroupName, serverName, databaseName, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listByDatabasePagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByDatabase( resourceGroupName, serverName, databaseName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByDatabaseNext( resourceGroupName, serverName, databaseName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByDatabasePagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseOptionalParams ): AsyncIterableIterator { for await (const page of this.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * Lists SQL Vulnerability Assessment policies associated with a database. * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param options The options parameters. */ private _listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseOptionalParams ): Promise< DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseResponse > { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listByDatabaseOperationSpec ); } /** * Gets SQL Vulnerability Assessment policy for database. * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param vulnerabilityAssessmentName The name of the SQL Vulnerability Assessment. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, databaseName: string, vulnerabilityAssessmentName: SqlVulnerabilityAssessmentName, options?: DatabaseSqlVulnerabilityAssessmentsSettingsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, vulnerabilityAssessmentName, options }, getOperationSpec ); } /** * ListByDatabaseNext * @param resourceGroupName The name of the resource group that contains the resource. You can obtain * this value from the Azure Resource Manager API or the portal. * @param serverName The name of the server. * @param databaseName The name of the database. * @param nextLink The nextLink from the previous successful call to the ListByDatabase method. * @param options The options parameters. */ private _listByDatabaseNext( resourceGroupName: string, serverName: string, databaseName: string, nextLink: string, options?: DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseNextOptionalParams ): Promise< DatabaseSqlVulnerabilityAssessmentsSettingsListByDatabaseNextResponse > { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, nextLink, options }, listByDatabaseNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByDatabaseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/sqlVulnerabilityAssessments", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SqlVulnerabilityAssessmentListResult }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/sqlVulnerabilityAssessments/{vulnerabilityAssessmentName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SqlVulnerabilityAssessment }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.vulnerabilityAssessmentName2 ], headerParameters: [Parameters.accept], serializer }; const listByDatabaseNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SqlVulnerabilityAssessmentListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };