<commit_before>module Fog
  module AWS
    class EC2

      class SecurityGroup < Fog::Model

        identity  :group_name,        'groupName'

        attribute :group_description, 'groupDescription'
        attribute :ip_permissions,    'ipPermissions'
        attribute :owner_id,          'ownerId'

        def authorize(options = {})
          options = {
            'GroupName' => @group_name
          }.merge!(options)
          connection.authorize_security_group_ingress(options)
        end

        def destroy
          connection.delete_security_group(@group_name)
          true
        end

        def save
          data = connection.create_security_group(@group_name, @group_description).body
          true
        end

      end

    end
  end
end<commit_msg>nicer model interface to authorizing security group ingresses<commit_after>module Fog
  module AWS
    class EC2

      class SecurityGroup < Fog::Model

        identity  :group_name,        'groupName'

        attribute :group_description, 'groupDescription'
        attribute :ip_permissions,    'ipPermissions'
        attribute :owner_id,          'ownerId'

        def authorize_group_and_owner(group, owner)
          connection.authorize_security_group_ingress(
            'GroupName'                   => @group_name
            'SourceSecurityGroupName'     => group,
            'SourceSecurityGroupOwnerId'  => owner
          )
        end

        def authorize_port_range(range, options = {})
          connection.authorize_security_group_ingress(
            'CidrIp'      => options[:cidr_ip] || '0.0.0.0/0',
            'FromPort'    => range.min,
            'GroupName'   => @group_name,
            'ToPort'      => range.max,
            'IpProtocol'  => options[:ip_protocol] || 'tcp' 
          )
        end

        def destroy
          connection.delete_security_group(@group_name)
          true
        end

        def save
          data = connection.create_security_group(@group_name, @group_description).body
          true
        end

      end

    end
  end
end
{'fraction_non_alphanumeric': 0.0776978417266187, 'fraction_numerical': 0.003357314148681055, 'mean_word_length': 1.8419618528610355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2965453', 'n_tokens_mistral': 570, 'n_tokens_neox': 549, 'n_words': 116}