1313 r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4,5}\/(.)+"
1414)
1515
16-
1716def db_connect (
1817 interface = "psql" ,
1918 host = None ,
@@ -126,7 +125,6 @@ def cluster_dict(endpoint, is_serverless=False, start_time=None, end_time=None):
126125
127126 return cluster
128127
129-
130128def bucket_dict (bucket_url ):
131129 bucket , path = None , None
132130 try :
@@ -146,7 +144,6 @@ def bucket_dict(bucket_url):
146144 path = ""
147145 return {"url" : bucket_url , "bucket_name" : bucket , "prefix" : path }
148146
149-
150147def matches_filters (obj , filters ):
151148 """Check if the object matches the filters. The object just needs to
152149 provide a supported_filters() function. This also assumes filters has already
@@ -171,23 +168,26 @@ def matches_filters(obj, filters):
171168 else :
172169 return False
173170
174-
175171def get_connection_key (database_name , username , pid ):
176172 return f"{ database_name } _{ username } _{ pid } "
177173
178-
179174def is_serverless (config ):
180- if ".com.cn" in config ["target_cluster_endpoint" ] and len (config ["target_cluster_endpoint" ].split ("." )) == 7 :
181- serverless_cluster_endpoint_pattern = (r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com\.cn:[0-9]{4,5}\/(.)+" )
182- return bool (
183- re .fullmatch (serverless_cluster_endpoint_pattern , config ["target_cluster_endpoint" ])
184- )
185-
175+ endpoint = config ["target_cluster_endpoint" ]
176+
177+ # Determine the domain suffix based on region
178+ if ".com.cn" in endpoint and len (endpoint .split ("." )) == 7 :
179+ domain_suffix = "amazonaws.com.cn"
180+ else :
181+ domain_suffix = "amazonaws.com"
182+
183+ # Build the pattern dynamically
184+ pattern = rf"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.{ domain_suffix } :[0-9]{{4,5}}\/(.)+"
185+
186+ return bool (re .fullmatch (pattern , endpoint ))
186187
187188def current_offset_ms (ref_time ):
188189 return (datetime .datetime .now (tz = datetime .timezone .utc ) - ref_time ).total_seconds () * 1000.0
189190
190-
191191# exception thrown if credentials can't be retrieved
192192class CredentialsException (Exception ):
193193 pass
0 commit comments