Skip to content

Commit

Permalink
Bump AzureIPNetworks from 1.6.0 to 1.7.0 (#203)
Browse files Browse the repository at this point in the history
* Bump AzureIPNetworks from 1.6.0 to 1.7.0

Bumps [AzureIPNetworks](https://github.com/mburumaxwell/AzureIPNetworks) from 1.6.0 to 1.7.0.
- [Release notes](https://github.com/mburumaxwell/AzureIPNetworks/releases)
- [Commits](mburumaxwell/AzureIPNetworks@1.6.0...1.7.0)

---
updated-dependencies:
- dependency-name: AzureIPNetworks
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* React to changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Maxwell Weru <[email protected]>
  • Loading branch information
dependabot[bot] and mburumaxwell authored Jan 24, 2024
1 parent 00734f2 commit eec9971
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ namespace Tingle.AspNetCore.Authorization;
/// An <see cref="IAuthorizationRequirement"/> that contains IP networks
/// </summary>
/// <param name="networks">the networks allowed</param>
#if NET8_0_OR_GREATER
public sealed class ApprovedIPNetworkRequirement(IList<IPNetwork> networks) : IAuthorizationRequirement
#else
public sealed class ApprovedIPNetworkRequirement(IList<IPNetwork2> networks) : IAuthorizationRequirement
#endif
{
/// <summary>
/// Checks is an instance of <see cref="IPAddress"/> is approved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ public static class AuthorizationPolicyBuilderExtensions
/// </summary>
/// <param name="builder">The instance to add to</param>
/// <param name="networks">The allowed networks</param>
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
IList<IPNetwork> networks)
#if NET8_0_OR_GREATER
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, IList<IPNetwork> networks)
#else
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, IList<IPNetwork2> networks)
#endif
{
// if there are no networks just return
if (!networks.Any()) return builder;

// reduce the networks where possible (referred to as supernetting)
#if !NET8_0_OR_GREATER
networks = IPNetwork.Supernet([.. networks]);
networks = IPNetwork2.Supernet([.. networks]);
#endif

// add the requirement
Expand All @@ -41,10 +44,13 @@ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this Authorizat
/// </summary>
/// <param name="builder">The instance to add to</param>
/// <param name="networks">The allowed networks</param>
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
params string[] networks)
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params string[] networks)
{
#if NET8_0_OR_GREATER
var parsed = networks.Select(a => IPNetwork.Parse(a)).ToList();
#else
var parsed = networks.Select(a => IPNetwork2.Parse(a)).ToList();
#endif
return builder.RequireApprovedNetworks(parsed);
}

Expand All @@ -55,8 +61,11 @@ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this Authorizat
/// </summary>
/// <param name="builder">The instance to add to</param>
/// <param name="networks">The allowed networks</param>
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
params IPNetwork[] networks)
#if NET8_0_OR_GREATER
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params IPNetwork[] networks)
#else
public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params IPNetwork2[] networks)
#endif
{
return builder.RequireApprovedNetworks(networks.ToList());
}
Expand Down Expand Up @@ -122,10 +131,13 @@ public static AuthorizationPolicyBuilder RequireAzureIPNetworks(this Authorizati
/// A list of Fully Qualified Domain Names.
/// Each of them will be resolved to list of IP addresses using <see cref="Dns.GetHostAddresses(string)"/>
/// </param>
public static AuthorizationPolicyBuilder RequireNetworkFromDns(this AuthorizationPolicyBuilder builder,
params string[] fqdns)
public static AuthorizationPolicyBuilder RequireNetworkFromDns(this AuthorizationPolicyBuilder builder, params string[] fqdns)
{
#if NET8_0_OR_GREATER
var networks = new List<IPNetwork>();
#else
var networks = new List<IPNetwork2>();
#endif

// work on each FQDN
foreach (var f in fqdns)
Expand All @@ -136,7 +148,11 @@ public static AuthorizationPolicyBuilder RequireNetworkFromDns(this Authorizatio
var ips = Dns.GetHostAddresses(f);

// parse the IP addresses into IP networks
#if NET8_0_OR_GREATER
var rawNetworks = ips?.Select(ip => new IPNetwork(ip, (byte)(ip.AddressFamily is AddressFamily.InterNetwork ? 32 : 128)));
#else
var rawNetworks = ips?.Select(ip => new IPNetwork2(ip, (byte)(ip.AddressFamily is AddressFamily.InterNetwork ? 32 : 128)));
#endif

// add networks into the list if there are any
if (rawNetworks?.Any() ?? false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AzureIPNetworks" Version="1.6.0" />
<PackageReference Include="AzureIPNetworks" Version="1.7.0" />
</ItemGroup>

</Project>

0 comments on commit eec9971

Please sign in to comment.