Exemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ResourceName;
            }

            if (string.IsNullOrEmpty(this.ResourceGroupName))
            {
                this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
            }

            var result = new PSServerSecurityAlertPolicy(SynapseAnalyticsClient.GetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName),
                                                         this.ResourceGroupName, this.WorkspaceName);

            WriteObject(result);
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ResourceName;
            }

            if (string.IsNullOrEmpty(this.ResourceGroupName))
            {
                this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
            }

            ServerSecurityAlertPolicy policy = SynapseAnalyticsClient.GetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName);

            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.WorkspaceName, string.Format(Resources.UpdatingThreatProtectionSetting, this.WorkspaceName)))
            {
                var result = new PSServerSecurityAlertPolicy(SynapseAnalyticsClient.SetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, policy),
                                                             this.ResourceGroupName, this.WorkspaceName);
                WriteObject(result);
            }
        }