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

com.azure.resourcemanager.security.implementation.SecurityCenterImpl 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.ServiceClient;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.rest.Response;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.exception.ManagementError;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.management.polling.PollerFactory;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.polling.AsyncPollResponse;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.serializer.SerializerAdapter;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.security.fluent.AdvancedThreatProtectionsClient;
import com.azure.resourcemanager.security.fluent.AlertsClient;
import com.azure.resourcemanager.security.fluent.AllowedConnectionsClient;
import com.azure.resourcemanager.security.fluent.ApiCollectionsClient;
import com.azure.resourcemanager.security.fluent.AssessmentsClient;
import com.azure.resourcemanager.security.fluent.AssessmentsMetadatasClient;
import com.azure.resourcemanager.security.fluent.ComplianceResultsClient;
import com.azure.resourcemanager.security.fluent.CustomRecommendationsClient;
import com.azure.resourcemanager.security.fluent.DeviceSecurityGroupsClient;
import com.azure.resourcemanager.security.fluent.DiscoveredSecuritySolutionsClient;
import com.azure.resourcemanager.security.fluent.ExternalSecuritySolutionsClient;
import com.azure.resourcemanager.security.fluent.IotSecuritySolutionAnalyticsClient;
import com.azure.resourcemanager.security.fluent.IotSecuritySolutionsAnalyticsAggregatedAlertsClient;
import com.azure.resourcemanager.security.fluent.IotSecuritySolutionsAnalyticsRecommendationsClient;
import com.azure.resourcemanager.security.fluent.IotSecuritySolutionsClient;
import com.azure.resourcemanager.security.fluent.JitNetworkAccessPoliciesClient;
import com.azure.resourcemanager.security.fluent.PricingsClient;
import com.azure.resourcemanager.security.fluent.SecureScoreControlDefinitionsClient;
import com.azure.resourcemanager.security.fluent.SecureScoreControlsClient;
import com.azure.resourcemanager.security.fluent.SecureScoresClient;
import com.azure.resourcemanager.security.fluent.SecurityCenter;
import com.azure.resourcemanager.security.fluent.SecuritySolutionsClient;
import com.azure.resourcemanager.security.fluent.SecuritySolutionsReferenceDatasClient;
import com.azure.resourcemanager.security.fluent.SecurityStandardsClient;
import com.azure.resourcemanager.security.fluent.ServerVulnerabilityAssessmentsClient;
import com.azure.resourcemanager.security.fluent.ServerVulnerabilityAssessmentsSettingsClient;
import com.azure.resourcemanager.security.fluent.SettingsClient;
import com.azure.resourcemanager.security.fluent.StandardAssignmentsClient;
import com.azure.resourcemanager.security.fluent.TopologiesClient;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * Initializes a new instance of the SecurityCenterImpl type.
 */
@ServiceClient(builder = SecurityCenterBuilder.class)
public final class SecurityCenterImpl implements SecurityCenter {
    /**
     * Azure subscription ID.
     */
    private final String subscriptionId;

    /**
     * Gets Azure subscription ID.
     * 
     * @return the subscriptionId value.
     */
    public String getSubscriptionId() {
        return this.subscriptionId;
    }

    /**
     * server parameter.
     */
    private final String endpoint;

    /**
     * Gets server parameter.
     * 
     * @return the endpoint value.
     */
    public String getEndpoint() {
        return this.endpoint;
    }

    /**
     * The HTTP pipeline to send requests through.
     */
    private final HttpPipeline httpPipeline;

    /**
     * Gets The HTTP pipeline to send requests through.
     * 
     * @return the httpPipeline value.
     */
    public HttpPipeline getHttpPipeline() {
        return this.httpPipeline;
    }

    /**
     * The serializer to serialize an object into a string.
     */
    private final SerializerAdapter serializerAdapter;

    /**
     * Gets The serializer to serialize an object into a string.
     * 
     * @return the serializerAdapter value.
     */
    SerializerAdapter getSerializerAdapter() {
        return this.serializerAdapter;
    }

    /**
     * The default poll interval for long-running operation.
     */
    private final Duration defaultPollInterval;

    /**
     * Gets The default poll interval for long-running operation.
     * 
     * @return the defaultPollInterval value.
     */
    public Duration getDefaultPollInterval() {
        return this.defaultPollInterval;
    }

    /**
     * The ComplianceResultsClient object to access its operations.
     */
    private final ComplianceResultsClient complianceResults;

