Пример #1
0
        /// <summary>
        /// The non-boilerplated test code of the APIs for managing the lifecycle of a given database's security alert policy. It is meant to be called with a name of an already existing database (and therefore already existing
        /// server and resource group). This test does not create these resources and does not remove them.
        /// </summary>
        private static void TestServerSecurityAlertApis(SqlManagementClient sqlClient, string resourceGroupName, Server server)
        {
            var getDefaultDatabaseSecurityAlertPolicyResponse = sqlClient.SecurityAlertPolicy.GetServerSecurityAlertPolicy(resourceGroupName, server.Name);
            var properties = getDefaultDatabaseSecurityAlertPolicyResponse.SecurityAlertPolicy.Properties;

            // Verify that the initial Get request contains the default policy.
            TestUtilities.ValidateOperationResponse(getDefaultDatabaseSecurityAlertPolicyResponse);
            VerifySecurityAlertPolicyInformation(GetDefaultServerSecurityAlertProperties(), properties);

            // Modify the policy properties, send and receive, see it its still ok
            ChangeSecurityAlertPolicy(properties);
            var updateParams = new ServerSecurityAlertPolicyCreateOrUpdateParameters {
                Properties = properties
            };

            /*var updateResponse = */ sqlClient.SecurityAlertPolicy.CreateOrUpdateServerSecurityAlertPolicy(resourceGroupName, server.Name, updateParams);

            // Verify that the initial Get request contains the default policy.
            //  TestUtilities.ValidateOperationResponse(updateResponse);

            var getUpdatedPolicyResponse = sqlClient.SecurityAlertPolicy.GetServerSecurityAlertPolicy(resourceGroupName, server.Name);
            var updatedProperties        = getUpdatedPolicyResponse.SecurityAlertPolicy.Properties;

            // Verify that the Get request contains the updated policy.
            TestUtilities.ValidateOperationResponse(getUpdatedPolicyResponse);
            VerifySecurityAlertPolicyInformation(properties, updatedProperties);
        }
        /// <summary>
        /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint
        /// </summary>
        private ServerSecurityAlertPolicyCreateOrUpdateParameters PolicizeServerSecurityAlertModel(BaseThreatDetectionPolicyModel model, string storageEndpointSuffix)
        {
            var updateParameters = new ServerSecurityAlertPolicyCreateOrUpdateParameters();
            var properties       = PopulatePolicyProperties(model, storageEndpointSuffix, new ServerSecurityAlertPolicyProperties()) as ServerSecurityAlertPolicyProperties;

            updateParameters.Properties = properties;
            return(updateParameters);
        }
Пример #3
0
        /// <summary>
        /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint
        /// </summary>
        /// <param name="model">The SecurityAlert model object</param>
        /// <returns>The communication model object</returns>
        private ServerSecurityAlertPolicyCreateOrUpdateParameters PolicizeServerSecurityAlertModel(ServerThreatDetectionPolicyModel model)
        {
            var updateParameters = new ServerSecurityAlertPolicyCreateOrUpdateParameters();
            var properties       = PopulatePolicyProperties(model, new ServerSecurityAlertPolicyProperties()) as ServerSecurityAlertPolicyProperties;

            updateParameters.Properties = properties;
            return(updateParameters);
        }
Пример #4
0
 /// <summary>
 /// Creates or updates an Azure SQL Server security alert policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.LegacySdk.ISecurityAlertPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a Azure
 /// SQL Database security alert policy.
 /// </param>
 /// <returns>
 /// Response to Azure Sql Server security alert policy create or update
 /// operation.
 /// </returns>
 public static Task <ServerSecurityAlertPolicyCreateOrUpdateResponse> CreateOrUpdateServerSecurityAlertPolicyAsync(this ISecurityAlertPolicyOperations operations, string resourceGroupName, string serverName, ServerSecurityAlertPolicyCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateServerSecurityAlertPolicyAsync(resourceGroupName, serverName, parameters, CancellationToken.None));
 }
Пример #5
0
 /// <summary>
 /// Creates or updates an Azure SQL Server security alert policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.LegacySdk.ISecurityAlertPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for creating or updating a Azure
 /// SQL Database security alert policy.
 /// </param>
 /// <returns>
 /// Response to Azure Sql Server security alert policy create or update
 /// operation.
 /// </returns>
 public static ServerSecurityAlertPolicyCreateOrUpdateResponse CreateOrUpdateServerSecurityAlertPolicy(this ISecurityAlertPolicyOperations operations, string resourceGroupName, string serverName, ServerSecurityAlertPolicyCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ISecurityAlertPolicyOperations)s).CreateOrUpdateServerSecurityAlertPolicyAsync(resourceGroupName, serverName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Пример #6
0
        /// <summary>
        /// Calls the set security alert APIs for the server security alert policy in the given resource group
        /// </summary>
        public void SetServerSecurityAlertPolicy(string resourceGroupName, string serverName, string clientRequestId, ServerSecurityAlertPolicyCreateOrUpdateParameters parameters)
        {
            ISecurityAlertPolicyOperations operations = GetCurrentSqlClient(clientRequestId).SecurityAlertPolicy;
            var statusLink = operations.CreateOrUpdateServerSecurityAlertPolicy(resourceGroupName, serverName, parameters).OperationStatusLink;

            if (string.IsNullOrEmpty(statusLink))
            {
                return;
            }
            for (var iterationCount = 0; iterationCount < 1800; iterationCount++) // wait for at most an hour
            {
                var status = GetServerCreateOrUpdateOperationStatus(statusLink, clientRequestId);
                if (status == OperationStatus.Succeeded)
                {
                    break;
                }
                TestMockSupport.Delay(2000); // wait 2 seconds between each poll
            }
        }