<commit_before>module Awful

  class SecurityGroup < Cli

    desc 'ls [NAME]', 'list security groups [matching NAME]'
    method_option :long, aliases: '-l', default: false, desc: 'Long listing'
    def ls(name = /./)
      fields = options[:long] ?
        ->(s) { [tag_name(s), s.group_id, s.group_name, s.vpc_id, s.description] } :
        ->(s) { [s.group_name] }

      ec2.describe_security_groups.map(&:security_groups).flatten.select do |sg|
        sg.group_name.match(name) or sg.group_id.match(name)
      end.map do |sg|
        fields.call(sg)
      end.tap do |list|
        print_table list
      end
    end

    desc 'dump NAME', 'dump security group with NAME as yaml'
    def dump(name)
      ec2.describe_security_groups.map(&:security_groups).flatten.find do |sg|
        sg.group_name == name
      end.tap do |sg|
        puts YAML.dump(stringify_keys(sg.to_hash))
      end
    end

  end

end<commit_msg>add inbound rule task<commit_after>module Awful

  class SecurityGroup < Cli

    desc 'ls [NAME]', 'list security groups [matching NAME]'
    method_option :long, aliases: '-l', default: false, desc: 'Long listing'
    def ls(name = /./)
      fields = options[:long] ?
        ->(s) { [tag_name(s), s.group_id, s.group_name, s.vpc_id, s.description] } :
        ->(s) { [s.group_name] }

      ec2.describe_security_groups.map(&:security_groups).flatten.select do |sg|
        sg.group_name.match(name) or sg.group_id.match(name)
      end.map do |sg|
        fields.call(sg)
      end.tap do |list|
        print_table list
      end
    end

    desc 'dump NAME', 'dump security group with NAME as yaml'
    def dump(name)
      ec2.describe_security_groups.map(&:security_groups).flatten.find do |sg|
        sg.group_name == name
      end.tap do |sg|
        puts YAML.dump(stringify_keys(sg.to_hash))
      end
    end

    desc 'inbound NAME', 'show inbound rules for named security group'
    method_option :long, aliases: '-l', default: false, desc: 'Long listing'
    def inbound(name)
      ec2.describe_security_groups.map(&:security_groups).flatten.find do |sg|
        sg.group_name == name
      end.ip_permissions.tap do |perms|
        sources = ->(perm) { perm.ip_ranges.map(&:cidr_ip) + perm.user_id_group_pairs.map(&:group_id) }
        if options[:long]
          perms.map do |p|
            sources.call(p).map do |s|
              [p.ip_protocol, p.from_port, p.to_port, s]
            end
          end.flatten(1).tap { |list| print_table list }
        else
          puts perms.map { |p| sources.call(p) }.flatten
        end
      end
    end

  end

end
{'fraction_non_alphanumeric': 0.12739097169089517, 'fraction_numerical': 0.0022953328232593728, 'mean_word_length': 2.458994708994709, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '212856', 'n_tokens_mistral': 937, 'n_tokens_neox': 892, 'n_words': 215}