    /**
     * Gets the ComplianceResultsClient object to access its operations.
     * 
     * @return the ComplianceResultsClient object.
     */
    public ComplianceResultsClient getComplianceResults() {
        return this.complianceResults;
    }

    /**
     * The AdvancedThreatProtectionsClient object to access its operations.
     */
    private final AdvancedThreatProtectionsClient advancedThreatProtections;

    /**
     * Gets the AdvancedThreatProtectionsClient object to access its operations.
     * 
     * @return the AdvancedThreatProtectionsClient object.
     */
    public AdvancedThreatProtectionsClient getAdvancedThreatProtections() {
        return this.advancedThreatProtections;
    }

    /**
     * The DeviceSecurityGroupsClient object to access its operations.
     */
    private final DeviceSecurityGroupsClient deviceSecurityGroups;

    /**
     * Gets the DeviceSecurityGroupsClient object to access its operations.
     * 
     * @return the DeviceSecurityGroupsClient object.
     */
    public DeviceSecurityGroupsClient getDeviceSecurityGroups() {
        return this.deviceSecurityGroups;
    }

    /**
     * The IotSecuritySolutionAnalyticsClient object to access its operations.
     */
    private final IotSecuritySolutionAnalyticsClient iotSecuritySolutionAnalytics;

    /**
     * Gets the IotSecuritySolutionAnalyticsClient object to access its operations.
     * 
     * @return the IotSecuritySolutionAnalyticsClient object.
     */
    public IotSecuritySolutionAnalyticsClient getIotSecuritySolutionAnalytics() {
        return this.iotSecuritySolutionAnalytics;
    }

    /**
     * The IotSecuritySolutionsAnalyticsAggregatedAlertsClient object to access its operations.
     */
    private final IotSecuritySolutionsAnalyticsAggregatedAlertsClient iotSecuritySolutionsAnalyticsAggregatedAlerts;

    /**
     * Gets the IotSecuritySolutionsAnalyticsAggregatedAlertsClient object to access its operations.
     * 
     * @return the IotSecuritySolutionsAnalyticsAggregatedAlertsClient object.
     */
    public IotSecuritySolutionsAnalyticsAggregatedAlertsClient getIotSecuritySolutionsAnalyticsAggregatedAlerts() {
        return this.iotSecuritySolutionsAnalyticsAggregatedAlerts;
    }

    /**
     * The IotSecuritySolutionsAnalyticsRecommendationsClient object to access its operations.
     */
    private final IotSecuritySolutionsAnalyticsRecommendationsClient iotSecuritySolutionsAnalyticsRecommendations;

    /**
     * Gets the IotSecuritySolutionsAnalyticsRecommendationsClient object to access its operations.
     * 
     * @return the IotSecuritySolutionsAnalyticsRecommendationsClient object.
     */
    public IotSecuritySolutionsAnalyticsRecommendationsClient getIotSecuritySolutionsAnalyticsRecommendations() {
        return this.iotSecuritySolutionsAnalyticsRecommendations;
    }

    /**
     * The IotSecuritySolutionsClient object to access its operations.
     */
    private final IotSecuritySolutionsClient iotSecuritySolutions;

    /**
     * Gets the IotSecuritySolutionsClient object to access its operations.
     * 
     * @return the IotSecuritySolutionsClient object.
     */
    public IotSecuritySolutionsClient getIotSecuritySolutions() {
        return this.iotSecuritySolutions;
    }

    /**
     * The AllowedConnectionsClient object to access its operations.
     */
    private final AllowedConnectionsClient allowedConnections;

    /**
     * Gets the AllowedConnectionsClient object to access its operations.
     * 
     * @return the AllowedConnectionsClient object.
     */
    public AllowedConnectionsClient getAllowedConnections() {
        return this.allowedConnections;
    }

    /**
     * The DiscoveredSecuritySolutionsClient object to access its operations.
     */
    private final DiscoveredSecuritySolutionsClient discoveredSecuritySolutions;

    /**
     * Gets the DiscoveredSecuritySolutionsClient object to access its operations.
     * 
     * @return the DiscoveredSecuritySolutionsClient object.
     */
    public DiscoveredSecuritySolutionsClient getDiscoveredSecuritySolutions() {
        return this.discoveredSecuritySolutions;
    }

    /**
     * The ExternalSecuritySolutionsClient object to access its operations.
     */
    private final ExternalSecuritySolutionsClient externalSecuritySolutions;

    /**
     * Gets the ExternalSecuritySolutionsClient object to access its operations.
     * 
     * @return the ExternalSecuritySolutionsClient object.
     */
    public ExternalSecuritySolutionsClient getExternalSecuritySolutions() {
        return this.externalSecuritySolutions;
    }

