public override void Execute()
        {
            base.Execute();

            // Add some validation based on the type of RuleCollection (SNAT will be supported later)
            // if (MNM.AzureFirewallNatRCActionType.Dnat.Equals(ActionType))
            {
                if (DestinationAddress.Length != 1)
                {
                    throw new ArgumentException("Only one destination address is accepted.", nameof(DestinationAddress));
                }

                if (DestinationPort.Length != 1)
                {
                    throw new ArgumentException("Only one destination port is accepted.", nameof(DestinationPort));
                }

                ValidateIsSingleIpNotRange(DestinationAddress.Single());
                if (TranslatedAddress != null)
                {
                    ValidateIsSingleIpNotRange(TranslatedAddress);
                }
                if (TranslatedFqdn != null)
                {
                    ValidateIsFqdn(TranslatedFqdn);
                }

                // Only one of TranslatedAddress or TranslatedFqdn is allowed
                if ((TranslatedAddress != null) && (TranslatedFqdn != null))
                {
                    throw new ArgumentException("Both TranslatedAddress and TranslatedFqdn not allowed");
                }

                // One of TranslatedAddress or TranslatedFqdn must be present
                if ((TranslatedAddress == null) && (TranslatedFqdn == null))
                {
                    throw new ArgumentException("Either TranslatedAddress or TranslatedFqdn is required");
                }

                ValidateIsSinglePortNotRange(DestinationPort.Single());
                ValidateIsSinglePortNotRange(TranslatedPort);
            }

            var networkRule = new PSAzureFirewallNatRule
            {
                Name                 = this.Name,
                Description          = this.Description,
                Protocols            = this.Protocol?.ToList(),
                SourceAddresses      = this.SourceAddress?.ToList(),
                DestinationAddresses = this.DestinationAddress?.ToList(),
                DestinationPorts     = this.DestinationPort?.ToList(),
                TranslatedAddress    = this.TranslatedAddress,
                TranslatedFqdn       = this.TranslatedFqdn,
                TranslatedPort       = this.TranslatedPort
            };

            WriteObject(networkRule);
        }
Ejemplo n.º 2
0
        public override void Execute()
        {
            base.Execute();

            // Add some validation based on the type of RuleCollection (SNAT will be supported later)
            // if (MNM.AzureFirewallNatRCActionType.Dnat.Equals(ActionType))
            {
                if (DestinationAddress.Length != 1)
                {
                    throw new ArgumentException("Only one destination address is accepted.", nameof(DestinationAddress));
                }

                if (DestinationPort.Length != 1)
                {
                    throw new ArgumentException("Only one destination port is accepted.", nameof(DestinationPort));
                }

                ValidateIsSingleIpNotRange(DestinationAddress.Single());
                ValidateIsSingleIpNotRange(TranslatedAddress);

                ValidateIsSinglePortNotRange(DestinationPort.Single());
                ValidateIsSinglePortNotRange(TranslatedPort);
            }

            var networkRule = new PSAzureFirewallNatRule
            {
                Name                 = this.Name,
                Description          = this.Description,
                Protocols            = this.Protocol?.ToList(),
                SourceAddresses      = this.SourceAddress?.ToList(),
                DestinationAddresses = this.DestinationAddress?.ToList(),
                DestinationPorts     = this.DestinationPort?.ToList(),
                TranslatedAddress    = this.TranslatedAddress,
                TranslatedPort       = this.TranslatedPort
            };

            WriteObject(networkRule);
        }