diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/__init__.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/__init__.py index 14ff84b0f760..230e22f7d8ce 100644 --- a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/__init__.py +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/__init__.py @@ -32,6 +32,7 @@ from .performance_tier_properties_py3 import PerformanceTierProperties from .name_availability_request_py3 import NameAvailabilityRequest from .name_availability_py3 import NameAvailability + from .server_security_alert_policy_py3 import ServerSecurityAlertPolicy except (SyntaxError, ImportError): from .proxy_resource import ProxyResource from .tracked_resource import TrackedResource @@ -55,6 +56,7 @@ from .performance_tier_properties import PerformanceTierProperties from .name_availability_request import NameAvailabilityRequest from .name_availability import NameAvailability + from .server_security_alert_policy import ServerSecurityAlertPolicy from .server_paged import ServerPaged from .firewall_rule_paged import FirewallRulePaged from .database_paged import DatabasePaged @@ -68,6 +70,7 @@ GeoRedundantBackup, SkuTier, OperationOrigin, + ServerSecurityAlertPolicyState, ) __all__ = [ @@ -93,6 +96,7 @@ 'PerformanceTierProperties', 'NameAvailabilityRequest', 'NameAvailability', + 'ServerSecurityAlertPolicy', 'ServerPaged', 'FirewallRulePaged', 'DatabasePaged', @@ -105,4 +109,5 @@ 'GeoRedundantBackup', 'SkuTier', 'OperationOrigin', + 'ServerSecurityAlertPolicyState', ] diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/postgre_sql_management_client_enums.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/postgre_sql_management_client_enums.py index 067e776798b4..56adfdb34f8b 100644 --- a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/postgre_sql_management_client_enums.py +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/postgre_sql_management_client_enums.py @@ -49,3 +49,9 @@ class OperationOrigin(str, Enum): not_specified = "NotSpecified" user = "user" system = "system" + + +class ServerSecurityAlertPolicyState(str, Enum): + + enabled = "Enabled" + disabled = "Disabled" diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy.py new file mode 100644 index 000000000000..2e42bd22f18d --- /dev/null +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy.py @@ -0,0 +1,83 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from .proxy_resource import ProxyResource + + +class ServerSecurityAlertPolicy(ProxyResource): + """A server security alert policy. + + Variables are only populated by the server, and will be ignored when + sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Resource ID + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :param state: Required. Specifies the state of the policy, whether it is + enabled or disabled. Possible values include: 'Enabled', 'Disabled' + :type state: str or + ~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicyState + :param disabled_alerts: Specifies an array of alerts that are disabled. + Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, + Access_Anomaly + :type disabled_alerts: list[str] + :param email_addresses: Specifies an array of e-mail addresses to which + the alert is sent. + :type email_addresses: list[str] + :param email_account_admins: Specifies that the alert is sent to the + account administrators. + :type email_account_admins: bool + :param storage_endpoint: Specifies the blob storage endpoint (e.g. + https://MyAccount.blob.core.windows.net). This blob storage will hold all + Threat Detection audit logs. + :type storage_endpoint: str + :param storage_account_access_key: Specifies the identifier key of the + Threat Detection audit storage account. + :type storage_account_access_key: str + :param retention_days: Specifies the number of days to keep in the Threat + Detection audit logs. + :type retention_days: int + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'state': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'state': {'key': 'properties.state', 'type': 'ServerSecurityAlertPolicyState'}, + 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, + 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, + 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, + 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, + 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, + 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, + } + + def __init__(self, **kwargs): + super(ServerSecurityAlertPolicy, self).__init__(**kwargs) + self.state = kwargs.get('state', None) + self.disabled_alerts = kwargs.get('disabled_alerts', None) + self.email_addresses = kwargs.get('email_addresses', None) + self.email_account_admins = kwargs.get('email_account_admins', None) + self.storage_endpoint = kwargs.get('storage_endpoint', None) + self.storage_account_access_key = kwargs.get('storage_account_access_key', None) + self.retention_days = kwargs.get('retention_days', None) diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy_py3.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy_py3.py new file mode 100644 index 000000000000..0a40a1edd57d --- /dev/null +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/models/server_security_alert_policy_py3.py @@ -0,0 +1,83 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from .proxy_resource import ProxyResource + + +class ServerSecurityAlertPolicy(ProxyResource): + """A server security alert policy. + + Variables are only populated by the server, and will be ignored when + sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Resource ID + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :param state: Required. Specifies the state of the policy, whether it is + enabled or disabled. Possible values include: 'Enabled', 'Disabled' + :type state: str or + ~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicyState + :param disabled_alerts: Specifies an array of alerts that are disabled. + Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, + Access_Anomaly + :type disabled_alerts: list[str] + :param email_addresses: Specifies an array of e-mail addresses to which + the alert is sent. + :type email_addresses: list[str] + :param email_account_admins: Specifies that the alert is sent to the + account administrators. + :type email_account_admins: bool + :param storage_endpoint: Specifies the blob storage endpoint (e.g. + https://MyAccount.blob.core.windows.net). This blob storage will hold all + Threat Detection audit logs. + :type storage_endpoint: str + :param storage_account_access_key: Specifies the identifier key of the + Threat Detection audit storage account. + :type storage_account_access_key: str + :param retention_days: Specifies the number of days to keep in the Threat + Detection audit logs. + :type retention_days: int + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'state': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'state': {'key': 'properties.state', 'type': 'ServerSecurityAlertPolicyState'}, + 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, + 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, + 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, + 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, + 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, + 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, + } + + def __init__(self, *, state, disabled_alerts=None, email_addresses=None, email_account_admins: bool=None, storage_endpoint: str=None, storage_account_access_key: str=None, retention_days: int=None, **kwargs) -> None: + super(ServerSecurityAlertPolicy, self).__init__(**kwargs) + self.state = state + self.disabled_alerts = disabled_alerts + self.email_addresses = email_addresses + self.email_account_admins = email_account_admins + self.storage_endpoint = storage_endpoint + self.storage_account_access_key = storage_account_access_key + self.retention_days = retention_days diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/__init__.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/__init__.py index 323618c0dd5f..8da462eefd31 100644 --- a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/__init__.py +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/__init__.py @@ -16,6 +16,7 @@ from .log_files_operations import LogFilesOperations from .location_based_performance_tier_operations import LocationBasedPerformanceTierOperations from .check_name_availability_operations import CheckNameAvailabilityOperations +from .server_security_alert_policies_operations import ServerSecurityAlertPoliciesOperations from .operations import Operations __all__ = [ @@ -26,5 +27,6 @@ 'LogFilesOperations', 'LocationBasedPerformanceTierOperations', 'CheckNameAvailabilityOperations', + 'ServerSecurityAlertPoliciesOperations', 'Operations', ] diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/server_security_alert_policies_operations.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/server_security_alert_policies_operations.py new file mode 100644 index 000000000000..249d0f9b35ea --- /dev/null +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/operations/server_security_alert_policies_operations.py @@ -0,0 +1,212 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse +from msrestazure.azure_exceptions import CloudError +from msrest.polling import LROPoller, NoPolling +from msrestazure.polling.arm_polling import ARMPolling + +from .. import models + + +class ServerSecurityAlertPoliciesOperations(object): + """ServerSecurityAlertPoliciesOperations operations. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + :ivar security_alert_policy_name: The name of the security alert policy. Constant value: "Default". + :ivar api_version: The API version to use for the request. Constant value: "2017-12-01". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.security_alert_policy_name = "Default" + self.api_version = "2017-12-01" + + self.config = config + + def get( + self, resource_group_name, server_name, custom_headers=None, raw=False, **operation_config): + """Get a server's security alert policy. + + :param resource_group_name: The name of the resource group that + contains the resource. You can obtain this value from the Azure + Resource Manager API or the portal. + :type resource_group_name: str + :param server_name: The name of the server. + :type server_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ServerSecurityAlertPolicy or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicy + or ~msrest.pipeline.ClientRawResponse + :raises: :class:`CloudError` + """ + # Construct URL + url = self.get.metadata['url'] + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'serverName': self._serialize.url("server_name", server_name, 'str'), + 'securityAlertPolicyName': self._serialize.url("self.security_alert_policy_name", self.security_alert_policy_name, 'str'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send(request, header_parameters, stream=False, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ServerSecurityAlertPolicy', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}'} + + + def _create_or_update_initial( + self, resource_group_name, server_name, parameters, custom_headers=None, raw=False, **operation_config): + # Construct URL + url = self.create_or_update.metadata['url'] + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'serverName': self._serialize.url("server_name", server_name, 'str'), + 'securityAlertPolicyName': self._serialize.url("self.security_alert_policy_name", self.security_alert_policy_name, 'str'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(parameters, 'ServerSecurityAlertPolicy') + + # Construct and send request + request = self._client.put(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, stream=False, **operation_config) + + if response.status_code not in [200, 202]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ServerSecurityAlertPolicy', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def create_or_update( + self, resource_group_name, server_name, parameters, custom_headers=None, raw=False, polling=True, **operation_config): + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that + contains the resource. You can obtain this value from the Azure + Resource Manager API or the portal. + :type resource_group_name: str + :param server_name: The name of the server. + :type server_name: str + :param parameters: The server security alert policy. + :type parameters: + ~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicy + :param dict custom_headers: headers that will be added to the request + :param bool raw: The poller return type is ClientRawResponse, the + direct response alongside the deserialized response + :param polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :return: An instance of LROPoller that returns + ServerSecurityAlertPolicy or + ClientRawResponse if raw==True + :rtype: + ~msrestazure.azure_operation.AzureOperationPoller[~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicy] + or + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[~azure.mgmt.rdbms.postgresql.models.ServerSecurityAlertPolicy]] + :raises: :class:`CloudError` + """ + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + server_name=server_name, + parameters=parameters, + custom_headers=custom_headers, + raw=True, + **operation_config + ) + + def get_long_running_output(response): + deserialized = self._deserialize('ServerSecurityAlertPolicy', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + lro_delay = operation_config.get( + 'long_running_operation_timeout', + self.config.long_running_operation_timeout) + if polling is True: polling_method = ARMPolling(lro_delay, **operation_config) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}'} diff --git a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/postgre_sql_management_client.py b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/postgre_sql_management_client.py index 205e43afb3b4..c0ccfb0cad71 100644 --- a/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/postgre_sql_management_client.py +++ b/azure-mgmt-rdbms/azure/mgmt/rdbms/postgresql/postgre_sql_management_client.py @@ -9,7 +9,7 @@ # regenerated. # -------------------------------------------------------------------------- -from msrest.service_client import ServiceClient +from msrest.service_client import SDKClient from msrest import Serializer, Deserializer from msrestazure import AzureConfiguration from .version import VERSION @@ -20,6 +20,7 @@ from .operations.log_files_operations import LogFilesOperations from .operations.location_based_performance_tier_operations import LocationBasedPerformanceTierOperations from .operations.check_name_availability_operations import CheckNameAvailabilityOperations +from .operations.server_security_alert_policies_operations import ServerSecurityAlertPoliciesOperations from .operations.operations import Operations from . import models @@ -57,8 +58,8 @@ def __init__( self.subscription_id = subscription_id -class PostgreSQLManagementClient(object): - """The Microsoft Azure management API provides create, read, update, and delete functionality for Azure PostgreSQL resources including servers, databases, firewall rules, log files and configurations with new business model. +class PostgreSQLManagementClient(SDKClient): + """The Microsoft Azure management API provides create, read, update, and delete functionality for Azure PostgreSQL resources including servers, databases, firewall rules, security alert policies, log files and configurations with new business model. :ivar config: Configuration for client. :vartype config: PostgreSQLManagementClientConfiguration @@ -77,6 +78,8 @@ class PostgreSQLManagementClient(object): :vartype location_based_performance_tier: azure.mgmt.rdbms.postgresql.operations.LocationBasedPerformanceTierOperations :ivar check_name_availability: CheckNameAvailability operations :vartype check_name_availability: azure.mgmt.rdbms.postgresql.operations.CheckNameAvailabilityOperations + :ivar server_security_alert_policies: ServerSecurityAlertPolicies operations + :vartype server_security_alert_policies: azure.mgmt.rdbms.postgresql.operations.ServerSecurityAlertPoliciesOperations :ivar operations: Operations operations :vartype operations: azure.mgmt.rdbms.postgresql.operations.Operations @@ -93,7 +96,7 @@ def __init__( self, credentials, subscription_id, base_url=None): self.config = PostgreSQLManagementClientConfiguration(credentials, subscription_id, base_url) - self._client = ServiceClient(self.config.credentials, self.config) + super(PostgreSQLManagementClient, self).__init__(self.config.credentials, self.config) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self.api_version = '2017-12-01' @@ -114,5 +117,7 @@ def __init__( self._client, self.config, self._serialize, self._deserialize) self.check_name_availability = CheckNameAvailabilityOperations( self._client, self.config, self._serialize, self._deserialize) + self.server_security_alert_policies = ServerSecurityAlertPoliciesOperations( + self._client, self.config, self._serialize, self._deserialize) self.operations = Operations( self._client, self.config, self._serialize, self._deserialize)