<commit_before>module Fog
  module Storage
    class AWS
      private
        def self.hash_to_acl(acl)
          data =
<<-DATA
<AccessControlPolicy>
  <Owner>
    <ID>#{acl['Owner']['ID']}</ID>
    <DisplayName>#{acl['Owner']['DisplayName']}</DisplayName>
  </Owner>
  <AccessControlList>
DATA

          acl['AccessControlList'].each do |grant|
            data << "    <Grant>\n"
            case grant['Grantee'].keys.sort
            when ['DisplayName', 'ID']
              data << "      <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\">\n"
              data << "        <ID>#{grant['Grantee']['ID']}</ID>\n"
              data << "        <DisplayName>#{grant['Grantee']['DisplayName']}</DisplayName>\n"
              data << "      </Grantee>\n"
            when ['EmailAddress']
              data << "      <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"AmazonCustomerByEmail\">\n"
              data << "        <EmailAddress>#{grant['Grantee']['EmailAddress']}</EmailAddress>\n"
              data << "      </Grantee>\n"
            when ['URI']
              data << "      <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Group\">\n"
              data << "        <URI>#{grant['Grantee']['URI']}</URI>\n"
              data << "      </Grantee>\n"
            end
            data << "      <Permission>#{grant['Permission']}</Permission>\n"
            data << "    </Grant>\n"
          end
          
          data <<
<<-DATA
  </AccessControlList>
</AccessControlPolicy>
DATA
          data
        end
    end
  end
end
<commit_msg>AWS#hash_to_acl - add support for EmailAddress and URI grantee types.<commit_after>module Fog
  module Storage
    class AWS

      private
        def self.hash_to_acl(acl)
          data =  "<AccessControlPolicy>\n"

          if acl['Owner'] && (acl['Owner']['ID'] || acl['Owner']['DisplayName'])
            data << "  <Owner>\n"
            data << "    <ID>#{acl['Owner']['ID']}</ID>\n" if acl['Owner']['ID']
            data << "    <DisplayName>#{acl['Owner']['DisplayName']}</DisplayName>\n" if acl['Owner']['DisplayName']
            data << "  </Owner>\n"
          end

          data << "  <AccessControlList>\n" if acl['AccessControlList'].any?
          acl['AccessControlList'].each do |grant|
            data << "    <Grant>\n"
            type = case grant['Grantee'].keys.sort
            when ['ID']
              'CanonicalUser'
            when ['EmailAddress']
              'AmazonCustomerByEmail'
            when ['URI']
              'Group'
            end

            data << "      <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">\n"
            data << "        <ID>#{grant['Grantee']['ID']}</ID>\n" if grant['Grantee']['ID']
            data << "        <DisplayName>#{grant['Grantee']['DisplayName']}</DisplayName>\n" if grant['Grantee']['DisplayName']
            data << "        <EmailAddress>#{grant['Grantee']['EmailAddress']}</EmailAddress>\n" if grant['Grantee']['EmailAddress']
            data << "        <URI>#{grant['Grantee']['URI']}</URI>\n" if grant['Grantee']['URI']
            data << "      </Grantee>\n"
            data << "      <Permission>#{grant['Permission']}</Permission>\n"
            data << "    </Grant>\n"
          end
          data << "  </AccessControlList>\n" if acl['AccessControlList'].any?

          data << "</AccessControlPolicy>"

          data
        end

    end
  end
end
{'fraction_non_alphanumeric': 0.19065052098000562, 'fraction_numerical': 0.005632216277105041, 'mean_word_length': 1.9282769991755977, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, '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': '5618342', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1049, 'n_words': 170}