221 lines
7.0 KiB
TypeScript
221 lines
7.0 KiB
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, PageSettings } from "@azure/core-paging";
|
|
import { setContinuationToken } from "../pagingHelper";
|
|
import { SubscriptionPolicy } from "../operationsInterfaces";
|
|
import * as coreClient from "@azure/core-client";
|
|
import * as Mappers from "../models/mappers";
|
|
import * as Parameters from "../models/parameters";
|
|
import { SubscriptionClient } from "../subscriptionClient";
|
|
import {
|
|
GetTenantPolicyResponse,
|
|
SubscriptionPolicyListPolicyForTenantNextOptionalParams,
|
|
SubscriptionPolicyListPolicyForTenantOptionalParams,
|
|
SubscriptionPolicyListPolicyForTenantResponse,
|
|
PutTenantPolicyRequestProperties,
|
|
SubscriptionPolicyAddUpdatePolicyForTenantOptionalParams,
|
|
SubscriptionPolicyAddUpdatePolicyForTenantResponse,
|
|
SubscriptionPolicyGetPolicyForTenantOptionalParams,
|
|
SubscriptionPolicyGetPolicyForTenantResponse,
|
|
SubscriptionPolicyListPolicyForTenantNextResponse
|
|
} from "../models";
|
|
|
|
/// <reference lib="esnext.asynciterable" />
|
|
/** Class containing SubscriptionPolicy operations. */
|
|
export class SubscriptionPolicyImpl implements SubscriptionPolicy {
|
|
private readonly client: SubscriptionClient;
|
|
|
|
/**
|
|
* Initialize a new instance of the class SubscriptionPolicy class.
|
|
* @param client Reference to the service client
|
|
*/
|
|
constructor(client: SubscriptionClient) {
|
|
this.client = client;
|
|
}
|
|
|
|
/**
|
|
* Get the subscription tenant policy for the user's tenant.
|
|
* @param options The options parameters.
|
|
*/
|
|
public listPolicyForTenant(
|
|
options?: SubscriptionPolicyListPolicyForTenantOptionalParams
|
|
): PagedAsyncIterableIterator<GetTenantPolicyResponse> {
|
|
const iter = this.listPolicyForTenantPagingAll(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.listPolicyForTenantPagingPage(options, settings);
|
|
}
|
|
};
|
|
}
|
|
|
|
private async *listPolicyForTenantPagingPage(
|
|
options?: SubscriptionPolicyListPolicyForTenantOptionalParams,
|
|
settings?: PageSettings
|
|
): AsyncIterableIterator<GetTenantPolicyResponse[]> {
|
|
let result: SubscriptionPolicyListPolicyForTenantResponse;
|
|
let continuationToken = settings?.continuationToken;
|
|
if (!continuationToken) {
|
|
result = await this._listPolicyForTenant(options);
|
|
let page = result.value || [];
|
|
continuationToken = result.nextLink;
|
|
setContinuationToken(page, continuationToken);
|
|
yield page;
|
|
}
|
|
while (continuationToken) {
|
|
result = await this._listPolicyForTenantNext(continuationToken, options);
|
|
continuationToken = result.nextLink;
|
|
let page = result.value || [];
|
|
setContinuationToken(page, continuationToken);
|
|
yield page;
|
|
}
|
|
}
|
|
|
|
private async *listPolicyForTenantPagingAll(
|
|
options?: SubscriptionPolicyListPolicyForTenantOptionalParams
|
|
): AsyncIterableIterator<GetTenantPolicyResponse> {
|
|
for await (const page of this.listPolicyForTenantPagingPage(options)) {
|
|
yield* page;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create or Update Subscription tenant policy for user's tenant.
|
|
* @param body Put tenant policy request properties.
|
|
* @param options The options parameters.
|
|
*/
|
|
addUpdatePolicyForTenant(
|
|
body: PutTenantPolicyRequestProperties,
|
|
options?: SubscriptionPolicyAddUpdatePolicyForTenantOptionalParams
|
|
): Promise<SubscriptionPolicyAddUpdatePolicyForTenantResponse> {
|
|
return this.client.sendOperationRequest(
|
|
{ body, options },
|
|
addUpdatePolicyForTenantOperationSpec
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the subscription tenant policy for the user's tenant.
|
|
* @param options The options parameters.
|
|
*/
|
|
getPolicyForTenant(
|
|
options?: SubscriptionPolicyGetPolicyForTenantOptionalParams
|
|
): Promise<SubscriptionPolicyGetPolicyForTenantResponse> {
|
|
return this.client.sendOperationRequest(
|
|
{ options },
|
|
getPolicyForTenantOperationSpec
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the subscription tenant policy for the user's tenant.
|
|
* @param options The options parameters.
|
|
*/
|
|
private _listPolicyForTenant(
|
|
options?: SubscriptionPolicyListPolicyForTenantOptionalParams
|
|
): Promise<SubscriptionPolicyListPolicyForTenantResponse> {
|
|
return this.client.sendOperationRequest(
|
|
{ options },
|
|
listPolicyForTenantOperationSpec
|
|
);
|
|
}
|
|
|
|
/**
|
|
* ListPolicyForTenantNext
|
|
* @param nextLink The nextLink from the previous successful call to the ListPolicyForTenant method.
|
|
* @param options The options parameters.
|
|
*/
|
|
private _listPolicyForTenantNext(
|
|
nextLink: string,
|
|
options?: SubscriptionPolicyListPolicyForTenantNextOptionalParams
|
|
): Promise<SubscriptionPolicyListPolicyForTenantNextResponse> {
|
|
return this.client.sendOperationRequest(
|
|
{ nextLink, options },
|
|
listPolicyForTenantNextOperationSpec
|
|
);
|
|
}
|
|
}
|
|
// Operation Specifications
|
|
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
|
|
|
|
const addUpdatePolicyForTenantOperationSpec: coreClient.OperationSpec = {
|
|
path: "/providers/Microsoft.Subscription/policies/default",
|
|
httpMethod: "PUT",
|
|
responses: {
|
|
200: {
|
|
bodyMapper: Mappers.GetTenantPolicyResponse
|
|
},
|
|
default: {
|
|
bodyMapper: Mappers.ErrorResponseBody
|
|
}
|
|
},
|
|
requestBody: Parameters.body3,
|
|
queryParameters: [Parameters.apiVersion1],
|
|
urlParameters: [Parameters.$host],
|
|
headerParameters: [Parameters.accept, Parameters.contentType],
|
|
mediaType: "json",
|
|
serializer
|
|
};
|
|
const getPolicyForTenantOperationSpec: coreClient.OperationSpec = {
|
|
path: "/providers/Microsoft.Subscription/policies/default",
|
|
httpMethod: "GET",
|
|
responses: {
|
|
200: {
|
|
bodyMapper: Mappers.GetTenantPolicyResponse
|
|
},
|
|
default: {
|
|
bodyMapper: Mappers.ErrorResponseBody
|
|
}
|
|
},
|
|
queryParameters: [Parameters.apiVersion1],
|
|
urlParameters: [Parameters.$host],
|
|
headerParameters: [Parameters.accept],
|
|
serializer
|
|
};
|
|
const listPolicyForTenantOperationSpec: coreClient.OperationSpec = {
|
|
path: "/providers/Microsoft.Subscription/policies",
|
|
httpMethod: "GET",
|
|
responses: {
|
|
200: {
|
|
bodyMapper: Mappers.GetTenantPolicyListResponse
|
|
},
|
|
default: {
|
|
bodyMapper: Mappers.ErrorResponseBody
|
|
}
|
|
},
|
|
queryParameters: [Parameters.apiVersion1],
|
|
urlParameters: [Parameters.$host],
|
|
headerParameters: [Parameters.accept],
|
|
serializer
|
|
};
|
|
const listPolicyForTenantNextOperationSpec: coreClient.OperationSpec = {
|
|
path: "{nextLink}",
|
|
httpMethod: "GET",
|
|
responses: {
|
|
200: {
|
|
bodyMapper: Mappers.GetTenantPolicyListResponse
|
|
},
|
|
default: {
|
|
bodyMapper: Mappers.ErrorResponseBody
|
|
}
|
|
},
|
|
queryParameters: [Parameters.apiVersion1],
|
|
urlParameters: [Parameters.$host, Parameters.nextLink],
|
|
headerParameters: [Parameters.accept],
|
|
serializer
|
|
};
|