/// <summary> /// Set settings with storage access key /// </summary> public VulnerabilityAssessmentSettingsModel SetVulnerabilityAssessmentSettingsWithStorageAccessKey(VulnerabilityAssessmentSettingsModel model, string serverName, string databaseName, ApplyToType applyToType) { var resourceGroupName = AzureCommunicator.GetStorageResourceGroup(model.StorageAccountName); var storageContainerInfo = VulnerabilityAssessmentCommunicator.GetStorageContainerInfo(resourceGroupName, model.StorageAccountName, model.ScanResultsContainerName); DatabaseVulnerabilityAssessment settings = new DatabaseVulnerabilityAssessment { StorageContainerPath = storageContainerInfo.StorageContainerPath, StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey, RecurringScans = new VulnerabilityAssessmentRecurringScansProperties() { IsEnabled = model.RecurringScansInterval != RecurringScansInterval.None, EmailSubscriptionAdmins = model.EmailAdmins, Emails = model.NotificationEmail } }; var vulnerabilityAssessmentSettings = (applyToType == ApplyToType.Database) ? VulnerabilityAssessmentCommunicator.SetDatabaseVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, databaseName, settings) : VulnerabilityAssessmentCommunicator.SetManagedDatabaseVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, databaseName, settings); return(ConvertSettingsToModel(model.ResourceGroupName, serverName, databaseName, vulnerabilityAssessmentSettings)); }
/// <summary> /// Set settings with storage access key /// </summary> public VulnerabilityAssessmentSettingsModel SetVulnerabilityAssessmentSettingsWithStorageAccessKey(VulnerabilityAssessmentSettingsModel model, string serverName, string databaseName, ApplyToType applyToType) { var resourceGroupName = AzureCommunicator.GetStorageResourceGroup(model.StorageAccountName); var storageContainerInfo = VulnerabilityAssessmentCommunicator.GetStorageContainerInfo(resourceGroupName, model.StorageAccountName, model.ScanResultsContainerName); switch (applyToType) { case ApplyToType.Database: DatabaseVulnerabilityAssessment vaDbSettings = new DatabaseVulnerabilityAssessment { StorageContainerPath = storageContainerInfo.StorageContainerPath, StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey, RecurringScans = new VulnerabilityAssessmentRecurringScansProperties() { IsEnabled = model.RecurringScansInterval != RecurringScansInterval.None, EmailSubscriptionAdmins = model.EmailAdmins, Emails = model.NotificationEmail } }; vaDbSettings = VulnerabilityAssessmentCommunicator.SetDatabaseVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, databaseName, vaDbSettings); return(ConvertSettingsToModel(model.ResourceGroupName, vaDbSettings.RecurringScans, vaDbSettings.StorageContainerPath)); case ApplyToType.ManagedDatabase: DatabaseVulnerabilityAssessment vaManagedDbSettings = new DatabaseVulnerabilityAssessment { StorageContainerPath = storageContainerInfo.StorageContainerPath, StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey, RecurringScans = new VulnerabilityAssessmentRecurringScansProperties() { IsEnabled = model.RecurringScansInterval != RecurringScansInterval.None, EmailSubscriptionAdmins = model.EmailAdmins, Emails = model.NotificationEmail } }; vaManagedDbSettings = VulnerabilityAssessmentCommunicator.SetManagedDatabaseVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, databaseName, vaManagedDbSettings); return(ConvertSettingsToModel(model.ResourceGroupName, vaManagedDbSettings.RecurringScans, vaManagedDbSettings.StorageContainerPath)); case ApplyToType.Server: ServerVulnerabilityAssessment vaServerSettings = new ServerVulnerabilityAssessment { StorageContainerPath = storageContainerInfo.StorageContainerPath, StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey, RecurringScans = new VulnerabilityAssessmentRecurringScansProperties() { IsEnabled = model.RecurringScansInterval != RecurringScansInterval.None, EmailSubscriptionAdmins = model.EmailAdmins, Emails = model.NotificationEmail } }; vaServerSettings = VulnerabilityAssessmentCommunicator.SetServerVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, vaServerSettings); return(ConvertSettingsToModel(model.ResourceGroupName, vaServerSettings.RecurringScans, vaServerSettings.StorageContainerPath)); case ApplyToType.ManagedInstance: ManagedInstanceVulnerabilityAssessment vaManagedInstanceSettings = new ManagedInstanceVulnerabilityAssessment { StorageContainerPath = storageContainerInfo.StorageContainerPath, StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey, RecurringScans = new VulnerabilityAssessmentRecurringScansProperties() { IsEnabled = model.RecurringScansInterval != RecurringScansInterval.None, EmailSubscriptionAdmins = model.EmailAdmins, Emails = model.NotificationEmail } }; vaManagedInstanceSettings = VulnerabilityAssessmentCommunicator.SetManagedInstanceVulnerabilityAssessmentSettings(model.ResourceGroupName, serverName, vaManagedInstanceSettings); return(ConvertSettingsToModel(model.ResourceGroupName, vaManagedInstanceSettings.RecurringScans, vaManagedInstanceSettings.StorageContainerPath)); default: throw new ArgumentOutOfRangeException(nameof(applyToType), applyToType, null); } }