@azure/arm-security
Version:
A generated SDK for SecurityCenter.
195 lines (184 loc) • 5.96 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 { ComplianceResults } 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 {
ComplianceResult,
ComplianceResultsListNextOptionalParams,
ComplianceResultsListOptionalParams,
ComplianceResultsListResponse,
ComplianceResultsGetOptionalParams,
ComplianceResultsGetResponse,
ComplianceResultsListNextResponse
} from "../models";
/// <reference lib="esnext.asynciterable" />
/** Class containing ComplianceResults operations. */
export class ComplianceResultsImpl implements ComplianceResults {
private readonly client: SecurityCenter;
/**
* Initialize a new instance of the class ComplianceResults class.
* @param client Reference to the service client
*/
constructor(client: SecurityCenter) {
this.client = client;
}
/**
* Security compliance results in the subscription
* @param scope Scope of the query, can be subscription
* (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group
* (/providers/Microsoft.Management/managementGroups/mgName).
* @param options The options parameters.
*/
public list(
scope: string,
options?: ComplianceResultsListOptionalParams
): PagedAsyncIterableIterator<ComplianceResult> {
const iter = this.listPagingAll(scope, options);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage: () => {
return this.listPagingPage(scope, options);
}
};
}
private async *listPagingPage(
scope: string,
options?: ComplianceResultsListOptionalParams
): AsyncIterableIterator<ComplianceResult[]> {
let result = await this._list(scope, options);
yield result.value || [];
let continuationToken = result.nextLink;
while (continuationToken) {
result = await this._listNext(scope, continuationToken, options);
continuationToken = result.nextLink;
yield result.value || [];
}
}
private async *listPagingAll(
scope: string,
options?: ComplianceResultsListOptionalParams
): AsyncIterableIterator<ComplianceResult> {
for await (const page of this.listPagingPage(scope, options)) {
yield* page;
}
}
/**
* Security compliance results in the subscription
* @param scope Scope of the query, can be subscription
* (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group
* (/providers/Microsoft.Management/managementGroups/mgName).
* @param options The options parameters.
*/
private _list(
scope: string,
options?: ComplianceResultsListOptionalParams
): Promise<ComplianceResultsListResponse> {
return this.client.sendOperationRequest(
{ scope, options },
listOperationSpec
);
}
/**
* Security Compliance Result
* @param resourceId The identifier of the resource.
* @param complianceResultName name of the desired assessment compliance result
* @param options The options parameters.
*/
get(
resourceId: string,
complianceResultName: string,
options?: ComplianceResultsGetOptionalParams
): Promise<ComplianceResultsGetResponse> {
return this.client.sendOperationRequest(
{ resourceId, complianceResultName, options },
getOperationSpec
);
}
/**
* ListNext
* @param scope Scope of the query, can be subscription
* (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or management group
* (/providers/Microsoft.Management/managementGroups/mgName).
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
scope: string,
nextLink: string,
options?: ComplianceResultsListNextOptionalParams
): Promise<ComplianceResultsListNextResponse> {
return this.client.sendOperationRequest(
{ scope, nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path: "/{scope}/providers/Microsoft.Security/complianceResults",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ComplianceResultList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion2],
urlParameters: [Parameters.$host, Parameters.scope],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/{resourceId}/providers/Microsoft.Security/complianceResults/{complianceResultName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ComplianceResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion2],
urlParameters: [
Parameters.$host,
Parameters.resourceId,
Parameters.complianceResultName
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ComplianceResultList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion2],
urlParameters: [Parameters.$host, Parameters.nextLink, Parameters.scope],
headerParameters: [Parameters.accept],
serializer
};