/* * 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 { Permissions } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { AuthorizationManagementClient } from "../authorizationManagementClient"; import { Permission, PermissionsListForResourceGroupNextOptionalParams, PermissionsListForResourceGroupOptionalParams, PermissionsListForResourceGroupResponse, PermissionsListForResourceNextOptionalParams, PermissionsListForResourceOptionalParams, PermissionsListForResourceResponse, PermissionsListForResourceGroupNextResponse, PermissionsListForResourceNextResponse } from "../models"; /// /** Class containing Permissions operations. */ export class PermissionsImpl implements Permissions { private readonly client: AuthorizationManagementClient; /** * Initialize a new instance of the class Permissions class. * @param client Reference to the service client */ constructor(client: AuthorizationManagementClient) { this.client = client; } /** * Gets all permissions the caller has for a resource group. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param options The options parameters. */ public listForResourceGroup( resourceGroupName: string, options?: PermissionsListForResourceGroupOptionalParams ): PagedAsyncIterableIterator { const iter = this.listForResourceGroupPagingAll(resourceGroupName, 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.listForResourceGroupPagingPage( resourceGroupName, options, settings ); } }; } private async *listForResourceGroupPagingPage( resourceGroupName: string, options?: PermissionsListForResourceGroupOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: PermissionsListForResourceGroupResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listForResourceGroup(resourceGroupName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listForResourceGroupNext( resourceGroupName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listForResourceGroupPagingAll( resourceGroupName: string, options?: PermissionsListForResourceGroupOptionalParams ): AsyncIterableIterator { for await (const page of this.listForResourceGroupPagingPage( resourceGroupName, options )) { yield* page; } } /** * Gets all permissions the caller has for a resource. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param resourceProviderNamespace The namespace of the resource provider. * @param parentResourcePath The parent resource identity. * @param resourceType The resource type of the resource. * @param resourceName The name of the resource to get the permissions for. * @param options The options parameters. */ public listForResource( resourceGroupName: string, resourceProviderNamespace: string, parentResourcePath: string, resourceType: string, resourceName: string, options?: PermissionsListForResourceOptionalParams ): PagedAsyncIterableIterator { const iter = this.listForResourcePagingAll( resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, 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.listForResourcePagingPage( resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options, settings ); } }; } private async *listForResourcePagingPage( resourceGroupName: string, resourceProviderNamespace: string, parentResourcePath: string, resourceType: string, resourceName: string, options?: PermissionsListForResourceOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: PermissionsListForResourceResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listForResource( resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listForResourceNext( resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listForResourcePagingAll( resourceGroupName: string, resourceProviderNamespace: string, parentResourcePath: string, resourceType: string, resourceName: string, options?: PermissionsListForResourceOptionalParams ): AsyncIterableIterator { for await (const page of this.listForResourcePagingPage( resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options )) { yield* page; } } /** * Gets all permissions the caller has for a resource group. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param options The options parameters. */ private _listForResourceGroup( resourceGroupName: string, options?: PermissionsListForResourceGroupOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, options }, listForResourceGroupOperationSpec ); } /** * Gets all permissions the caller has for a resource. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param resourceProviderNamespace The namespace of the resource provider. * @param parentResourcePath The parent resource identity. * @param resourceType The resource type of the resource. * @param resourceName The name of the resource to get the permissions for. * @param options The options parameters. */ private _listForResource( resourceGroupName: string, resourceProviderNamespace: string, parentResourcePath: string, resourceType: string, resourceName: string, options?: PermissionsListForResourceOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options }, listForResourceOperationSpec ); } /** * ListForResourceGroupNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param nextLink The nextLink from the previous successful call to the ListForResourceGroup method. * @param options The options parameters. */ private _listForResourceGroupNext( resourceGroupName: string, nextLink: string, options?: PermissionsListForResourceGroupNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, nextLink, options }, listForResourceGroupNextOperationSpec ); } /** * ListForResourceNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param resourceProviderNamespace The namespace of the resource provider. * @param parentResourcePath The parent resource identity. * @param resourceType The resource type of the resource. * @param resourceName The name of the resource to get the permissions for. * @param nextLink The nextLink from the previous successful call to the ListForResource method. * @param options The options parameters. */ private _listForResourceNext( resourceGroupName: string, resourceProviderNamespace: string, parentResourcePath: string, resourceType: string, resourceName: string, nextLink: string, options?: PermissionsListForResourceNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, nextLink, options }, listForResourceNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listForResourceGroupOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Authorization/permissions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PermissionGetResult }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName ], headerParameters: [Parameters.accept], serializer }; const listForResourceOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/permissions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PermissionGetResult }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.resourceProviderNamespace, Parameters.parentResourcePath, Parameters.resourceType, Parameters.resourceName ], headerParameters: [Parameters.accept], serializer }; const listForResourceGroupNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PermissionGetResult }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink, Parameters.resourceGroupName ], headerParameters: [Parameters.accept], serializer }; const listForResourceNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PermissionGetResult }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink, Parameters.resourceGroupName, Parameters.resourceProviderNamespace, Parameters.parentResourcePath, Parameters.resourceType, Parameters.resourceName ], headerParameters: [Parameters.accept], serializer };