/*
* 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 { Budgets } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { ConsumptionManagementClient } from "../consumptionManagementClient";
import {
Budget,
BudgetsListNextOptionalParams,
BudgetsListOptionalParams,
BudgetsListResponse,
BudgetsGetOptionalParams,
BudgetsGetResponse,
BudgetsCreateOrUpdateOptionalParams,
BudgetsCreateOrUpdateResponse,
BudgetsDeleteOptionalParams,
BudgetsListNextResponse
} from "../models";
///
/** Class containing Budgets operations. */
export class BudgetsImpl implements Budgets {
private readonly client: ConsumptionManagementClient;
/**
* Initialize a new instance of the class Budgets class.
* @param client Reference to the service client
*/
constructor(client: ConsumptionManagementClient) {
this.client = client;
}
/**
* Lists all budgets for the defined scope.
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @param options The options parameters.
*/
public list(
scope: string,
options?: BudgetsListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(scope, 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(scope, options, settings);
}
};
}
private async *listPagingPage(
scope: string,
options?: BudgetsListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: BudgetsListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(scope, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(scope, continuationToken, options);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
scope: string,
options?: BudgetsListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(scope, options)) {
yield* page;
}
}
/**
* Lists all budgets for the defined scope.
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @param options The options parameters.
*/
private _list(
scope: string,
options?: BudgetsListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, options },
listOperationSpec
);
}
/**
* Gets the budget for the scope by budget name.
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @param budgetName Budget Name.
* @param options The options parameters.
*/
get(
scope: string,
budgetName: string,
options?: BudgetsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, budgetName, options },
getOperationSpec
);
}
/**
* The operation to create or update a budget. You can optionally provide an eTag if desired as a form
* of concurrency control. To obtain the latest eTag for a given budget, perform a get operation prior
* to your put operation.
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @param budgetName Budget Name.
* @param parameters Parameters supplied to the Create Budget operation.
* @param options The options parameters.
*/
createOrUpdate(
scope: string,
budgetName: string,
parameters: Budget,
options?: BudgetsCreateOrUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, budgetName, parameters, options },
createOrUpdateOperationSpec
);
}
/**
* The operation to delete a budget.
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @param budgetName Budget Name.
* @param options The options parameters.
*/
delete(
scope: string,
budgetName: string,
options?: BudgetsDeleteOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, budgetName, options },
deleteOperationSpec
);
}
/**
* ListNext
* @param scope The scope associated with budget operations. This includes
* '/subscriptions/{subscriptionId}/' for subscription scope,
* '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for
* Department scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}'
* for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId}'
* for Management Group scope,
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for billingProfile scope,
* 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}'
* for invoiceSection scope.
* @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?: BudgetsListNextOptionalParams
): Promise {
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.Consumption/budgets",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.BudgetsListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.scope],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path: "/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Budget
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.scope, Parameters.budgetName],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path: "/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Budget
},
201: {
bodyMapper: Mappers.Budget
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.scope, Parameters.budgetName],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path: "/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}",
httpMethod: "DELETE",
responses: {
200: {},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.scope, Parameters.budgetName],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.BudgetsListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [Parameters.$host, Parameters.scope, Parameters.nextLink],
headerParameters: [Parameters.accept],
serializer
};