    /**
     * The JitNetworkAccessPoliciesClient object to access its operations.
     */
    private final JitNetworkAccessPoliciesClient jitNetworkAccessPolicies;

    /**
     * Gets the JitNetworkAccessPoliciesClient object to access its operations.
     * 
     * @return the JitNetworkAccessPoliciesClient object.
     */
    public JitNetworkAccessPoliciesClient getJitNetworkAccessPolicies() {
        return this.jitNetworkAccessPolicies;
    }

    /**
     * The SecureScoresClient object to access its operations.
     */
    private final SecureScoresClient secureScores;

    /**
     * Gets the SecureScoresClient object to access its operations.
     * 
     * @return the SecureScoresClient object.
     */
    public SecureScoresClient getSecureScores() {
        return this.secureScores;
    }

    /**
     * The SecureScoreControlsClient object to access its operations.
     */
    private final SecureScoreControlsClient secureScoreControls;

    /**
     * Gets the SecureScoreControlsClient object to access its operations.
     * 
     * @return the SecureScoreControlsClient object.
     */
    public SecureScoreControlsClient getSecureScoreControls() {
        return this.secureScoreControls;
    }

    /**
     * The SecureScoreControlDefinitionsClient object to access its operations.
     */
    private final SecureScoreControlDefinitionsClient secureScoreControlDefinitions;

    /**
     * Gets the SecureScoreControlDefinitionsClient object to access its operations.
     * 
     * @return the SecureScoreControlDefinitionsClient object.
     */
    public SecureScoreControlDefinitionsClient getSecureScoreControlDefinitions() {
        return this.secureScoreControlDefinitions;
    }

    /**
     * The SecuritySolutionsClient object to access its operations.
     */
    private final SecuritySolutionsClient securitySolutions;

    /**
     * Gets the SecuritySolutionsClient object to access its operations.
     * 
     * @return the SecuritySolutionsClient object.
     */
    public SecuritySolutionsClient getSecuritySolutions() {
        return this.securitySolutions;
    }

    /**
     * The SecuritySolutionsReferenceDatasClient object to access its operations.
     */
    private final SecuritySolutionsReferenceDatasClient securitySolutionsReferenceDatas;

    /**
     * Gets the SecuritySolutionsReferenceDatasClient object to access its operations.
     * 
     * @return the SecuritySolutionsReferenceDatasClient object.
     */
    public SecuritySolutionsReferenceDatasClient getSecuritySolutionsReferenceDatas() {
        return this.securitySolutionsReferenceDatas;
    }

    /**
     * The ServerVulnerabilityAssessmentsClient object to access its operations.
     */
    private final ServerVulnerabilityAssessmentsClient serverVulnerabilityAssessments;

    /**
     * Gets the ServerVulnerabilityAssessmentsClient object to access its operations.
     * 
     * @return the ServerVulnerabilityAssessmentsClient object.
     */
    public ServerVulnerabilityAssessmentsClient getServerVulnerabilityAssessments() {
        return this.serverVulnerabilityAssessments;
    }

    /**
     * The TopologiesClient object to access its operations.
     */
    private final TopologiesClient topologies;

    /**
     * Gets the TopologiesClient object to access its operations.
     * 
     * @return the TopologiesClient object.
     */
    public TopologiesClient getTopologies() {
        return this.topologies;
    }

    /**
     * The AssessmentsMetadatasClient object to access its operations.
     */
    private final AssessmentsMetadatasClient assessmentsMetadatas;

    /**
     * Gets the AssessmentsMetadatasClient object to access its operations.
     * 
     * @return the AssessmentsMetadatasClient object.
     */
    public AssessmentsMetadatasClient getAssessmentsMetadatas() {
        return this.assessmentsMetadatas;
    }

    /**
     * The AssessmentsClient object to access its operations.
     */
    private final AssessmentsClient assessments;

    /**
     * Gets the AssessmentsClient object to access its operations.
     * 
     * @return the AssessmentsClient object.
     */
    public AssessmentsClient getAssessments() {
        return this.assessments;
    }

    /**
     * The AlertsClient object to access its operations.
     */
    private final AlertsClient alerts;

    /**
     * Gets the AlertsClient object to access its operations.
     * 
     * @return the AlertsClient object.
     */
    public AlertsClient getAlerts() {
        return this.alerts;
    }

    /**
     * The SettingsClient object to access its operations.
     */
    private final SettingsClient settings;

