@azure/arm-security
Version:
A generated SDK for SecurityCenter.
223 lines (211 loc) • 6.01 kB
text/typescript
/*
* 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 { Settings } 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 {
SettingUnion,
SettingsListNextOptionalParams,
SettingsListOptionalParams,
SettingsListResponse,
SettingName,
SettingsGetOptionalParams,
SettingsGetResponse,
SettingsUpdateOptionalParams,
SettingsUpdateResponse,
SettingsListNextResponse
} from "../models";
/// <reference lib="esnext.asynciterable" />
/** Class containing Settings operations. */
export class SettingsImpl implements Settings {
private readonly client: SecurityCenter;
/**
* Initialize a new instance of the class Settings class.
* @param client Reference to the service client
*/
constructor(client: SecurityCenter) {
this.client = client;
}
/**
* Settings about different configurations in security center
* @param options The options parameters.
*/
public list(
options?: SettingsListOptionalParams
): PagedAsyncIterableIterator<SettingUnion> {
const iter = this.listPagingAll(options);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage: () => {
return this.listPagingPage(options);
}
};
}
private async *listPagingPage(
options?: SettingsListOptionalParams
): AsyncIterableIterator<SettingUnion[]> {
let result = await this._list(options);
yield result.value || [];
let continuationToken = result.nextLink;
while (continuationToken) {
result = await this._listNext(continuationToken, options);
continuationToken = result.nextLink;
yield result.value || [];
}
}
private async *listPagingAll(
options?: SettingsListOptionalParams
): AsyncIterableIterator<SettingUnion> {
for await (const page of this.listPagingPage(options)) {
yield* page;
}
}
/**
* Settings about different configurations in security center
* @param options The options parameters.
*/
private _list(
options?: SettingsListOptionalParams
): Promise<SettingsListResponse> {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* Settings of different configurations in security center
* @param settingName The name of the setting
* @param options The options parameters.
*/
get(
settingName: SettingName,
options?: SettingsGetOptionalParams
): Promise<SettingsGetResponse> {
return this.client.sendOperationRequest(
{ settingName, options },
getOperationSpec
);
}
/**
* updating settings about different configurations in security center
* @param settingName The name of the setting
* @param setting Setting object
* @param options The options parameters.
*/
update(
settingName: SettingName,
setting: SettingUnion,
options?: SettingsUpdateOptionalParams
): Promise<SettingsUpdateResponse> {
return this.client.sendOperationRequest(
{ settingName, setting, options },
updateOperationSpec
);
}
/**
* ListNext
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
nextLink: string,
options?: SettingsListNextOptionalParams
): Promise<SettingsListNextResponse> {
return this.client.sendOperationRequest(
{ nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path: "/subscriptions/{subscriptionId}/providers/Microsoft.Security/settings",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.SettingsList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion14],
urlParameters: [Parameters.$host, Parameters.subscriptionId],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Security/settings/{settingName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Setting
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion14],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.settingName2
],
headerParameters: [Parameters.accept],
serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Security/settings/{settingName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Setting
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.setting1,
queryParameters: [Parameters.apiVersion14],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.settingName2
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.SettingsList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion14],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};