示例#1
0
        public override void Execute()
        {
            base.Execute();

            var present = NetworkBaseCmdlet.IsResourcePresent(() => GetAzureFirewallPolicy(this.ResourceGroupName, this.Name));

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () => WriteObject(this.CreateAzureFirewallPolicy()),
                () => present);
        }
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(c => c.LoadBalancer))
            {
                this.ResourceGroupName = this.LoadBalancer.ResourceGroupName;
                this.LoadBalancerName  = this.LoadBalancer.Name;
            }

            if (this.IsParameterBound(c => c.InputObject) || this.IsParameterBound(p => p.ResourceId))
            {
                var id = this.IsParameterBound(c => c.InputObject) ? this.InputObject.Id : this.ResourceId;
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(id);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.LoadBalancerName  = resourceIdentifier.ParentResource.Split('/')[1];
                this.Name = resourceIdentifier.ResourceName;
            }

            // check if resource already exists
            var found = NetworkBaseCmdlet.IsResourcePresent(
                () => this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.Get(
                    this.ResourceGroupName,
                    this.LoadBalancerName,
                    this.Name));

            if (!found)
            {
                throw new ArgumentException(string.Format(Properties.Resources.ResourceNotFound, this.Name));
            }
            // this prompts user to confirm the deletion of the backend pool
            if (ShouldProcess(Name, Microsoft.Azure.Commands.Network.Properties.Resources.RemoveResourceMessage))
            {
                this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.Delete(this.ResourceGroupName,
                                                                                                  this.LoadBalancerName, this.Name);

                if (this.PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            }
        }
示例#3
0
 public bool IsVirtualNetworkGatewayNatRulePresent(string resourceGroupName, string parentGatewayName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetVirtualNetworkGatewayNatRule(resourceGroupName, parentGatewayName, name); }));
 }
 public bool IsVpnConnectionPresent(string resourceGroupName, string parentVpnGatewayName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetVpnConnection(resourceGroupName, parentVpnGatewayName, name); }));
 }
 public bool IsP2SVpnGatewayPresent(string resourceGroupName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetP2SVpnGateway(resourceGroupName, name); }));
 }
 public bool IsVpnServerConfigurationPresent(string resourceGroupName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetVpnServerConfiguration(resourceGroupName, name); }));
 }
示例#7
0
 public bool IsHubVnetConnectionPresent(string resourceGroupName, string parentHubName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetHubVirtualNetworkConnection(resourceGroupName, parentHubName, name); }));
 }
