/// <summary>
        /// Convert a Management.Sql.LegacySdk.Models.Server to AzureSqlDatabaseServerModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the server is in</param>
        /// <param name="resp">The management client server response to convert</param>
        /// <returns>The converted server model</returns>
        private static AzureSqlServerModel CreateServerModelFromResponse(Management.Sql.Models.Server resp)
        {
            AzureSqlServerModel server = new AzureSqlServerModel();

            // Extract the resource group name from the ID.
            // ID is in the form:
            // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Sql/servers/serverName
            string[] segments = resp.Id.Split('/');
            server.ResourceGroupName = segments[4];

            server.ServerName            = resp.Name;
            server.ServerVersion         = resp.Version;
            server.SqlAdministratorLogin = resp.AdministratorLogin;
            server.Location = resp.Location;
            server.Tags     = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false);
            server.Identity = resp.Identity;
            server.FullyQualifiedDomainName = resp.FullyQualifiedDomainName;
            server.ResourceId                    = resp.Id;
            server.MinimalTlsVersion             = resp.MinimalTlsVersion;
            server.PublicNetworkAccess           = resp.PublicNetworkAccess;
            server.RestrictOutboundNetworkAccess = resp.RestrictOutboundNetworkAccess;
            server.Administrators                = resp.Administrators;

            if (server.Administrators != null && server.Administrators.AdministratorType == null)
            {
                server.Administrators.AdministratorType = "ActiveDirectory";
            }
            server.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId;
            server.KeyId             = resp.KeyId;
            server.FederatedClientId = resp.FederatedClientId;

            return(server);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is responsible to call the right API in the communication layer that will eventually send the information in the
        /// object to the REST endpoint
        /// </summary>
        /// <param name="model">The model object with the data to be sent to the REST endpoints</param>
        protected override ServerAdvancedDataSecurityPolicyModel PersistChanges(ServerAdvancedDataSecurityPolicyModel model)
        {
            model.IsEnabled = true;

            if (DoNotConfigureVulnerabilityAssessment)
            {
                ModelAdapter.SetServerAdvancedDataSecurity(model);
            }
            else
            {
                // Deploy arm template to enable VA - only if VA at server level is not defined
                var vaAdapter = new SqlVulnerabilityAssessmentAdapter(DefaultContext);
                var vaModel   = vaAdapter.GetVulnerabilityAssessmentSettings(ResourceGroupName, ServerName, "", ApplyToType.Server);

                if (string.IsNullOrEmpty(vaModel.StorageAccountName))
                {
                    var serverAdapter = new AzureSqlServerAdapter(DefaultContext);
                    AzureSqlServerModel serverModel = serverAdapter.GetServer(ResourceGroupName, ServerName);
                    ModelAdapter.EnableServerAdsWithVa(ResourceGroupName, ServerName, serverModel.Location, DeploymentName);
                }
                else
                {
                    ModelAdapter.SetServerAdvancedDataSecurity(model);
                }
            }

            return(model);
        }
        /// <summary>
        /// Convert a Management.Sql.Models.Server to AzureSqlDatabaseServerModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the server is in</param>
        /// <param name="resp">The management client server response to convert</param>
        /// <returns>The converted server model</returns>
        private static AzureSqlServerModel CreateServerModelFromResponse(string resourceGroupName, Management.Sql.Models.Server resp)
        {
            AzureSqlServerModel server = new AzureSqlServerModel();

            server.ResourceGroupName     = resourceGroupName;
            server.ServerName            = resp.Name;
            server.ServerVersion         = resp.Properties.Version;
            server.SqlAdministratorLogin = resp.Properties.AdministratorLogin;
            server.Location = resp.Location;

            return(server);
        }
        /// <summary>
        /// Upserts a server
        /// </summary>
        /// <param name="model">The server to upsert</param>
        /// <returns>The updated server model</returns>
        public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, Util.GenerateTracingId(), new Management.Sql.Models.Server()
            {
                Location                   = model.Location,
                Tags                       = model.Tags,
                AdministratorLogin         = model.SqlAdministratorLogin,
                AdministratorLoginPassword = model.SqlAdministratorPassword != null ? Decrypt(model.SqlAdministratorPassword) : null,
                Version                    = model.ServerVersion,
            });

            return(CreateServerModelFromResponse(model.ResourceGroupName, resp));
        }
        /// <summary>
        /// Convert a Management.Sql.LegacySdk.Models.Server to AzureSqlDatabaseServerModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the server is in</param>
        /// <param name="resp">The management client server response to convert</param>
        /// <returns>The converted server model</returns>
        private static AzureSqlServerModel CreateServerModelFromResponse(string resourceGroupName, Management.Sql.Models.Server resp)
        {
            AzureSqlServerModel server = new AzureSqlServerModel();

            server.ResourceGroupName     = resourceGroupName;
            server.ServerName            = resp.Name;
            server.ServerVersion         = resp.Version;
            server.SqlAdministratorLogin = resp.AdministratorLogin;
            server.Location = resp.Location;
            server.Tags     = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false);

            return(server);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Upserts a server
        /// </summary>
        /// <param name="model">The server to upsert</param>
        /// <returns>The updated server model</returns>
        public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, new Management.Sql.Models.Server()
            {
                Location                   = model.Location,
                Tags                       = model.Tags,
                AdministratorLogin         = model.SqlAdministratorLogin,
                AdministratorLoginPassword = model.SqlAdministratorPassword != null ? Decrypt(model.SqlAdministratorPassword) : null,
                Version                    = model.ServerVersion,
                Identity                   = model.Identity,
                PublicNetworkAccess        = model.PublicNetworkAccess
            });

            return(CreateServerModelFromResponse(resp));
        }
        /// <summary>
        /// Upserts a server
        /// </summary>
        /// <param name="model">The server to upsert</param>
        /// <returns>The updated server model</returns>
        public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, Util.GenerateTracingId(), new ServerCreateOrUpdateParameters()
            {
                Location   = model.Location,
                Tags       = model.Tags,
                Properties = new ServerCreateOrUpdateProperties()
                {
                    AdministratorLogin         = model.SqlAdministratorLogin,
                    AdministratorLoginPassword = Decrypt(model.SqlAdministratorPassword),
                    Version = model.ServerVersion,
                }
            });

            return(CreateServerModelFromResponse(model.ResourceGroupName, resp));
        }
        /// <summary>
        /// Convert a Management.Sql.LegacySdk.Models.Server to AzureSqlDatabaseServerModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the server is in</param>
        /// <param name="resp">The management client server response to convert</param>
        /// <returns>The converted server model</returns>
        private static AzureSqlServerModel CreateServerModelFromResponse(Management.Sql.Models.Server resp)
        {
            AzureSqlServerModel server = new AzureSqlServerModel();

            // Extract the resource group name from the ID.
            // ID is in the form:
            // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Sql/servers/serverName
            string[] segments = resp.Id.Split('/');
            server.ResourceGroupName = segments[4];

            server.ServerName            = resp.Name;
            server.ServerVersion         = resp.Version;
            server.SqlAdministratorLogin = resp.AdministratorLogin;
            server.Location = resp.Location;
            server.Tags     = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false);
            server.Identity = resp.Identity;

            return(server);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Upserts a server
        /// </summary>
        /// <param name="model">The server to upsert</param>
        /// <returns>The updated server model</returns>
        public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, new Management.Sql.Models.Server()
            {
                Location                      = model.Location,
                Tags                          = model.Tags,
                AdministratorLogin            = model.SqlAdministratorLogin,
                AdministratorLoginPassword    = model.SqlAdministratorPassword != null ? Decrypt(model.SqlAdministratorPassword) : null,
                Version                       = model.ServerVersion,
                Identity                      = model.Identity,
                MinimalTlsVersion             = model.MinimalTlsVersion,
                PublicNetworkAccess           = model.PublicNetworkAccess,
                Administrators                = GetActiveDirectoryInformation(model.Administrators),
                PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
                KeyId                         = model.KeyId
            });

            return(CreateServerModelFromResponse(resp));
        }