Skip to content

feat: Add scripts to delete tagged SGs and EFS #55

feat: Add scripts to delete tagged SGs and EFS

feat: Add scripts to delete tagged SGs and EFS #55

GitHub Actions / Black failed Feb 1, 2024 in 0s

3 errors

Black found 3 errors

Annotations

Check failure on line 39 in /home/runner/work/aws-toolbox/aws-toolbox/ec2/delete_tagged_security_groups.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/aws-toolbox/aws-toolbox/ec2/delete_tagged_security_groups.py#L23-L39

 
 def revoke_permissions(ec2_client, group_id, permissions):
     for sg in permissions:
         if sg.get("IpPermissions", []):
             for rule in sg.get("IpPermissions", []):
-                ec2_client.revoke_security_group_ingress(GroupId=group_id, IpPermissions=[rule])
-                print("Revoked ingress IP permissions for Security Group ID: {}".format(group_id))
+                ec2_client.revoke_security_group_ingress(
+                    GroupId=group_id, IpPermissions=[rule]
+                )
+                print(
+                    "Revoked ingress IP permissions for Security Group ID: {}".format(
+                        group_id
+                    )
+                )
         if sg.get("IpPermissionsEgress", []):
             for rule in sg.get("IpPermissionsEgress", []):
-                ec2_client.revoke_security_group_egress(GroupId=group_id, IpPermissions=[rule])
-                print("Revoked egress IP permissions for Security Group ID: {}".format(group_id))
+                ec2_client.revoke_security_group_egress(
+                    GroupId=group_id, IpPermissions=[rule]
+                )
+                print(
+                    "Revoked egress IP permissions for Security Group ID: {}".format(
+                        group_id
+                    )
+                )
 
 
 def delete_security_group(ec2_client, group_id):
     ec2_client.delete_security_group(GroupId=group_id)
     print("Deleted Security Group ID: {}".format(group_id))

Check failure on line 68 in /home/runner/work/aws-toolbox/aws-toolbox/ec2/delete_tagged_security_groups.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/aws-toolbox/aws-toolbox/ec2/delete_tagged_security_groups.py#L48-L68

     # Modify the tag key and value to your own liking
     tag_key = "ManagedByAmazonSageMakerResource"
     tag_value_contains = f"arn:aws:sagemaker:{aws_region}:{account_id}:domain"
 
     # Find security groups
-    tagged_security_groups = find_security_groups(ec2_client, tag_key, tag_value_contains)
+    tagged_security_groups = find_security_groups(
+        ec2_client, tag_key, tag_value_contains
+    )
 
     # Iterate through security groups, revoke permissions, and delete
     for sg in tagged_security_groups:
         group_id = sg["GroupId"]
 
         # Fetch the current ingress and egress IP permissions
-        sg = ec2_client.describe_security_groups(Filters=[{"Name": "group-id", "Values": [group_id]}]).get(
-            "SecurityGroups", []
-        )
+        sg = ec2_client.describe_security_groups(
+            Filters=[{"Name": "group-id", "Values": [group_id]}]
+        ).get("SecurityGroups", [])
 
         # Revoke permissions
         revoke_permissions(ec2_client, group_id, sg)
 
         # Delete the security group

Check failure on line 49 in /home/runner/work/aws-toolbox/aws-toolbox/efs/delete_tagged_efs.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/aws-toolbox/aws-toolbox/efs/delete_tagged_efs.py#L38-L49

             # Delete the mount targets for the EFS filesystem
             delete_mount_targets(efs_client, filesystem_id)
 
             # Wait with exponential backoff
             delay = (2**current_retry) + random.uniform(0, 1)
-            print(f"Waiting for {delay} seconds before attempting to delete the EFS filesystem.")
+            print(
+                f"Waiting for {delay} seconds before attempting to delete the EFS filesystem."
+            )
             time.sleep(delay)
 
             # Delete the specified EFS filesystem
             efs_client.delete_file_system(FileSystemId=filesystem_id)
             print("Deleted EFS Filesystem: {}".format(filesystem_id))