PermissionsClientImpl.java
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.
package com.azure.resourcemanager.authorization.implementation;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.authorization.fluent.PermissionsClient;
import com.azure.resourcemanager.authorization.fluent.models.PermissionInner;
import com.azure.resourcemanager.authorization.models.PermissionGetResult;
import reactor.core.publisher.Mono;
/** An instance of this class provides access to all the operations defined in PermissionsClient. */
public final class PermissionsClientImpl implements PermissionsClient {
private final ClientLogger logger = new ClientLogger(PermissionsClientImpl.class);
/** The proxy service used to perform REST calls. */
private final PermissionsService service;
/** The service client containing this operation class. */
private final AuthorizationManagementClientImpl client;
/**
* Initializes an instance of PermissionsClientImpl.
*
* @param client the instance of the service client containing this operation class.
*/
PermissionsClientImpl(AuthorizationManagementClientImpl client) {
this.service =
RestProxy.create(PermissionsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
this.client = client;
}
/**
* The interface defining all the services for AuthorizationManagementClientPermissions to be used by the proxy
* service to perform REST calls.
*/
@Host("{$host}")
@ServiceInterface(name = "AuthorizationManagem")
private interface PermissionsService {
@Headers({"Accept: application/json", "Content-Type: application/json"})
@Get(
"/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Authorization"
+ "/permissions")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<PermissionGetResult>> listByResourceGroup(
@HostParam("$host") String endpoint,
@PathParam("resourceGroupName") String resourceGroupName,
@QueryParam("api-version") String apiVersion,
@PathParam("subscriptionId") String subscriptionId,
Context context);
@Headers({"Accept: application/json", "Content-Type: application/json"})
@Get(
"/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}"
+ "/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/permissions")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<PermissionGetResult>> listForResource(
@HostParam("$host") String endpoint,
@PathParam("resourceGroupName") String resourceGroupName,
@PathParam("resourceProviderNamespace") String resourceProviderNamespace,
@PathParam(value = "parentResourcePath", encoded = true) String parentResourcePath,
@PathParam(value = "resourceType", encoded = true) String resourceType,
@PathParam("resourceName") String resourceName,
@QueryParam("api-version") String apiVersion,
@PathParam("subscriptionId") String subscriptionId,
Context context);
@Headers({"Accept: application/json", "Content-Type: application/json"})
@Get("{nextLink}")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<PermissionGetResult>> listForResourceGroupNext(
@PathParam(value = "nextLink", encoded = true) String nextLink, Context context);
@Headers({"Accept: application/json", "Content-Type: application/json"})
@Get("{nextLink}")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<PermissionGetResult>> listForResourceNext(
@PathParam(value = "nextLink", encoded = true) String nextLink, Context context);
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
if (this.client.getEndpoint() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
if (resourceGroupName == null) {
return Mono
.error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
}
if (this.client.getSubscriptionId() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getSubscriptionId() is required and cannot be null."));
}
final String apiVersion = "2018-01-01-preview";
return FluxUtil
.withContext(
context ->
service
.listByResourceGroup(
this.client.getEndpoint(),
resourceGroupName,
apiVersion,
this.client.getSubscriptionId(),
context))
.<PagedResponse<PermissionInner>>map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null))
.subscriberContext(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext())));
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listByResourceGroupSinglePageAsync(
String resourceGroupName, Context context) {
if (this.client.getEndpoint() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
if (resourceGroupName == null) {
return Mono
.error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
}
if (this.client.getSubscriptionId() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getSubscriptionId() is required and cannot be null."));
}
final String apiVersion = "2018-01-01-preview";
context = this.client.mergeContext(context);
return service
.listByResourceGroup(
this.client.getEndpoint(), resourceGroupName, apiVersion, this.client.getSubscriptionId(), context)
.map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null));
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<PermissionInner> listByResourceGroupAsync(String resourceGroupName) {
return new PagedFlux<>(
() -> listByResourceGroupSinglePageAsync(resourceGroupName),
nextLink -> listForResourceGroupNextSinglePageAsync(nextLink));
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
private PagedFlux<PermissionInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
return new PagedFlux<>(
() -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
nextLink -> listForResourceGroupNextSinglePageAsync(nextLink, context));
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<PermissionInner> listByResourceGroup(String resourceGroupName) {
return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
}
/**
* Gets all permissions the caller has for a resource group.
*
* @param resourceGroupName The name of the resource group.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource group.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<PermissionInner> listByResourceGroup(String resourceGroupName, Context context) {
return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceSinglePageAsync(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName) {
if (this.client.getEndpoint() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
if (resourceGroupName == null) {
return Mono
.error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
}
if (resourceProviderNamespace == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter resourceProviderNamespace is required and cannot be null."));
}
if (parentResourcePath == null) {
return Mono
.error(new IllegalArgumentException("Parameter parentResourcePath is required and cannot be null."));
}
if (resourceType == null) {
return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
}
if (resourceName == null) {
return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
}
if (this.client.getSubscriptionId() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getSubscriptionId() is required and cannot be null."));
}
final String apiVersion = "2018-01-01-preview";
return FluxUtil
.withContext(
context ->
service
.listForResource(
this.client.getEndpoint(),
resourceGroupName,
resourceProviderNamespace,
parentResourcePath,
resourceType,
resourceName,
apiVersion,
this.client.getSubscriptionId(),
context))
.<PagedResponse<PermissionInner>>map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null))
.subscriberContext(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext())));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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 context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceSinglePageAsync(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName,
Context context) {
if (this.client.getEndpoint() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
if (resourceGroupName == null) {
return Mono
.error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
}
if (resourceProviderNamespace == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter resourceProviderNamespace is required and cannot be null."));
}
if (parentResourcePath == null) {
return Mono
.error(new IllegalArgumentException("Parameter parentResourcePath is required and cannot be null."));
}
if (resourceType == null) {
return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
}
if (resourceName == null) {
return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
}
if (this.client.getSubscriptionId() == null) {
return Mono
.error(
new IllegalArgumentException(
"Parameter this.client.getSubscriptionId() is required and cannot be null."));
}
final String apiVersion = "2018-01-01-preview";
context = this.client.mergeContext(context);
return service
.listForResource(
this.client.getEndpoint(),
resourceGroupName,
resourceProviderNamespace,
parentResourcePath,
resourceType,
resourceName,
apiVersion,
this.client.getSubscriptionId(),
context)
.map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<PermissionInner> listForResourceAsync(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName) {
return new PagedFlux<>(
() ->
listForResourceSinglePageAsync(
resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName),
nextLink -> listForResourceNextSinglePageAsync(nextLink));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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 context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
private PagedFlux<PermissionInner> listForResourceAsync(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName,
Context context) {
return new PagedFlux<>(
() ->
listForResourceSinglePageAsync(
resourceGroupName,
resourceProviderNamespace,
parentResourcePath,
resourceType,
resourceName,
context),
nextLink -> listForResourceNextSinglePageAsync(nextLink, context));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<PermissionInner> listForResource(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName) {
return new PagedIterable<>(
listForResourceAsync(
resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName));
}
/**
* Gets all permissions the caller has for a resource.
*
* @param resourceGroupName The name of the resource group.
* @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 context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return all permissions the caller has for a resource.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<PermissionInner> listForResource(
String resourceGroupName,
String resourceProviderNamespace,
String parentResourcePath,
String resourceType,
String resourceName,
Context context) {
return new PagedIterable<>(
listForResourceAsync(
resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, context));
}
/**
* Get the next page of items.
*
* @param nextLink The nextLink parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return permissions information.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceGroupNextSinglePageAsync(String nextLink) {
if (nextLink == null) {
return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
return FluxUtil
.withContext(context -> service.listForResourceGroupNext(nextLink, context))
.<PagedResponse<PermissionInner>>map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null))
.subscriberContext(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext())));
}
/**
* Get the next page of items.
*
* @param nextLink The nextLink parameter.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return permissions information.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceGroupNextSinglePageAsync(
String nextLink, Context context) {
if (nextLink == null) {
return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
context = this.client.mergeContext(context);
return service
.listForResourceGroupNext(nextLink, context)
.map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null));
}
/**
* Get the next page of items.
*
* @param nextLink The nextLink parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return permissions information.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceNextSinglePageAsync(String nextLink) {
if (nextLink == null) {
return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
return FluxUtil
.withContext(context -> service.listForResourceNext(nextLink, context))
.<PagedResponse<PermissionInner>>map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null))
.subscriberContext(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext())));
}
/**
* Get the next page of items.
*
* @param nextLink The nextLink parameter.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return permissions information.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<PermissionInner>> listForResourceNextSinglePageAsync(String nextLink, Context context) {
if (nextLink == null) {
return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
context = this.client.mergeContext(context);
return service
.listForResourceNext(nextLink, context)
.map(
res ->
new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().value(),
res.getValue().nextLink(),
null));
}
}