<commit_before>define :rsa_keypair_from_pkcs12, :aws_access_key_id => nil, :aws_secret_access_key => nil, :s3_bucket => nil, :s3_file => nil, :pkcs12_pass => nil, :rsa_cert_path => nil, :rsa_key_path => nil do
  tempdir = "/tmp/pkcs12"
  pkcs12_cert="#{tempdir}/cert.pkcs12"
  rsa_pair = "#{tempdir}/rsa_pair.crt"

  directory tempdir do
    recursive true
    action :create
  end

  aws_s3 "Get the PKCS12 file" do
    access_key_id params[:aws_access_key_id]
    secret_access_key params[:aws_secret_access_key]
    s3_bucket params[:s3_bucket]
    s3_file params[:s3_file]
    file_path pkcs12_cert
    action :get
  end

  bash "Convert PKCS12 to RSA Pair" do
    code <<-EOF
openssl pkcs12 -passin pass:#{params[:pkcs12_pass]} -in #{pkcs12_cert} -out #{rsa_pair} -nodes
    EOF
  end

  ruby_block "Extract pair from converted file" do
    block do
      copy_to_key = false
      copy_to_cert = false
      key = ''
      cert = ''
      ::File.new(rsa_pair, 'r').each_line do |line|
        if line =~ /-----BEGIN RSA PRIVATE KEY-----/
          key = line
          copy_to_key = true
          next
        end
        if copy_to_key
          key += line
          if line =~ /-----END RSA PRIVATE KEY-----/ then
            copy_to_key = false
          end<commit_msg>Forgotten bit to refactor from aws to rjg_aws<commit_after>define :rsa_keypair_from_pkcs12, :aws_access_key_id => nil, :aws_secret_access_key => nil, :s3_bucket => nil, :s3_file => nil, :pkcs12_pass => nil, :rsa_cert_path => nil, :rsa_key_path => nil do
  tempdir = "/tmp/pkcs12"
  pkcs12_cert="#{tempdir}/cert.pkcs12"
  rsa_pair = "#{tempdir}/rsa_pair.crt"

  directory tempdir do
    recursive true
    action :create
  end

  rjg_aws_s3 "Get the PKCS12 file" do
    access_key_id params[:aws_access_key_id]
    secret_access_key params[:aws_secret_access_key]
    s3_bucket params[:s3_bucket]
    s3_file params[:s3_file]
    file_path pkcs12_cert
    action :get
  end

  bash "Convert PKCS12 to RSA Pair" do
    code <<-EOF
openssl pkcs12 -passin pass:#{params[:pkcs12_pass]} -in #{pkcs12_cert} -out #{rsa_pair} -nodes
    EOF
  end

  ruby_block "Extract pair from converted file" do
    block do
      copy_to_key = false
      copy_to_cert = false
      key = ''
      cert = ''
      ::File.new(rsa_pair, 'r').each_line do |line|
        if line =~ /-----BEGIN RSA PRIVATE KEY-----/
          key = line
          copy_to_key = true
          next
        end
        if copy_to_key
          key += line
          if line =~ /-----END RSA PRIVATE KEY-----/ then
            copy_to_key = false
          end
{'fraction_non_alphanumeric': 0.11162432640492687, 'fraction_numerical': 0.022324865280985373, 'mean_word_length': 2.521680216802168, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '6198298', 'n_tokens_mistral': 994, 'n_tokens_neox': 938, 'n_words': 234}