From 590c2da3de3fa340add18d7900df6fc6e2f1ec89 Mon Sep 17 00:00:00 2001 From: Ryan Jung Date: Thu, 9 Jan 2025 12:14:44 -0700 Subject: [PATCH] Lint with newer ruff --- tb_pulumi/__init__.py | 3 +-- tb_pulumi/cloudwatch.py | 38 +++++++++++++++++++------------------- tb_pulumi/network.py | 4 ++-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tb_pulumi/__init__.py b/tb_pulumi/__init__.py index d7107d5..994c49b 100644 --- a/tb_pulumi/__init__.py +++ b/tb_pulumi/__init__.py @@ -136,8 +136,7 @@ def __init__( if self.protect_resources: pulumi.info( - f'Resource protection has been enabled on {name}. ' - 'To disable, export TBPULUMI_DISABLE_PROTECTION=True' + f'Resource protection has been enabled on {name}. To disable, export TBPULUMI_DISABLE_PROTECTION=True' ) # Merge provided opts with defaults before calling superconstructor diff --git a/tb_pulumi/cloudwatch.py b/tb_pulumi/cloudwatch.py index 9420659..4323735 100644 --- a/tb_pulumi/cloudwatch.py +++ b/tb_pulumi/cloudwatch.py @@ -223,13 +223,13 @@ def __init__( alb_5xx = pulumi.Output.all(res_name=resource.name, res_suffix=resource.arn_suffix).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-alb5xx', - name=f'{outputs['res_name']}-alb5xx', + name=f'{outputs["res_name"]}-alb5xx', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', dimensions={'LoadBalancer': outputs['res_suffix']}, metric_name='HTTPCode_ELB_5XX_Count', namespace='AWS/ApplicationELB', - alarm_description=f'Elevated 5xx errors on ALB {outputs['res_name']}', + alarm_description=f'Elevated 5xx errors on ALB {outputs["res_name"]}', tags=alb_5xx_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -251,13 +251,13 @@ def __init__( target_5xx = pulumi.Output.all(res_name=resource.name, res_suffix=resource.arn_suffix).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-target5xx', - name=f'{outputs['res_name']}-target5xx', + name=f'{outputs["res_name"]}-target5xx', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', dimensions={'LoadBalancer': outputs['res_suffix']}, metric_name='HTTPCode_ELB_5XX_Count', namespace='AWS/ApplicationELB', - alarm_description=f'Elevated 5xx errors on the targets of ALB {outputs['res_name']}', + alarm_description=f'Elevated 5xx errors on the targets of ALB {outputs["res_name"]}', tags=target_5xx_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -279,13 +279,13 @@ def __init__( response_time = pulumi.Output.all(res_name=resource.name, res_suffix=resource.arn_suffix).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-responsetime', - name=f'{outputs['res_name']}-responsetime', + name=f'{outputs["res_name"]}-responsetime', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', dimensions={'LoadBalancer': outputs['res_suffix']}, metric_name='TargetResponseTime', namespace='AWS/ApplicationELB', - alarm_description=f'Average response time is over {response_time_opts['threshold']} second(s) for {response_time_opts['period']} seconds', # noqa: E501 + alarm_description=f'Average response time is over {response_time_opts["threshold"]} second(s) for {response_time_opts["period"]} seconds', # noqa: E501 tags=response_time_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -401,14 +401,14 @@ def __unhealthy_hosts_metric_alarm( return pulumi.Output.all(tg_suffix=tg_suffix, lb_suffix=lb_suffix).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-unhealthy-hosts', - name=f'{outputs['tg_suffix'].split('/')[1]}-{outputs['lb_suffix'].split('/')[1]}-unhealthy-hosts', + name=f'{outputs["tg_suffix"].split("/")[1]}-{outputs["lb_suffix"].split("/")[1]}-unhealthy-hosts', alarm_actions=[self.monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', dimensions={'TargetGroup': outputs['tg_suffix'], 'LoadBalancer': outputs['lb_suffix']}, metric_name='UnHealthyHostCount', namespace='AWS/ApplicationELB', - alarm_description=f'{outputs['tg_suffix'].split('/')[1]} has detected unhealthy hosts in load balancer ' - f'{outputs['lb_suffix'].split('/')[1]}', + alarm_description=f'{outputs["tg_suffix"].split("/")[1]} has detected unhealthy hosts in load balancer ' + f'{outputs["lb_suffix"].split("/")[1]}', tags=tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[target_group, self.monitoring_group.resources['sns_topic']] @@ -474,14 +474,14 @@ def __init__( distro_4xx = pulumi.Output.all(res_id=resource.id, res_comment=resource.comment).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-4xx', - name=f'{self.project.name_prefix}-cfdistro-{outputs['res_id']}-4xx', + name=f'{self.project.name_prefix}-cfdistro-{outputs["res_id"]}-4xx', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', dimensions={'DistributionId': outputs['res_id']}, metric_name='4xxErrorRate', namespace='AWS/CloudFront', - alarm_description=f'4xx error rate for CloudFront Distribution "{outputs['res_comment']}" exceeds ' - f'{distro_4xx_opts['threshold']} on average over {distro_4xx_opts['period']} seconds.', + alarm_description=f'4xx error rate for CloudFront Distribution "{outputs["res_comment"]}" exceeds ' + f'{distro_4xx_opts["threshold"]} on average over {distro_4xx_opts["period"]} seconds.', tags=distro_4xx_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -559,7 +559,7 @@ def __init__( metric_name='FunctionComputeUtilization', namespace='AWS/CloudFront', alarm_description=f'CPU utilization on CloudFront Function {res_name} exceeds ' - f'{cpu_utilization_opts['threshold']}.', + f'{cpu_utilization_opts["threshold"]}.', tags=cpu_utilization_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -632,7 +632,7 @@ def __init__( cpu_utilization = pulumi.Output.all(res_name=resource.name, cluster_arn=resource.cluster).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-cpu', - name=f'{outputs['res_name']}-cpu', + name=f'{outputs["res_name"]}-cpu', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', # There is no direct way to get the Cluster name from a Service, but we can get the ARN, which has the @@ -640,8 +640,8 @@ def __init__( dimensions={'ClusterName': outputs['cluster_arn'].split('/')[-1], 'ServiceName': outputs['res_name']}, metric_name='CPUUtilization', namespace='AWS/ECS', - alarm_description=f'CPU utilization on the {outputs['res_name']} cluster exceeds ' - f'{cpu_utilization_opts['threshold']}%', + alarm_description=f'CPU utilization on the {outputs["res_name"]} cluster exceeds ' + f'{cpu_utilization_opts["threshold"]}%', tags=cpu_utilization_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] @@ -665,7 +665,7 @@ def __init__( memory_utilization = pulumi.Output.all(res_name=resource.name, cluster_arn=resource.cluster).apply( lambda outputs: aws.cloudwatch.MetricAlarm( f'{self.name}-memory', - name=f'{outputs['res_name']}-memory', + name=f'{outputs["res_name"]}-memory', alarm_actions=[monitoring_group.resources['sns_topic'].arn], comparison_operator='GreaterThanOrEqualToThreshold', # There is no direct way to get the Cluster name from a Service, but we can get the ARN, which has the @@ -673,8 +673,8 @@ def __init__( dimensions={'ClusterName': outputs['cluster_arn'].split('/')[-1], 'ServiceName': outputs['res_name']}, metric_name='MemoryUtilization', namespace='AWS/ECS', - alarm_description=f'Memory utilization on the {outputs['res_name']} cluster exceeds ' - f'{memory_utilization_opts['threshold']}%', + alarm_description=f'Memory utilization on the {outputs["res_name"]} cluster exceeds ' + f'{memory_utilization_opts["threshold"]}%', tags=memory_utilization_tags, opts=pulumi.ResourceOptions( parent=self, depends_on=[resource, monitoring_group.resources['sns_topic']] diff --git a/tb_pulumi/network.py b/tb_pulumi/network.py index cd90d7e..454b9b2 100644 --- a/tb_pulumi/network.py +++ b/tb_pulumi/network.py @@ -323,7 +323,7 @@ def __init__( rule.update({'type': 'ingress', 'security_group_id': sg.id}) ingress_rules.append( aws.ec2.SecurityGroupRule( - f'{name}-ingress-{rule['to_port']}', + f'{name}-ingress-{rule["to_port"]}', opts=pulumi.ResourceOptions(parent=self, depends_on=[sg]), **rule, ) @@ -334,7 +334,7 @@ def __init__( rule.update({'type': 'egress', 'security_group_id': sg.id}) egress_rules.append( aws.ec2.SecurityGroupRule( - f'{name}-egress-{rule['to_port']}', + f'{name}-egress-{rule["to_port"]}', opts=pulumi.ResourceOptions(parent=self, depends_on=[sg]), **rule, )