<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from utils import get_external_ip, get_sg_id_from_name, get_all_sgs
import boto3

def sg_close(sg_name=None, all_sgs=False):
      if all_sgs:
            sgs = get_all_sgs()
      else:
            ec2 = boto3.resource('ec2')
            sg_id = get_sg_id_from_name(sg_name)
            sgs = [ec2.SecurityGroup(sg_id)]
      
      current_ip = get_external_ip()
      current_cidr = current_ip + "/32"
      for security_group in sgs:
            print('Closing SSH to this IP on Security Group %s' % security_group.group_name)
            security_group.revoke_ingress(
                        IpProtocol='tcp',
                        FromPort=22,
                        ToPort=22,
                        CidrIp=current_cidr
                        )<commit_msg>Close all open permissions instead of trying to revoke IP<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from utils import get_external_ip, get_sg_id_from_name, get_all_sgs
from ipaddress import IPv4Address
from sg_list import get_open_permissions
import boto3

def sg_close(sg_name=None, all_sgs=False):
      if all_sgs:
            sgs = get_all_sgs()
      else:
            ec2 = boto3.resource('ec2')
            sg_id = get_sg_id_from_name(sg_name)
            sgs = [ec2.SecurityGroup(sg_id)]
      
      current_ip = IPv4Address(get_external_ip())
      for security_group in sgs:
            permissions = get_open_permissions(security_group, current_ip)
            if permissions:
                  print('Closing SSH to this IP on Security Group %s via permissions:' % security_group.group_name)
                  security_group.revoke_ingress(IpPermissions=permissions)
                  for permission in permissions:
                        print(permission)
{'fraction_non_alphanumeric': 0.07916437603078615, 'fraction_numerical': 0.010995052226498075, 'mean_word_length': 2.127147766323024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393435', 'n_tokens_mistral': 577, 'n_tokens_neox': 557, 'n_words': 122}