-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix docker linux issue where ip address was not correctly identified.
- Loading branch information
Showing
4 changed files
with
80 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/AzureEventGridSimulator/Infrastructure/ValidationIpAddress.cs
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/AzureEventGridSimulator/Infrastructure/ValidationIpAddressProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
|
||
namespace AzureEventGridSimulator.Infrastructure; | ||
|
||
public class ValidationIpAddressProvider | ||
{ | ||
private static string _ipAddress; | ||
private static readonly object _lock = new(); | ||
|
||
public string Create() | ||
{ | ||
return (NetworkInterface.GetAllNetworkInterfaces() | ||
.SelectMany(o => o.GetIPProperties().DnsAddresses) | ||
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork && | ||
!ip.ToString().StartsWith("172") && | ||
!IPAddress.IsLoopback(ip)) ?? IPAddress.Loopback).ToString(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
lock (_lock) | ||
{ | ||
if (string.IsNullOrWhiteSpace(_ipAddress)) | ||
{ | ||
_ipAddress = Create(); | ||
} | ||
} | ||
|
||
return _ipAddress; | ||
} | ||
|
||
public static implicit operator string(ValidationIpAddressProvider d) | ||
{ | ||
return d.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters