public async Task CreateOrUpdate()
        {
            AzureFirewall firewall = await CreateFirewallAsync();

            Assert.IsNotNull(firewall.Data);
            Assert.AreEqual(_firewallName, firewall.Data.Name);
        }
Esempio n. 2
0
        public async Task <Response <AzureFirewall> > GetAsync(string resourceGroupName, string azureFirewallName, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (azureFirewallName == null)
            {
                throw new ArgumentNullException(nameof(azureFirewallName));
            }

            using var message = CreateGetRequest(resourceGroupName, azureFirewallName);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                AzureFirewall value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                if (document.RootElement.ValueKind == JsonValueKind.Null)
                {
                    value = null;
                }
                else
                {
                    value = AzureFirewall.DeserializeAzureFirewall(document.RootElement);
                }
                return(Response.FromValue(value, message.Response));
            }
Esempio n. 3
0
 public async Task Teardown()
 {
     if (await _resourceGroup.GetAzureFirewalls().CheckIfExistsAsync(_firewallName))
     {
         AzureFirewall firewall = await _resourceGroup.GetAzureFirewalls().GetAsync(_firewallName);
         await firewall.DeleteAsync();
     }
 }
        public PSAzureFirewall ToPsAzureFirewall(AzureFirewall firewall)
        {
            var azureFirewall = NetworkResourceManagerProfile.Mapper.Map <PSAzureFirewall>(firewall);

            azureFirewall.Tag = TagsConversionHelper.CreateTagHashtable(firewall.Tags);

            return(azureFirewall);
        }
Esempio n. 5
0
        public async Task Teardown()
        {
            if (await _resourceGroup.GetAzureFirewalls().ExistsAsync(_firewallName))
            {
                AzureFirewall firewall = await _resourceGroup.GetAzureFirewalls().GetAsync(_firewallName);

                await firewall.DeleteAsync(WaitUntil.Completed);
            }
        }
Esempio n. 6
0
        public async Task Delete()
        {
            AzureFirewall firewall = await CreateFirewallAsync();
            List<AzureFirewall> firewallList = await _resourceGroup.GetAzureFirewalls().GetAllAsync().ToEnumerableAsync();
            Assert.AreEqual(1, firewallList.Count);

            await firewall.DeleteAsync();
            firewallList = await _resourceGroup.GetAzureFirewalls().GetAllAsync().ToEnumerableAsync();
            Assert.AreEqual(0, firewallList.Count);
        }
        public async Task TestSetUp()
        {
            var client = GetArmClient();

            _resourceGroup = await client.GetResourceGroup(_resourceGroupIdentifier).GetAsync();

            _network = await _resourceGroup.GetVirtualNetworks().GetAsync(_networkIdentifier.Name);

            _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name);

            _firewall = await _resourceGroup.GetAzureFirewalls().GetAsync(_firewallIdentifier.Name);
        }
 /// <summary>
 /// Creates or updates the specified Azure Firewall.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='azureFirewallName'>
 /// The name of the Azure Firewall.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update Azure Firewall operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AzureFirewall> BeginCreateOrUpdateAsync(this IAzureFirewallsOperations operations, string resourceGroupName, string azureFirewallName, AzureFirewall parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, azureFirewallName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates the specified Azure Firewall.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='azureFirewallName'>
 /// The name of the Azure Firewall.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update Azure Firewall operation.
 /// </param>
 public static AzureFirewall BeginCreateOrUpdate(this IAzureFirewallsOperations operations, string resourceGroupName, string azureFirewallName, AzureFirewall parameters)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, azureFirewallName, parameters).GetAwaiter().GetResult());
 }
Esempio n. 10
0
        public virtual AzureFirewallsCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string azureFirewallName, AzureFirewall parameters, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (azureFirewallName == null)
            {
                throw new ArgumentNullException(nameof(azureFirewallName));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _clientDiagnostics.CreateScope("AzureFirewallsClient.StartCreateOrUpdate");
            scope.Start();
            try
            {
                var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, azureFirewallName, parameters, cancellationToken);
                return(new AzureFirewallsCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, azureFirewallName, parameters).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async Task GlobalSetUp()
        {
            Subscription subscription = await GlobalClient.GetDefaultSubscriptionAsync();

            var rgLro = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("FirewallPolicyRG-"), new ResourceGroupData(AzureLocation.WestUS2));

            ResourceGroup rg = rgLro.Value;

            _resourceGroupIdentifier = rg.Id;

            VirtualNetworkData vnetData = new VirtualNetworkData()
            {
                Location     = AzureLocation.WestUS2,
                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.26.0.0/16", }
                },
                Subnets =
                {
                    new SubnetData()
                    {
                        Name = "Default", AddressPrefix = "10.26.1.0/26",
                    },
                    new SubnetData()
                    {
                        Name = "AzureFirewallSubnet", AddressPrefix = "10.26.2.0/26",
                    },
                },
            };
            var vnetLro = await rg.GetVirtualNetworks().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("vnet-"), vnetData);

            _network           = vnetLro.Value;
            _networkIdentifier = _network.Id;

            PublicIPAddressData ipData = new PublicIPAddressData()
            {
                Location = AzureLocation.WestUS2,
                PublicIPAllocationMethod = IPAllocationMethod.Static,
                Sku = new PublicIPAddressSku()
                {
                    Name = PublicIPAddressSkuName.Standard
                },
            };
            var ipLro = await rg.GetPublicIPAddresses().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("publicIp-"), ipData);

            _publicIPAddress           = ipLro.Value;
            _publicIPAddressIdentifier = _publicIPAddress.Id;

            AzureFirewallData firewallData = new AzureFirewallData();

            firewallData.Location = AzureLocation.WestUS2;
            firewallData.IPConfigurations.Add(new AzureFirewallIPConfiguration()
            {
                Name            = "fwpip",
                PublicIPAddress = new WritableSubResource()
                {
                    Id = _publicIPAddressIdentifier
                },
                Subnet = new WritableSubResource()
                {
                    Id = _networkIdentifier.AppendChildResource("subnets", "AzureFirewallSubnet")
                },
            });
            var firewallLro = await rg.GetAzureFirewalls().CreateOrUpdateAsync(true, SessionRecording.GenerateAssetName("firewall-"), firewallData);

            _firewall           = firewallLro.Value;
            _firewallIdentifier = _firewall.Id;

            await StopSessionRecordingAsync();
        }