/*
* 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 { DatabaseBlobAuditingPolicies } 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 {
DatabaseBlobAuditingPolicy,
DatabaseBlobAuditingPoliciesListByDatabaseNextOptionalParams,
DatabaseBlobAuditingPoliciesListByDatabaseOptionalParams,
DatabaseBlobAuditingPoliciesListByDatabaseResponse,
DatabaseBlobAuditingPoliciesGetOptionalParams,
DatabaseBlobAuditingPoliciesGetResponse,
DatabaseBlobAuditingPoliciesCreateOrUpdateOptionalParams,
DatabaseBlobAuditingPoliciesCreateOrUpdateResponse,
DatabaseBlobAuditingPoliciesListByDatabaseNextResponse
} from "../models";
///
/** Class containing DatabaseBlobAuditingPolicies operations. */
export class DatabaseBlobAuditingPoliciesImpl
implements DatabaseBlobAuditingPolicies {
private readonly client: SqlManagementClient;
/**
* Initialize a new instance of the class DatabaseBlobAuditingPolicies class.
* @param client Reference to the service client
*/
constructor(client: SqlManagementClient) {
this.client = client;
}
/**
* Lists auditing settings of 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?: DatabaseBlobAuditingPoliciesListByDatabaseOptionalParams
): 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?: DatabaseBlobAuditingPoliciesListByDatabaseOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: DatabaseBlobAuditingPoliciesListByDatabaseResponse;
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?: DatabaseBlobAuditingPoliciesListByDatabaseOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByDatabasePagingPage(
resourceGroupName,
serverName,
databaseName,
options
)) {
yield* page;
}
}
/**
* Lists auditing settings of 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?: DatabaseBlobAuditingPoliciesListByDatabaseOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, serverName, databaseName, options },
listByDatabaseOperationSpec
);
}
/**
* Gets a database's blob auditing policy.
* @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.
*/
get(
resourceGroupName: string,
serverName: string,
databaseName: string,
options?: DatabaseBlobAuditingPoliciesGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, serverName, databaseName, options },
getOperationSpec
);
}
/**
* Creates or updates a database's blob auditing policy.
* @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 The database blob auditing policy.
* @param options The options parameters.
*/
createOrUpdate(
resourceGroupName: string,
serverName: string,
databaseName: string,
parameters: DatabaseBlobAuditingPolicy,
options?: DatabaseBlobAuditingPoliciesCreateOrUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, serverName, databaseName, parameters, options },
createOrUpdateOperationSpec
);
}
/**
* 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?: DatabaseBlobAuditingPoliciesListByDatabaseNextOptionalParams
): Promise {
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}/auditingSettings",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DatabaseBlobAuditingPolicyListResult
},
default: {}
},
queryParameters: [Parameters.apiVersion7],
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}/auditingSettings/{blobAuditingPolicyName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DatabaseBlobAuditingPolicy
},
default: {}
},
queryParameters: [Parameters.apiVersion7],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.serverName,
Parameters.databaseName,
Parameters.blobAuditingPolicyName
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.DatabaseBlobAuditingPolicy
},
201: {
bodyMapper: Mappers.DatabaseBlobAuditingPolicy
},
default: {}
},
requestBody: Parameters.parameters76,
queryParameters: [Parameters.apiVersion7],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.serverName,
Parameters.databaseName,
Parameters.blobAuditingPolicyName
],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer
};
const listByDatabaseNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DatabaseBlobAuditingPolicyListResult
},
default: {}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.serverName,
Parameters.databaseName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};