示例#8
0
 public bool IsVpnSitePresent(string resourceGroupName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetVpnSite(resourceGroupName, name); }));
 }
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceInfo = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceInfo.ResourceGroupName;
                Name = resourceInfo.ResourceName;
            }
            else if (this.IsParameterBound(c => c.InputObject))
            {
                ResourceGroupName = InputObject.ResourceGroupName;
                Name = InputObject.Name;
            }

            if (!NetworkBaseCmdlet.IsResourcePresent(() => GetAzureFirewallPolicy(ResourceGroupName, Name)))
            {
                throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                this.Location                          = this.IsParameterBound(c => c.Location) ? Location : InputObject.Location;
                this.ThreatIntelMode                   = this.IsParameterBound(c => c.ThreatIntelMode) ? ThreatIntelMode : InputObject.ThreatIntelMode;
                this.ThreatIntelWhitelist              = this.IsParameterBound(c => c.ThreatIntelWhitelist) ? ThreatIntelWhitelist : InputObject.ThreatIntelWhitelist;
                this.BasePolicy                        = this.IsParameterBound(c => c.BasePolicy) ? BasePolicy : (InputObject.BasePolicy != null ? InputObject.BasePolicy.Id : null);
                this.DnsSetting                        = this.IsParameterBound(c => c.DnsSetting) ? DnsSetting : (InputObject.DnsSettings != null ? InputObject.DnsSettings : null);
                this.IntrusionDetection                = this.IsParameterBound(c => c.IntrusionDetection) ? IntrusionDetection : (InputObject.IntrusionDetection != null ? InputObject.IntrusionDetection : null);
                this.TransportSecurityName             = this.IsParameterBound(c => c.TransportSecurityName) ? TransportSecurityName : (InputObject.TransportSecurity?.CertificateAuthority != null ? InputObject.TransportSecurity.CertificateAuthority.Name : null);
                this.TransportSecurityKeyVaultSecretId = this.IsParameterBound(c => c.TransportSecurityKeyVaultSecretId) ? TransportSecurityKeyVaultSecretId : (InputObject.TransportSecurity?.CertificateAuthority != null ? InputObject.TransportSecurity.CertificateAuthority.KeyVaultSecretId : null);
                this.Identity                          = this.IsParameterBound(c => c.Identity) ? Identity : (InputObject.Identity != null ? InputObject.Identity : null);
                this.UserAssignedIdentityId            = this.IsParameterBound(c => c.UserAssignedIdentityId) ? UserAssignedIdentityId : (InputObject.Identity?.UserAssignedIdentities != null ? InputObject.Identity.UserAssignedIdentities?.First().Key : null);
                this.SkuTier      = this.IsParameterBound(c => c.SkuTier) ? SkuTier : (InputObject.Sku?.Tier != null ? InputObject.Sku.Tier : null);
                this.PrivateRange = this.IsParameterBound(c => c.PrivateRange) ? PrivateRange : InputObject.PrivateRange;

                var firewallPolicy = new PSAzureFirewallPolicy()
                {
                    Name = this.Name,
                    ResourceGroupName    = this.ResourceGroupName,
                    Location             = this.Location,
                    ThreatIntelMode      = this.ThreatIntelMode ?? MNM.AzureFirewallThreatIntelMode.Alert,
                    ThreatIntelWhitelist = this.ThreatIntelWhitelist,
                    BasePolicy           = this.BasePolicy != null ? new Microsoft.Azure.Management.Network.Models.SubResource(this.BasePolicy) : null,
                    DnsSettings          = this.DnsSetting,
                    PrivateRange         = this.PrivateRange
                };

                AddPremiumProperties(firewallPolicy);

                var azureFirewallPolicyModel = NetworkResourceManagerProfile.Mapper.Map <MNM.FirewallPolicy>(firewallPolicy);

                // Execute the PUT AzureFirewall Policy call
                this.AzureFirewallPolicyClient.CreateOrUpdate(ResourceGroupName, Name, azureFirewallPolicyModel);
                var getAzureFirewall = this.GetAzureFirewallPolicy(ResourceGroupName, Name);
                WriteObject(getAzureFirewall);
            }
            else
            {
                var firewallPolicy = new PSAzureFirewallPolicy()
                {
                    Name = this.Name,
                    ResourceGroupName    = this.ResourceGroupName,
                    Location             = this.Location,
                    ThreatIntelMode      = this.ThreatIntelMode ?? MNM.AzureFirewallThreatIntelMode.Alert,
                    ThreatIntelWhitelist = this.ThreatIntelWhitelist,
                    BasePolicy           = BasePolicy != null ? new Microsoft.Azure.Management.Network.Models.SubResource(BasePolicy) : null,
                    DnsSettings          = this.DnsSetting,
                    PrivateRange         = this.PrivateRange
                };

                AddPremiumProperties(firewallPolicy);

                // Map to the sdk object
                var azureFirewallPolicyModel = NetworkResourceManagerProfile.Mapper.Map <MNM.FirewallPolicy>(firewallPolicy);
                azureFirewallPolicyModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

                // Execute the Create AzureFirewall call
                this.AzureFirewallPolicyClient.CreateOrUpdate(this.ResourceGroupName, this.Name, azureFirewallPolicyModel);
                var getAzureFirewallPolicy = this.GetAzureFirewallPolicy(ResourceGroupName, Name);
                WriteObject(getAzureFirewallPolicy);
            }
        }
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceInfo = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceInfo.ResourceGroupName;
                Name = resourceInfo.ResourceName;
            }
            else if (this.IsParameterBound(c => c.InputObject))
            {
                ResourceGroupName = InputObject.ResourceGroupName;
                Name = InputObject.Name;
            }

            if (!NetworkBaseCmdlet.IsResourcePresent(() => GetAzureFirewallPolicy(ResourceGroupName, Name)))
            {
                throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                this.Location        = this.IsParameterBound(c => c.Location) ? Location : InputObject.Location;
                this.ThreatIntelMode = this.IsParameterBound(c => c.ThreatIntelMode) ? ThreatIntelMode : InputObject.ThreatIntelMode;
                this.BasePolicy      = this.IsParameterBound(c => c.BasePolicy) ? BasePolicy : (InputObject.BasePolicy != null ? InputObject.BasePolicy.Id : null);

                var firewallPolicy = new PSAzureFirewallPolicy()
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Location          = this.Location,
                    ThreatIntelMode   = this.ThreatIntelMode ?? MNM.AzureFirewallThreatIntelMode.Alert,
                    BasePolicy        = this.BasePolicy != null ? new Microsoft.Azure.Management.Network.Models.SubResource(this.BasePolicy) : null
                };


                var azureFirewallPolicyModel = NetworkResourceManagerProfile.Mapper.Map <MNM.FirewallPolicy>(firewallPolicy);
                // Execute the PUT AzureFirewall Policy call
                this.AzureFirewallPolicyClient.CreateOrUpdate(ResourceGroupName, Name, azureFirewallPolicyModel);
                var getAzureFirewall = this.GetAzureFirewallPolicy(ResourceGroupName, Name);
                WriteObject(getAzureFirewall);
            }
            else
            {
                var firewallPolicy = new PSAzureFirewallPolicy()
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName,
                    Location          = this.Location,
                    ThreatIntelMode   = this.ThreatIntelMode ?? MNM.AzureFirewallThreatIntelMode.Alert,
                    BasePolicy        = BasePolicy != null ? new Microsoft.Azure.Management.Network.Models.SubResource(BasePolicy) : null
                };

                // Map to the sdk object
                var azureFirewallPolicyModel = NetworkResourceManagerProfile.Mapper.Map <MNM.FirewallPolicy>(firewallPolicy);
                azureFirewallPolicyModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

                // Execute the Create AzureFirewall call
                this.AzureFirewallPolicyClient.CreateOrUpdate(this.ResourceGroupName, this.Name, azureFirewallPolicyModel);
                var getAzureFirewallPolicy = this.GetAzureFirewallPolicy(ResourceGroupName, Name);
                WriteObject(getAzureFirewallPolicy);
            }
        }
 public bool IsVirtualHubRouteTablePresent(string resourceGroupName, string parentHubName, string name)
 {
     return(NetworkBaseCmdlet.IsResourcePresent(() => { GetVirtualHubRouteTable(resourceGroupName, parentHubName, name); }));
 }