    /**
     * Gets the SettingsClient object to access its operations.
     * 
     * @return the SettingsClient object.
     */
    public SettingsClient getSettings() {
        return this.settings;
    }

    /**
     * The ServerVulnerabilityAssessmentsSettingsClient object to access its operations.
     */
    private final ServerVulnerabilityAssessmentsSettingsClient serverVulnerabilityAssessmentsSettings;

    /**
     * Gets the ServerVulnerabilityAssessmentsSettingsClient object to access its operations.
     * 
     * @return the ServerVulnerabilityAssessmentsSettingsClient object.
     */
    public ServerVulnerabilityAssessmentsSettingsClient getServerVulnerabilityAssessmentsSettings() {
        return this.serverVulnerabilityAssessmentsSettings;
    }

    /**
     * The ApiCollectionsClient object to access its operations.
     */
    private final ApiCollectionsClient apiCollections;

    /**
     * Gets the ApiCollectionsClient object to access its operations.
     * 
     * @return the ApiCollectionsClient object.
     */
    public ApiCollectionsClient getApiCollections() {
        return this.apiCollections;
    }

    /**
     * The PricingsClient object to access its operations.
     */
    private final PricingsClient pricings;

    /**
     * Gets the PricingsClient object to access its operations.
     * 
     * @return the PricingsClient object.
     */
    public PricingsClient getPricings() {
        return this.pricings;
    }

    /**
     * The SecurityStandardsClient object to access its operations.
     */
    private final SecurityStandardsClient securityStandards;

    /**
     * Gets the SecurityStandardsClient object to access its operations.
     * 
     * @return the SecurityStandardsClient object.
     */
    public SecurityStandardsClient getSecurityStandards() {
        return this.securityStandards;
    }

    /**
     * The StandardAssignmentsClient object to access its operations.
     */
    private final StandardAssignmentsClient standardAssignments;

    /**
     * Gets the StandardAssignmentsClient object to access its operations.
     * 
     * @return the StandardAssignmentsClient object.
     */
    public StandardAssignmentsClient getStandardAssignments() {
        return this.standardAssignments;
    }

    /**
     * The CustomRecommendationsClient object to access its operations.
     */
    private final CustomRecommendationsClient customRecommendations;

    /**
     * Gets the CustomRecommendationsClient object to access its operations.
     * 
     * @return the CustomRecommendationsClient object.
     */
    public CustomRecommendationsClient getCustomRecommendations() {
        return this.customRecommendations;
    }

