@@ -100,7 +100,9 @@ def request_target_group_data(self, region_name):
100100 cloudtrail_resource_type ,
101101 raw_tg ["TargetGroupArn" ],
102102 ),
103- "targets_health" : self .get_targets_health (raw_tg ["TargetGroupArn" ])
103+ "targets_health" : self .get_targets_health (
104+ raw_tg ["TargetGroupArn" ]
105+ ),
104106 }
105107 )
106108
@@ -172,7 +174,9 @@ def request_load_balancer_data(self, region_name):
172174 ),
173175 "listener_rules" : list (
174176 map (
175- lambda _listener_rule : ListenerRule (_listener_rule , strict = False ),
177+ lambda _listener_rule : ListenerRule (
178+ _listener_rule , strict = False
179+ ),
176180 listener_rules ,
177181 )
178182 ),
@@ -256,7 +260,7 @@ def match_elb_instance(self, target_group, instances):
256260
257261 return match_instances
258262
259- def get_listener_rules (self , raw_listeners : list ):
263+ def get_listener_rules (self , raw_listeners : list ) -> list :
260264 listener_rules = []
261265
262266 for raw_listener in raw_listeners :
@@ -265,7 +269,9 @@ def get_listener_rules(self, raw_listeners: list):
265269
266270 for raw_listener_rule in raw_listener_rules :
267271 is_default = raw_listener_rule .get ("IsDefault" , False )
268- conditions = self .get_formatted_conditions (raw_listener_rule ["Conditions" ], is_default )
272+ conditions = self .get_formatted_conditions (
273+ raw_listener_rule ["Conditions" ], is_default
274+ )
269275 actions = self .get_formatted_actions (raw_listener_rule ["Actions" ])
270276 rule_info = {
271277 "Protocol" : raw_listener .get ("Protocol" ),
@@ -280,9 +286,7 @@ def get_listener_rules(self, raw_listeners: list):
280286 listener_rules .append (rule_info )
281287 except Exception as e :
282288 resource_id = raw_listener .get ("ListenerArn" , "" )
283- error_resource_response = self .generate_error (
284- None , resource_id , e
285- )
289+ error_resource_response = self .generate_error (None , resource_id , e )
286290 _LOGGER .error (error_resource_response )
287291
288292 return listener_rules
@@ -292,16 +296,53 @@ def get_formatted_conditions(raw_conditions: list, is_default: bool) -> list:
292296 str_conditions = []
293297
294298 if is_default :
295- str_conditions .append ("If no other rule applies" )
296- return str_conditions
299+ return ["If no other rule applies" ]
297300
298301 for condition in raw_conditions :
299302 field = condition .get ("Field" )
300- str_value = None
301- if values := condition .get ("Values" ):
302- str_value = ',' .join (values )
303303
304- str_conditions .append (f"{ field } : { str_value } " )
304+ if field == "http-header" :
305+ if config := condition .get ("HttpHeaderConfig" , {}):
306+ header_name = config .get ("HttpHeaderName" )
307+ header_values : list = config .get ("Values" )
308+
309+ if header_name and header_values :
310+ str_value = "," .join (header_values )
311+ str_conditions .append ("HTTP Header :" )
312+ str_conditions .append (f" - { header_name } : { str_value } " )
313+
314+ elif field == "http-request-method" :
315+ if values := condition .get ("HttpRequestMethodConfig" , {}).get ("Values" ):
316+ str_value = "," .join (values )
317+ str_conditions .append (f"HTTP Request Method : { str_value } " )
318+
319+ elif field == "host-header" :
320+ if values := condition .get ("HostHeaderConfig" , {}).get ("Values" ):
321+ str_value = "," .join (values )
322+ str_conditions .append (f"Host Header : { str_value } " )
323+
324+ elif field == "path-pattern" :
325+ if values := condition .get ("PathPatternConfig" , {}).get ("Values" ):
326+ str_value = "," .join (values )
327+ str_conditions .append (f"Path Pattern : { str_value } " )
328+
329+ elif field == "query-string" :
330+ if values := condition .get ("QueryStringConfig" , {}).get ("Values" ):
331+ str_conditions .append ("QueryString :" )
332+
333+ for config in values :
334+ key = config .get ("Key" )
335+ value = config .get ("Value" )
336+
337+ if key :
338+ str_conditions .append (f" - key={ key } : value={ value } " )
339+ else :
340+ str_conditions .append (f" - value={ value } " )
341+
342+ elif field == "source-ip" :
343+ if values := condition .get ("SourceIpConfig" , {}).get ("Values" ):
344+ str_value = "," .join (values )
345+ str_conditions .append (f"Source IP : { str_value } " )
305346
306347 return str_conditions
307348
@@ -315,7 +356,14 @@ def get_formatted_actions(actions: list) -> list:
315356 if action_type == "forward" :
316357 config = action .get ("ForwardConfig" )
317358 target_groups = config .get ("TargetGroups" )
318- stickiness = "on" if config .get ("TargetGroupStickinessConfig" , {}).get ("Enabled" , False ) == True else "off"
359+ stickiness = (
360+ "on"
361+ if config .get ("TargetGroupStickinessConfig" , {}).get (
362+ "Enabled" , False
363+ )
364+ == True
365+ else "off"
366+ )
319367
320368 str_actions .append ("Forward to target group" )
321369
@@ -334,25 +382,29 @@ def get_formatted_actions(actions: list) -> list:
334382 elif action_type == "authenticate-oidc" :
335383 config = action .get ("AuthenticateOidcConfig" )
336384
337- str_actions .extend ([
338- "Authenticate OIDC" ,
339- f" - Issuer: { config .get ('Issuer' )} " ,
340- f" - Client ID: { config .get ('ClientId' )} " ,
341- f" - Scope: { config .get ('Scope' )} " ,
342- f" - On Unauthenticated Request: { config .get ('OnUnauthenticatedRequest' )} " ,
343- ])
385+ str_actions .extend (
386+ [
387+ "Authenticate OIDC" ,
388+ f" - Issuer: { config .get ('Issuer' )} " ,
389+ f" - Client ID: { config .get ('ClientId' )} " ,
390+ f" - Scope: { config .get ('Scope' )} " ,
391+ f" - On Unauthenticated Request: { config .get ('OnUnauthenticatedRequest' )} " ,
392+ ]
393+ )
344394
345395 elif action_type == "authenticate-cognito" :
346396 config = action .get ("AuthenticateCognitoConfig" )
347397
348- str_actions .extend ([
349- "Authenticate Cognito" ,
350- f" - User Pool Arn: { config .get ('UserPoolArn' )} " ,
351- f" - User Pool Client ID: { config .get ('UserPoolClientId' )} " ,
352- f" - User Pool Domain: { config .get ('UserPoolDomain' )} " ,
353- f" - Scope: { config .get ('Scope' )} " ,
354- f" - On Unauthenticated Request: { config .get ('OnUnauthenticatedRequest' )} " ,
355- ])
398+ str_actions .extend (
399+ [
400+ "Authenticate Cognito" ,
401+ f" - User Pool Arn: { config .get ('UserPoolArn' )} " ,
402+ f" - User Pool Client ID: { config .get ('UserPoolClientId' )} " ,
403+ f" - User Pool Domain: { config .get ('UserPoolDomain' )} " ,
404+ f" - Scope: { config .get ('Scope' )} " ,
405+ f" - On Unauthenticated Request: { config .get ('OnUnauthenticatedRequest' )} " ,
406+ ]
407+ )
356408
357409 elif action_type == "redirect" :
358410 config = action .get ("RedirectConfig" )
@@ -372,12 +424,14 @@ def get_formatted_actions(actions: list) -> list:
372424 response_code = config .get ("StatusCode" )
373425 content_type = config .get ("ContentType" )
374426
375- str_actions .extend ([
376- "Return fixed response" ,
377- f" - Response code: { response_code } " ,
378- " - Response body" ,
379- f" - Response content type: { content_type } "
380- ])
427+ str_actions .extend (
428+ [
429+ "Return fixed response" ,
430+ f" - Response code: { response_code } " ,
431+ " - Response body" ,
432+ f" - Response content type: { content_type } " ,
433+ ]
434+ )
381435
382436 return str_actions
383437
0 commit comments