All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.security.implementation.GovernanceRulesClientImpl Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.security.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
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.Post;
import com.azure.core.annotation.Put;
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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.security.fluent.GovernanceRulesClient;
import com.azure.resourcemanager.security.fluent.models.GovernanceRuleInner;
import com.azure.resourcemanager.security.fluent.models.OperationResultAutoGeneratedInner;
import com.azure.resourcemanager.security.models.ExecuteGovernanceRuleParams;
import com.azure.resourcemanager.security.models.GovernanceRuleList;
import com.azure.resourcemanager.security.models.GovernanceRulesOperationResultsResponse;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * An instance of this class provides access to all the operations defined in GovernanceRulesClient.
 */
public final class GovernanceRulesClientImpl implements GovernanceRulesClient {
    /**
     * The proxy service used to perform REST calls.
     */
    private final GovernanceRulesService service;

    /**
     * The service client containing this operation class.
     */
    private final SecurityCenterImpl client;

    /**
     * Initializes an instance of GovernanceRulesClientImpl.
     * 
     * @param client the instance of the service client containing this operation class.
     */
    GovernanceRulesClientImpl(SecurityCenterImpl client) {
        this.service
            = RestProxy.create(GovernanceRulesService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for SecurityCenterGovernanceRules to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "SecurityCenterGovern")
    public interface GovernanceRulesService {
        @Headers({ "Content-Type: application/json" })
        @Get("/{scope}/providers/Microsoft.Security/governanceRules")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono> list(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Content-Type: application/json" })
        @Get("/{scope}/providers/Microsoft.Security/governanceRules/{ruleId}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono> get(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @PathParam("ruleId") String ruleId, @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Content-Type: application/json" })
        @Put("/{scope}/providers/Microsoft.Security/governanceRules/{ruleId}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono> createOrUpdate(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @PathParam("ruleId") String ruleId, @BodyParam("application/json") GovernanceRuleInner governanceRule,
            @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" })
        @Delete("/{scope}/providers/Microsoft.Security/governanceRules/{ruleId}")
        @ExpectedResponses({ 200, 202, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono>> delete(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @PathParam("ruleId") String ruleId, Context context);

        @Headers({ "Content-Type: application/json" })
        @Post("/{scope}/providers/Microsoft.Security/governanceRules/{ruleId}/execute")
        @ExpectedResponses({ 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono>> execute(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @PathParam("ruleId") String ruleId,
            @BodyParam("application/json") ExecuteGovernanceRuleParams executeGovernanceRuleParams,
            @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Content-Type: application/json" })
        @Get("/{scope}/providers/Microsoft.Security/governanceRules/{ruleId}/operationResults/{operationId}")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono operationResults(@HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("scope") String scope,
            @PathParam("ruleId") String ruleId, @PathParam("operationId") String operationId,
            @HeaderParam("Accept") String accept, Context context);

        @Headers({ "Content-Type: application/json" })
        @Get("{nextLink}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono> listNext(@PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint, @HeaderParam("Accept") String accept, Context context);
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> listSinglePageAsync(String scope) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.list(this.client.getEndpoint(), apiVersion, scope, accept, context))
            .>map(res -> new PagedResponseBase<>(res.getRequest(),
                res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> listSinglePageAsync(String scope, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.list(this.client.getEndpoint(), apiVersion, scope, accept, context)
            .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
                res.getValue().value(), res.getValue().nextLink(), null));
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux listAsync(String scope) {
        return new PagedFlux<>(() -> listSinglePageAsync(scope), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux listAsync(String scope, Context context) {
        return new PagedFlux<>(() -> listSinglePageAsync(scope, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable list(String scope) {
        return new PagedIterable<>(listAsync(scope));
    }

    /**
     * Get a list of all relevant governance rules over a scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @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 a list of all relevant governance rules over a scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable list(String scope, Context context) {
        return new PagedIterable<>(listAsync(scope, context));
    }

    /**
     * Get a specific governance rule for the requested scope by ruleId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 a specific governance rule for the requested scope by ruleId along with {@link Response} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> getWithResponseAsync(String scope, String ruleId) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.get(this.client.getEndpoint(), apiVersion, scope, ruleId, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a specific governance rule for the requested scope by ruleId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 a specific governance rule for the requested scope by ruleId along with {@link Response} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> getWithResponseAsync(String scope, String ruleId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.get(this.client.getEndpoint(), apiVersion, scope, ruleId, accept, context);
    }

    /**
     * Get a specific governance rule for the requested scope by ruleId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 a specific governance rule for the requested scope by ruleId on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono getAsync(String scope, String ruleId) {
        return getWithResponseAsync(scope, ruleId).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get a specific governance rule for the requested scope by ruleId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 a specific governance rule for the requested scope by ruleId along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response getWithResponse(String scope, String ruleId, Context context) {
        return getWithResponseAsync(scope, ruleId, context).block();
    }

    /**
     * Get a specific governance rule for the requested scope by ruleId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 a specific governance rule for the requested scope by ruleId.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GovernanceRuleInner get(String scope, String ruleId) {
        return getWithResponse(scope, ruleId, Context.NONE).getValue();
    }

    /**
     * Creates or updates a governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param governanceRule Governance rule over a given scope.
     * @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 governance rule over a given scope along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> createOrUpdateWithResponseAsync(String scope, String ruleId,
        GovernanceRuleInner governanceRule) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (governanceRule == null) {
            return Mono.error(new IllegalArgumentException("Parameter governanceRule is required and cannot be null."));
        } else {
            governanceRule.validate();
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, scope, ruleId,
                governanceRule, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param governanceRule Governance rule over a given scope.
     * @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 governance rule over a given scope along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> createOrUpdateWithResponseAsync(String scope, String ruleId,
        GovernanceRuleInner governanceRule, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (governanceRule == null) {
            return Mono.error(new IllegalArgumentException("Parameter governanceRule is required and cannot be null."));
        } else {
            governanceRule.validate();
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.createOrUpdate(this.client.getEndpoint(), apiVersion, scope, ruleId, governanceRule, accept,
            context);
    }

    /**
     * Creates or updates a governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param governanceRule Governance rule over a given scope.
     * @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 governance rule over a given scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono createOrUpdateAsync(String scope, String ruleId,
        GovernanceRuleInner governanceRule) {
        return createOrUpdateWithResponseAsync(scope, ruleId, governanceRule)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param governanceRule Governance rule over a given scope.
     * @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 governance rule over a given scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response createOrUpdateWithResponse(String scope, String ruleId,
        GovernanceRuleInner governanceRule, Context context) {
        return createOrUpdateWithResponseAsync(scope, ruleId, governanceRule, context).block();
    }

    /**
     * Creates or updates a governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param governanceRule Governance rule over a given scope.
     * @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 governance rule over a given scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GovernanceRuleInner createOrUpdate(String scope, String ruleId, GovernanceRuleInner governanceRule) {
        return createOrUpdateWithResponse(scope, ruleId, governanceRule, Context.NONE).getValue();
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono>> deleteWithResponseAsync(String scope, String ruleId) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        return FluxUtil
            .withContext(context -> service.delete(this.client.getEndpoint(), apiVersion, scope, ruleId, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono>> deleteWithResponseAsync(String scope, String ruleId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        context = this.client.mergeContext(context);
        return service.delete(this.client.getEndpoint(), apiVersion, scope, ruleId, context);
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux, Void> beginDeleteAsync(String scope, String ruleId) {
        Mono>> mono = deleteWithResponseAsync(scope, ruleId);
        return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class,
            this.client.getContext());
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux, Void> beginDeleteAsync(String scope, String ruleId, Context context) {
        context = this.client.mergeContext(context);
        Mono>> mono = deleteWithResponseAsync(scope, ruleId, context);
        return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class,
            context);
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller, Void> beginDelete(String scope, String ruleId) {
        return this.beginDeleteAsync(scope, ruleId).getSyncPoller();
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller, Void> beginDelete(String scope, String ruleId, Context context) {
        return this.beginDeleteAsync(scope, ruleId, context).getSyncPoller();
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono deleteAsync(String scope, String ruleId) {
        return beginDeleteAsync(scope, ruleId).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono deleteAsync(String scope, String ruleId, Context context) {
        return beginDeleteAsync(scope, ruleId, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String scope, String ruleId) {
        deleteAsync(scope, ruleId).block();
    }

    /**
     * Delete a Governance rule over a given scope.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String scope, String ruleId, Context context) {
        deleteAsync(scope, ruleId, context).block();
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono>> executeWithResponseAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (executeGovernanceRuleParams != null) {
            executeGovernanceRuleParams.validate();
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.execute(this.client.getEndpoint(), apiVersion, scope, ruleId,
                executeGovernanceRuleParams, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono>> executeWithResponseAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (executeGovernanceRuleParams != null) {
            executeGovernanceRuleParams.validate();
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.execute(this.client.getEndpoint(), apiVersion, scope, ruleId, executeGovernanceRuleParams,
            accept, context);
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux, Void> beginExecuteAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams) {
        Mono>> mono = executeWithResponseAsync(scope, ruleId, executeGovernanceRuleParams);
        return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class,
            this.client.getContext());
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux, Void> beginExecuteAsync(String scope, String ruleId) {
        final ExecuteGovernanceRuleParams executeGovernanceRuleParams = null;
        Mono>> mono = executeWithResponseAsync(scope, ruleId, executeGovernanceRuleParams);
        return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class,
            this.client.getContext());
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux, Void> beginExecuteAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams, Context context) {
        context = this.client.mergeContext(context);
        Mono>> mono
            = executeWithResponseAsync(scope, ruleId, executeGovernanceRuleParams, context);
        return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class,
            context);
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller, Void> beginExecute(String scope, String ruleId) {
        final ExecuteGovernanceRuleParams executeGovernanceRuleParams = null;
        return this.beginExecuteAsync(scope, ruleId, executeGovernanceRuleParams).getSyncPoller();
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller, Void> beginExecute(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams, Context context) {
        return this.beginExecuteAsync(scope, ruleId, executeGovernanceRuleParams, context).getSyncPoller();
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono executeAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams) {
        return beginExecuteAsync(scope, ruleId, executeGovernanceRuleParams).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono executeAsync(String scope, String ruleId) {
        final ExecuteGovernanceRuleParams executeGovernanceRuleParams = null;
        return beginExecuteAsync(scope, ruleId, executeGovernanceRuleParams).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono executeAsync(String scope, String ruleId,
        ExecuteGovernanceRuleParams executeGovernanceRuleParams, Context context) {
        return beginExecuteAsync(scope, ruleId, executeGovernanceRuleParams, context).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void execute(String scope, String ruleId) {
        final ExecuteGovernanceRuleParams executeGovernanceRuleParams = null;
        executeAsync(scope, ruleId, executeGovernanceRuleParams).block();
    }

    /**
     * Execute a governance rule.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param executeGovernanceRuleParams Execute governance rule over a given scope.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void execute(String scope, String ruleId, ExecuteGovernanceRuleParams executeGovernanceRuleParams,
        Context context) {
        executeAsync(scope, ruleId, executeGovernanceRuleParams, context).block();
    }

    /**
     * Get governance rules long run operation result for the requested scope by ruleId and operationId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param operationId The governance rule long running operation unique key.
     * @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 governance rules long run operation result for the requested scope by ruleId and operationId on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono operationResultsWithResponseAsync(String scope, String ruleId,
        String operationId) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (operationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter operationId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.operationResults(this.client.getEndpoint(), apiVersion, scope, ruleId,
                operationId, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get governance rules long run operation result for the requested scope by ruleId and operationId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param operationId The governance rule long running operation unique key.
     * @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 governance rules long run operation result for the requested scope by ruleId and operationId on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono operationResultsWithResponseAsync(String scope, String ruleId,
        String operationId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (ruleId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
        }
        if (operationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter operationId is required and cannot be null."));
        }
        final String apiVersion = "2022-01-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.operationResults(this.client.getEndpoint(), apiVersion, scope, ruleId, operationId, accept,
            context);
    }

    /**
     * Get governance rules long run operation result for the requested scope by ruleId and operationId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param operationId The governance rule long running operation unique key.
     * @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 governance rules long run operation result for the requested scope by ruleId and operationId on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono operationResultsAsync(String scope, String ruleId,
        String operationId) {
        return operationResultsWithResponseAsync(scope, ruleId, operationId)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get governance rules long run operation result for the requested scope by ruleId and operationId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param operationId The governance rule long running operation unique key.
     * @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 governance rules long run operation result for the requested scope by ruleId and operationId.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GovernanceRulesOperationResultsResponse operationResultsWithResponse(String scope, String ruleId,
        String operationId, Context context) {
        return operationResultsWithResponseAsync(scope, ruleId, operationId, context).block();
    }

    /**
     * Get governance rules long run operation result for the requested scope by ruleId and operationId.
     * 
     * @param scope The scope of the Governance rules. Valid scopes are: management group (format:
     * 'providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
     * 'subscriptions/{subscriptionId}'), or security connector (format:
     * 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/securityConnectors/{securityConnectorName})'.
     * @param ruleId The governance rule key - unique key for the standard governance rule (GUID).
     * @param operationId The governance rule long running operation unique key.
     * @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 governance rules long run operation result for the requested scope by ruleId and operationId.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public OperationResultAutoGeneratedInner operationResults(String scope, String ruleId, String operationId) {
        return operationResultsWithResponse(scope, ruleId, operationId, Context.NONE).getValue();
    }

    /**
     * Get the next page of items.
     * 
     * @param nextLink The URL to get the next list of items.
     * @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 page of a governance rules list along with {@link PagedResponse} on successful completion of
     * {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .>map(res -> new PagedResponseBase<>(res.getRequest(),
                res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     * 
     * @param nextLink The URL to get the next list of items.
     * @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 page of a governance rules list along with {@link PagedResponse} on successful completion of
     * {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
                res.getValue().value(), res.getValue().nextLink(), null));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy