File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change
1
+ import ipaddress
1
2
import threading
2
3
import time
3
4
import logging
9
10
from concurrent .futures import ThreadPoolExecutor
10
11
11
12
13
+
12
14
class ExecutorPool :
13
15
def __init__ (self ):
14
16
self ._executor = None
@@ -45,6 +47,7 @@ class Config:
45
47
port : int = 8080
46
48
datacenter : str = None
47
49
rack : str = None
50
+ client_cert : str = None
48
51
aws_region_name : str = "fake-alternator-lb-region"
49
52
aws_access_key_id : str = "fake-alternator-lb-access-key-id"
50
53
aws_secret_access_key : str = "fake-alternator-lb-secret-access-key"
@@ -105,10 +108,12 @@ def __init__(self, config: Config):
105
108
self ._next_update_time = 0
106
109
107
110
@staticmethod
108
- def _validate_uri (uri : str ):
109
- parsed_uri = urlparse (uri )
110
- if not parsed_uri .scheme or not parsed_uri .netloc :
111
- raise ValueError (f"Invalid URI: { uri } " )
111
+ def _validate_node (node : str ) -> bool :
112
+ try :
113
+ ipaddress .ip_address (node )
114
+ return True
115
+ except ValueError :
116
+ return False
112
117
113
118
def _update_nodes_if_needed (self ):
114
119
if self ._updating :
@@ -162,7 +167,7 @@ def _get_nodes(self, uri: str) -> List[str]:
162
167
return []
163
168
164
169
nodes = response .json ()
165
- return [self ._host_to_uri (host ) for host in nodes if host ]
170
+ return [self ._host_to_uri (host ) for host in nodes if host and self . _validate_node ( host ) ]
166
171
except Exception as e :
167
172
self ._logger .warning (f"Failed to fetch nodes from { uri } : { e } " )
168
173
return []
You can’t perform that action at this time.
0 commit comments