    /**
     * Initializes an instance of SecurityCenter client.
     * 
     * @param httpPipeline The HTTP pipeline to send requests through.
     * @param serializerAdapter The serializer to serialize an object into a string.
     * @param defaultPollInterval The default poll interval for long-running operation.
     * @param environment The Azure environment.
     * @param subscriptionId Azure subscription ID.
     * @param endpoint server parameter.
     */
    SecurityCenterImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval,
        AzureEnvironment environment, String subscriptionId, String endpoint) {
        this.httpPipeline = httpPipeline;
        this.serializerAdapter = serializerAdapter;
        this.defaultPollInterval = defaultPollInterval;
        this.subscriptionId = subscriptionId;
        this.endpoint = endpoint;
        this.complianceResults = new ComplianceResultsClientImpl(this);
        this.advancedThreatProtections = new AdvancedThreatProtectionsClientImpl(this);
        this.deviceSecurityGroups = new DeviceSecurityGroupsClientImpl(this);
        this.iotSecuritySolutionAnalytics = new IotSecuritySolutionAnalyticsClientImpl(this);
        this.iotSecuritySolutionsAnalyticsAggregatedAlerts
            = new IotSecuritySolutionsAnalyticsAggregatedAlertsClientImpl(this);
        this.iotSecuritySolutionsAnalyticsRecommendations
            = new IotSecuritySolutionsAnalyticsRecommendationsClientImpl(this);
        this.iotSecuritySolutions = new IotSecuritySolutionsClientImpl(this);
        this.allowedConnections = new AllowedConnectionsClientImpl(this);
        this.discoveredSecuritySolutions = new DiscoveredSecuritySolutionsClientImpl(this);
        this.externalSecuritySolutions = new ExternalSecuritySolutionsClientImpl(this);
        this.jitNetworkAccessPolicies = new JitNetworkAccessPoliciesClientImpl(this);
        this.secureScores = new SecureScoresClientImpl(this);
        this.secureScoreControls = new SecureScoreControlsClientImpl(this);
        this.secureScoreControlDefinitions = new SecureScoreControlDefinitionsClientImpl(this);
        this.securitySolutions = new SecuritySolutionsClientImpl(this);
        this.securitySolutionsReferenceDatas = new SecuritySolutionsReferenceDatasClientImpl(this);
        this.serverVulnerabilityAssessments = new ServerVulnerabilityAssessmentsClientImpl(this);
        this.topologies = new TopologiesClientImpl(this);
        this.assessmentsMetadatas = new AssessmentsMetadatasClientImpl(this);
        this.assessments = new AssessmentsClientImpl(this);
        this.alerts = new AlertsClientImpl(this);
        this.settings = new SettingsClientImpl(this);
        this.serverVulnerabilityAssessmentsSettings = new ServerVulnerabilityAssessmentsSettingsClientImpl(this);
        this.apiCollections = new ApiCollectionsClientImpl(this);
        this.pricings = new PricingsClientImpl(this);
        this.securityStandards = new SecurityStandardsClientImpl(this);
        this.standardAssignments = new StandardAssignmentsClientImpl(this);
        this.customRecommendations = new CustomRecommendationsClientImpl(this);
    }

    /**
     * Gets default client context.
     * 
     * @return the default client context.
     */
    public Context getContext() {
        return Context.NONE;
    }

    /**
     * Merges default client context with provided context.
     * 
     * @param context the context to be merged with default client context.
     * @return the merged context.
     */
    public Context mergeContext(Context context) {
        return CoreUtils.mergeContexts(this.getContext(), context);
    }

    /**
     * Gets long running operation result.
     * 
     * @param activationResponse the response of activation operation.
     * @param httpPipeline the http pipeline.
     * @param pollResultType type of poll result.
     * @param finalResultType type of final result.
     * @param context the context shared by all requests.
     * @param  type of poll result.
     * @param  type of final result.
     * @return poller flux for poll result and final result.
     */
    public  PollerFlux, U> getLroResult(Mono>> activationResponse,
        HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) {
        return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType,
            defaultPollInterval, activationResponse, context);
    }

    /**
     * Gets the final result, or an error, based on last async poll response.
     * 
     * @param response the last async poll response.
     * @param  type of poll result.
     * @param  type of final result.
     * @return the final result, or an error.
     */
    public  Mono getLroFinalResultOrError(AsyncPollResponse, U> response) {
        if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
            String errorMessage;
            ManagementError managementError = null;
            HttpResponse errorResponse = null;
            PollResult.Error lroError = response.getValue().getError();
            if (lroError != null) {
                errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(),
                    lroError.getResponseBody());

                errorMessage = response.getValue().getError().getMessage();
                String errorBody = response.getValue().getError().getResponseBody();
                if (errorBody != null) {
                    // try to deserialize error body to ManagementError
                    try {
                        managementError = this.getSerializerAdapter()
                            .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON);
                        if (managementError.getCode() == null || managementError.getMessage() == null) {
                            managementError = null;
                        }
                    } catch (IOException | RuntimeException ioe) {
                        LOGGER.logThrowableAsWarning(ioe);
                    }
                }
            } else {
                // fallback to default error message
                errorMessage = "Long running operation failed.";
            }
            if (managementError == null) {
                // fallback to default ManagementError
                managementError = new ManagementError(response.getStatus().toString(), errorMessage);
            }
            return Mono.error(new ManagementException(errorMessage, errorResponse, managementError));
        } else {
            return response.getFinalResult();
        }
    }

    private static final class HttpResponseImpl extends HttpResponse {
        private final int statusCode;

        private final byte[] responseBody;

        private final HttpHeaders httpHeaders;

        HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) {
            super(null);
            this.statusCode = statusCode;
            this.httpHeaders = httpHeaders;
            this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8);
        }

        public int getStatusCode() {
            return statusCode;
        }

        public String getHeaderValue(String s) {
            return httpHeaders.getValue(HttpHeaderName.fromString(s));
        }

        public HttpHeaders getHeaders() {
            return httpHeaders;
        }

        public Flux getBody() {
            return Flux.just(ByteBuffer.wrap(responseBody));
        }

        public Mono getBodyAsByteArray() {
            return Mono.just(responseBody);
        }

        public Mono getBodyAsString() {
            return Mono.just(new String(responseBody, StandardCharsets.UTF_8));
        }

        public Mono getBodyAsString(Charset charset) {
            return Mono.just(new String(responseBody, charset));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(SecurityCenterImpl.class);
}