/// <summary> /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint /// </summary> private DatabaseSecurityAlertPolicy PolicizeDatabaseSecurityAlertModel(BaseThreatDetectionPolicyModel model, string storageEndpointSuffix) { var policy = new DatabaseSecurityAlertPolicy() { State = model.ThreatDetectionState == ThreatDetectionStateType.Enabled ? SecurityAlertsPolicyState.Enabled : SecurityAlertsPolicyState.Disabled, DisabledAlerts = ExtractExcludedDetectionType(model), EmailAddresses = model.NotificationRecipientsEmails.Split(';').Where(mail => !string.IsNullOrEmpty(mail)).ToList(), EmailAccountAdmins = model.EmailAdmins, RetentionDays = Convert.ToInt32(model.RetentionInDays), }; if (string.IsNullOrEmpty(model.StorageAccountName)) { policy.StorageEndpoint = null; policy.StorageAccountAccessKey = null; } else { BaseSecurityAlertPolicyProperties legacyProperties = new BaseSecurityAlertPolicyProperties(); PopulateStoragePropertiesInPolicy(model, legacyProperties, storageEndpointSuffix); policy.StorageEndpoint = legacyProperties.StorageEndpoint; policy.StorageAccountAccessKey = legacyProperties.StorageAccountAccessKey; } return(policy); }
/// <summary> /// Transforms the given database policy object to its cmdlet model representation /// </summary> private DatabaseThreatDetectionPolicyModel ModelizeDatabaseThreatDetectionPolicy(DatabaseSecurityAlertPolicy threatDetectionPolicy) { DatabaseThreatDetectionPolicyModel databaseThreatDetectionPolicyModel = new DatabaseThreatDetectionPolicyModel(); DatabaseSecurityAlertPolicyProperties threatDetectionProperties = threatDetectionPolicy.Properties; databaseThreatDetectionPolicyModel.ThreatDetectionState = ModelizeThreatDetectionState(threatDetectionProperties.State); databaseThreatDetectionPolicyModel.NotificationRecipientsEmails = threatDetectionProperties.EmailAddresses; databaseThreatDetectionPolicyModel.EmailAdmins = ModelizeThreatDetectionEmailAdmins(threatDetectionProperties.EmailAccountAdmins); ModelizeDisabledAlerts(databaseThreatDetectionPolicyModel, threatDetectionProperties.DisabledAlerts); return databaseThreatDetectionPolicyModel; }