15
15
# limitations under the License.
16
16
#
17
17
18
+ import ipaddress
18
19
import logging
19
20
import re
20
21
@@ -78,7 +79,7 @@ def get_operational_subtype(self) -> str:
78
79
return service_name
79
80
80
81
@staticmethod
81
- def verify_decimal_value (input_value , comparison_value : int ):
82
+ def verify_decimal_value (input_value , max_value : int ):
82
83
try :
83
84
input_float = float (input_value )
84
85
input_int = int (input_float )
@@ -89,7 +90,7 @@ def verify_decimal_value(input_value, comparison_value: int):
89
90
if input_float != input_int :
90
91
return (False , f"Input ({ input_value } ) is not an integer." )
91
92
92
- if input_int <= comparison_value :
93
+ if input_int <= max_value :
93
94
return (True , f"Input ({ input_value } ) is valid." )
94
95
else :
95
96
return (False , f"Input ({ input_value } ) exceeds the allowed value { comparison_value } ." )
@@ -117,13 +118,15 @@ def verify_t_value(self, t_value):
117
118
118
119
@staticmethod
119
120
def contains_ipv6_address (addresses ):
120
- # IPv6 pattern for basic validation
121
- ipv6_pattern = re .compile (r'(?:(?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:))|(?:[0-9a-fA-F]{1,4}:){6}(?::[0-9a-fA-F]{1,4}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){5}(?:(?::[0-9a-fA-F]{1,4}){1,2}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:(?::[0-9a-fA-F]{1,4}){1,3}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(?::[0-9a-fA-F]{1,4}){1,4}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(?::[0-9a-fA-F]{1,4}){1,5}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){1}(?:(?::[0-9a-fA-F]{1,4}){1,6}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?::(?::[0-9a-fA-F]{1,4}){1,7}|:)' , re .VERBOSE )
122
-
123
121
for address in addresses :
124
- if ipv6_pattern .match (address ):
122
+ try :
123
+ # Attempt to create an IPv6 address object. If successful, this is an IPv6 address.
124
+ ipaddress .IPv6Address (address )
125
125
return True , "At least one IPv6 address is present."
126
-
126
+ except ipaddress .AddressValueError :
127
+ # If an AddressValueError is raised, the current address is not a valid IPv6 address.
128
+ # The loop will continue to the next address.
129
+ continue
127
130
return False , "No IPv6 addresses found."
128
131
129
132
@async_test_body
0 commit comments