public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

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

            if (!SynapseAnalyticsClient.TestFirewallRule(ResourceGroupName, WorkspaceName, Name))
            {
                throw new PSInvalidOperationException(string.Format(Resources.FirewallRuleDoesNotExist, Name));
            }

            var originIpFirewallRull = SynapseAnalyticsClient.GetFirewallRule(ResourceGroupName, WorkspaceName, Name);

            IpFirewallRuleInfo ipFirewallRuleInfo = new IpFirewallRuleInfo
            {
                StartIpAddress = StartIpAddress ?? originIpFirewallRull.StartIpAddress,
                EndIpAddress   = EndIpAddress ?? originIpFirewallRull.EndIpAddress,
            };

            if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingFirewallRule, this.WorkspaceName, this.Name)))
            {
                var result = new PSSynapseIpFirewallRule(this.SynapseAnalyticsClient.CreateOrUpdateWorkspaceFirewallRule(this.ResourceGroupName, this.WorkspaceName, this.Name, ipFirewallRuleInfo));
                WriteObject(result);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (ParameterSetName == CreateByNameAllowAllAzureIpParameterSet || ParameterSetName == CreateByParentObjectAllowAllAzureIpParameterSet)
            {
                this.Name           = AllowAllAzureIpRuleName;
                this.StartIpAddress = AllowAllAzureIpRuleStartIp;
                this.EndIpAddress   = AllowAllAzureIpRuleEndIp;
            }

            if (ParameterSetName == CreateByNameAllowAllIpParameterSet || ParameterSetName == CreateByParentObjectAllowAllIpParameterSet)
            {
                this.Name           = AllowAllIpRuleName;
                this.StartIpAddress = AllowAllIpRuleStartIp;
                this.EndIpAddress   = AllowAllIpRuleEndIp;
            }

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

            if (SynapseAnalyticsClient.TestFirewallRule(ResourceGroupName, WorkspaceName, Name))
            {
                throw new PSInvalidOperationException(string.Format(Resources.ConflictFirewallRuleName, Name));
            }

            IpFirewallRuleInfo ipFirewallRuleInfo = new IpFirewallRuleInfo
            {
                StartIpAddress = StartIpAddress,
                EndIpAddress   = EndIpAddress
            };

            if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingFirewallRule, this.WorkspaceName, this.Name)))
            {
                var result = new PSSynapseIpFirewallRule(this.SynapseAnalyticsClient.CreateOrUpdateWorkspaceFirewallRule(this.ResourceGroupName, this.WorkspaceName, this.Name, ipFirewallRuleInfo));
                WriteObject(result);
            }
        }