/* * 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 { SensitivityLabels } 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 { SensitivityLabel, SensitivityLabelsListCurrentByDatabaseNextOptionalParams, SensitivityLabelsListCurrentByDatabaseOptionalParams, SensitivityLabelsListCurrentByDatabaseResponse, SensitivityLabelsListRecommendedByDatabaseNextOptionalParams, SensitivityLabelsListRecommendedByDatabaseOptionalParams, SensitivityLabelsListRecommendedByDatabaseResponse, SensitivityLabelUpdateList, SensitivityLabelsUpdateOptionalParams, SensitivityLabelsEnableRecommendationOptionalParams, SensitivityLabelsDisableRecommendationOptionalParams, SensitivityLabelSource, SensitivityLabelsGetOptionalParams, SensitivityLabelsGetResponse, SensitivityLabelsCreateOrUpdateOptionalParams, SensitivityLabelsCreateOrUpdateResponse, SensitivityLabelsDeleteOptionalParams, SensitivityLabelsListCurrentByDatabaseNextResponse, SensitivityLabelsListRecommendedByDatabaseNextResponse } from "../models"; /// /** Class containing SensitivityLabels operations. */ export class SensitivityLabelsImpl implements SensitivityLabels { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class SensitivityLabels class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Gets the sensitivity labels of a given 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 listCurrentByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListCurrentByDatabaseOptionalParams ): PagedAsyncIterableIterator { const iter = this.listCurrentByDatabasePagingAll( 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.listCurrentByDatabasePagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listCurrentByDatabasePagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListCurrentByDatabaseOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: SensitivityLabelsListCurrentByDatabaseResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listCurrentByDatabase( resourceGroupName, serverName, databaseName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listCurrentByDatabaseNext( resourceGroupName, serverName, databaseName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listCurrentByDatabasePagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListCurrentByDatabaseOptionalParams ): AsyncIterableIterator { for await (const page of this.listCurrentByDatabasePagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * Gets the sensitivity labels of a given 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 listRecommendedByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListRecommendedByDatabaseOptionalParams ): PagedAsyncIterableIterator { const iter = this.listRecommendedByDatabasePagingAll( 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.listRecommendedByDatabasePagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listRecommendedByDatabasePagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListRecommendedByDatabaseOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: SensitivityLabelsListRecommendedByDatabaseResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listRecommendedByDatabase( resourceGroupName, serverName, databaseName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listRecommendedByDatabaseNext( resourceGroupName, serverName, databaseName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listRecommendedByDatabasePagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListRecommendedByDatabaseOptionalParams ): AsyncIterableIterator { for await (const page of this.listRecommendedByDatabasePagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * Gets the sensitivity labels of a given 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 _listCurrentByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListCurrentByDatabaseOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listCurrentByDatabaseOperationSpec ); } /** * Update sensitivity labels of a given database using an operations batch. * @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 parameters A list of sensitivity label update operations. * @param options The options parameters. */ update( resourceGroupName: string, serverName: string, databaseName: string, parameters: SensitivityLabelUpdateList, options?: SensitivityLabelsUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, parameters, options }, updateOperationSpec ); } /** * Gets the sensitivity labels of a given 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 _listRecommendedByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: SensitivityLabelsListRecommendedByDatabaseOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listRecommendedByDatabaseOperationSpec ); } /** * Enables sensitivity recommendations on a given column (recommendations are enabled by default on all * columns) * @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 schemaName The name of the schema. * @param tableName The name of the table. * @param columnName The name of the column. * @param options The options parameters. */ enableRecommendation( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, tableName: string, columnName: string, options?: SensitivityLabelsEnableRecommendationOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, options }, enableRecommendationOperationSpec ); } /** * Disables sensitivity recommendations on a given column * @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 schemaName The name of the schema. * @param tableName The name of the table. * @param columnName The name of the column. * @param options The options parameters. */ disableRecommendation( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, tableName: string, columnName: string, options?: SensitivityLabelsDisableRecommendationOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, options }, disableRecommendationOperationSpec ); } /** * Gets the sensitivity label of a given column * @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 schemaName The name of the schema. * @param tableName The name of the table. * @param columnName The name of the column. * @param sensitivityLabelSource The source of the sensitivity label. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, tableName: string, columnName: string, sensitivityLabelSource: SensitivityLabelSource, options?: SensitivityLabelsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, sensitivityLabelSource, options }, getOperationSpec ); } /** * Creates or updates the sensitivity label of a given column * @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 schemaName The name of the schema. * @param tableName The name of the table. * @param columnName The name of the column. * @param parameters The column sensitivity label resource. * @param options The options parameters. */ createOrUpdate( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, tableName: string, columnName: string, parameters: SensitivityLabel, options?: SensitivityLabelsCreateOrUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, parameters, options }, createOrUpdateOperationSpec ); } /** * Deletes the sensitivity label of a given column * @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 schemaName The name of the schema. * @param tableName The name of the table. * @param columnName The name of the column. * @param options The options parameters. */ delete( resourceGroupName: string, serverName: string, databaseName: string, schemaName: string, tableName: string, columnName: string, options?: SensitivityLabelsDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, options }, deleteOperationSpec ); } /** * ListCurrentByDatabaseNext * @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 ListCurrentByDatabase method. * @param options The options parameters. */ private _listCurrentByDatabaseNext( resourceGroupName: string, serverName: string, databaseName: string, nextLink: string, options?: SensitivityLabelsListCurrentByDatabaseNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, nextLink, options }, listCurrentByDatabaseNextOperationSpec ); } /** * ListRecommendedByDatabaseNext * @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 ListRecommendedByDatabase * method. * @param options The options parameters. */ private _listRecommendedByDatabaseNext( resourceGroupName: string, serverName: string, databaseName: string, nextLink: string, options?: SensitivityLabelsListRecommendedByDatabaseNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, nextLink, options }, listRecommendedByDatabaseNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listCurrentByDatabaseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SensitivityLabelListResult }, default: {} }, queryParameters: [ Parameters.skipToken, Parameters.filter1, Parameters.apiVersion3, Parameters.count ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels", httpMethod: "PATCH", responses: { 200: {}, default: {} }, requestBody: Parameters.parameters73, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.contentType], mediaType: "json", serializer }; const listRecommendedByDatabaseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SensitivityLabelListResult }, default: {} }, queryParameters: [ Parameters.skipToken, Parameters.filter1, Parameters.apiVersion3, Parameters.includeDisabledRecommendations ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const enableRecommendationOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable", httpMethod: "POST", responses: { 200: {}, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName, Parameters.tableName, Parameters.columnName, Parameters.sensitivityLabelSource2 ], serializer }; const disableRecommendationOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable", httpMethod: "POST", responses: { 200: {}, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName, Parameters.tableName, Parameters.columnName, Parameters.sensitivityLabelSource2 ], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SensitivityLabel }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName, Parameters.tableName, Parameters.columnName, Parameters.sensitivityLabelSource ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.SensitivityLabel }, 201: { bodyMapper: Mappers.SensitivityLabel }, default: {} }, requestBody: Parameters.parameters72, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName, Parameters.tableName, Parameters.columnName, Parameters.sensitivityLabelSource1 ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", httpMethod: "DELETE", responses: { 200: {}, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.schemaName, Parameters.tableName, Parameters.columnName, Parameters.sensitivityLabelSource1 ], serializer }; const listCurrentByDatabaseNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SensitivityLabelListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer }; const listRecommendedByDatabaseNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.SensitivityLabelListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };