File tree Expand file tree Collapse file tree 1 file changed +56
-2
lines changed
src/Network/Network/Models/AzureFirewall Expand file tree Collapse file tree 1 file changed +56
-2
lines changed Original file line number Diff line number Diff line change 15
15
16
16
namespace Microsoft . Azure . Commands . Network . Models
17
17
{
18
+ using System ;
19
+ using System . Management . Automation ;
20
+ using System . Net ;
21
+ using System . Text . RegularExpressions ;
22
+
18
23
public class PSAzureFirewallThreatIntelWhitelist
19
24
{
20
- public string [ ] FQDNs { get ; set ; }
25
+ private string [ ] fqdns ;
26
+
27
+ private string [ ] ipAddresses ;
28
+
29
+ public string [ ] FQDNs {
30
+ get { return this . fqdns ; }
31
+ set
32
+ {
33
+ fqdns = value ;
34
+ ValidateFqdns ( ) ;
35
+ }
36
+ }
37
+
38
+ public string [ ] IpAddresses
39
+ {
40
+ get { return this . ipAddresses ; }
41
+ set
42
+ {
43
+ ipAddresses = value ;
44
+ ValidateIpAddresses ( ) ;
45
+ }
46
+ }
47
+
48
+ private const string SecureGatewayThreatIntelFqdnRegex = "^\\ *?([a-zA-Z0-9\\ -\\ .]?[a-zA-Z0-9])*$" ;
49
+
50
+ private void ValidateFqdns ( )
51
+ {
52
+ if ( fqdns == null )
53
+ return ;
54
+ foreach ( var fqdn in fqdns )
55
+ {
56
+ var matchingRegEx = new Regex ( SecureGatewayThreatIntelFqdnRegex ) ;
57
+ if ( ! matchingRegEx . IsMatch ( fqdn ) )
58
+ {
59
+ throw new PSArgumentException ( String . Format ( "\' {0}\' is not a valid threat intel whitelist FQDN" , fqdn ) ) ;
60
+ }
61
+ }
62
+ }
21
63
22
- public string [ ] IpAddresses { get ; set ; }
64
+ private void ValidateIpAddresses ( )
65
+ {
66
+ if ( IpAddresses == null )
67
+ return ;
68
+ foreach ( var ip in IpAddresses )
69
+ {
70
+ IPAddress ipVal ;
71
+ if ( ! IPAddress . TryParse ( ip , out ipVal ) || ipVal . AddressFamily != System . Net . Sockets . AddressFamily . InterNetwork )
72
+ {
73
+ throw new PSArgumentException ( String . Format ( "\' {0}\' is not a valid threat intel whitelist Ip Address" , ip ) ) ;
74
+ }
75
+ }
76
+ }
23
77
}
24
78
}
You can’t perform that action at this time.
0 commit comments