public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } var result = new PSSqlPoolSecurityAlertPolicy(SynapseAnalyticsClient.GetSqlPoolThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, this.Name), this.ResourceGroupName, this.WorkspaceName, this.Name); WriteObject(result); }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } SqlPoolSecurityAlertPolicy policy = SynapseAnalyticsClient.GetSqlPoolThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, this.Name); policy.State = SecurityAlertPolicyState.Enabled; if (this.IsParameterBound(c => c.NotificationRecipientsEmail)) { policy.EmailAddresses = this.NotificationRecipientsEmail.Split(';').Where(mail => !string.IsNullOrEmpty(mail)).ToList(); } if (this.IsParameterBound(c => c.EmailAdmin)) { policy.EmailAccountAdmins = this.EmailAdmin; } if (this.IsParameterBound(c => c.ExcludedDetectionType)) { policy.DisabledAlerts = Utils.ProcessExcludedDetectionTypes(this.ExcludedDetectionType); } if (this.IsParameterBound(c => c.RetentionInDays)) { policy.RetentionDays = Convert.ToInt32(this.RetentionInDays); } if (this.IsParameterBound(c => c.StorageAccountName)) { policy.StorageEndpoint = string.Format("https://{0}.blob.{1}", this.StorageAccountName, DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix)); } if (!string.IsNullOrEmpty(policy.StorageEndpoint)) { policy.StorageAccountAccessKey = SynapseAnalyticsClient.GetStorageKeys(policy.StorageEndpoint)[StorageKeyKind.Primary]; } else { policy.StorageEndpoint = null; } if (this.ShouldProcess(this.Name, string.Format(Resources.UpdatingSqlPoolThreatProtectionSetting, this.Name, this.WorkspaceName))) { var result = new PSSqlPoolSecurityAlertPolicy(SynapseAnalyticsClient.SetSqlPoolThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, this.Name, policy), this.ResourceGroupName, this.WorkspaceName, this.Name); WriteObject(result); } }