/*
* 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 { Policies } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { DevTestLabsClient } from "../devTestLabsClient";
import {
Policy,
PoliciesListNextOptionalParams,
PoliciesListOptionalParams,
PoliciesListResponse,
PoliciesGetOptionalParams,
PoliciesGetResponse,
PoliciesCreateOrUpdateOptionalParams,
PoliciesCreateOrUpdateResponse,
PoliciesDeleteOptionalParams,
PolicyFragment,
PoliciesUpdateOptionalParams,
PoliciesUpdateResponse,
PoliciesListNextResponse
} from "../models";
///
/** Class containing Policies operations. */
export class PoliciesImpl implements Policies {
private readonly client: DevTestLabsClient;
/**
* Initialize a new instance of the class Policies class.
* @param client Reference to the service client
*/
constructor(client: DevTestLabsClient) {
this.client = client;
}
/**
* List policies in a given policy set.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param options The options parameters.
*/
public list(
resourceGroupName: string,
labName: string,
policySetName: string,
options?: PoliciesListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(
resourceGroupName,
labName,
policySetName,
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.listPagingPage(
resourceGroupName,
labName,
policySetName,
options,
settings
);
}
};
}
private async *listPagingPage(
resourceGroupName: string,
labName: string,
policySetName: string,
options?: PoliciesListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: PoliciesListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(
resourceGroupName,
labName,
policySetName,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
resourceGroupName,
labName,
policySetName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
resourceGroupName: string,
labName: string,
policySetName: string,
options?: PoliciesListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(
resourceGroupName,
labName,
policySetName,
options
)) {
yield* page;
}
}
/**
* List policies in a given policy set.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param options The options parameters.
*/
private _list(
resourceGroupName: string,
labName: string,
policySetName: string,
options?: PoliciesListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, options },
listOperationSpec
);
}
/**
* Get policy.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param name The name of the policy.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
labName: string,
policySetName: string,
name: string,
options?: PoliciesGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, name, options },
getOperationSpec
);
}
/**
* Create or replace an existing policy.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param name The name of the policy.
* @param policy A Policy.
* @param options The options parameters.
*/
createOrUpdate(
resourceGroupName: string,
labName: string,
policySetName: string,
name: string,
policy: Policy,
options?: PoliciesCreateOrUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, name, policy, options },
createOrUpdateOperationSpec
);
}
/**
* Delete policy.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param name The name of the policy.
* @param options The options parameters.
*/
delete(
resourceGroupName: string,
labName: string,
policySetName: string,
name: string,
options?: PoliciesDeleteOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, name, options },
deleteOperationSpec
);
}
/**
* Allows modifying tags of policies. All other properties will be ignored.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param name The name of the policy.
* @param policy A Policy.
* @param options The options parameters.
*/
update(
resourceGroupName: string,
labName: string,
policySetName: string,
name: string,
policy: PolicyFragment,
options?: PoliciesUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, name, policy, options },
updateOperationSpec
);
}
/**
* ListNext
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param policySetName The name of the policy set.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
resourceGroupName: string,
labName: string,
policySetName: string,
nextLink: string,
options?: PoliciesListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, policySetName, nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.PolicyList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.expand,
Parameters.filter,
Parameters.top,
Parameters.orderby
],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Policy
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion, Parameters.expand],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Policy
},
201: {
bodyMapper: Mappers.Policy
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.policy,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}",
httpMethod: "DELETE",
responses: {
200: {},
204: {},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept],
serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: Mappers.Policy
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.policy1,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.PolicyList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.expand,
Parameters.filter,
Parameters.top,
Parameters.orderby
],
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.labName,
Parameters.policySetName
],
headerParameters: [Parameters.accept],
serializer
};