<commit_before>require 'aws-sdk'
require 'openssl'
require 'thor'

module S3Encrypt
  require "s3encrypt/version"

  class CLI < Thor
    class_option  :credential_file, 
                  :aliases => :c, 
                  :desc => "AWS credential file",
                  :default => '~/.s3encrypt'
    class_option  :access_key, 
                  :aliases => :a, 
                  :desc => "AWS access key"
    class_option  :secret_key, 
                  :aliases => :s, 
                  :desc => "AWS secret key"
    class_option  :pub, 
                  :aliases => :p, 
                  :desc => "Public key file",
                  :default => '~/.s3encrypt.pub'
    class_option  :priv, 
                  :aliases => :k, 
                  :desc => "Private key file",
                  :default => '~/.s3encrypt.pem'
    class_option  :bucket, 
                  :aliases => :b, 
                  :desc => "S3 Bucket to upload file to",
                  :default => 's3encrypt'
    class_option  :unencrypted, 
                  :type => :boolean,
                  :aliases => :u, 
                  :desc => "Do not decrypt file"

    desc "create-key", "Creates key files for encryption"
    def create_key
      if File.exists?(private_key)
        puts "Please remove #{private_key} before recreating it!"
      else
        gen_key
     end
    end

    desc "list-buckets", "Lists all of your buckets"
    def list_buckets
      s3.buckets.each do |bucket|
        puts bucket.name
      end
    end

    desc "create-bucket name", "Create an s3 bucket"
    method_option :region, :default => "US"
    def create_bucket(name)
      s3.buckets.create(name)
    end

    desc "delete-bucket name", "Delete an s3 bucket and all its contents"
    def delete_bucket(name)
      bucket = s3.buckets[name]
      bucket.delete!
    end

    desc "list-objects bucket", "List all the keys in a specific bucket"
    def list_objects(bucket)
      bucket = s3.buckets[bucket]
      bucket.objects.each do |obj|
        puts obj.key
      end
    end

    desc "put bucket object", "Put the object in the bucket"
    def put(bucket, object)
      bucket = s3.buckets[bucket]
      bucket.objects[object].write(File.open(object), :encryption_key => pubcrypt)
    end

    desc "remove bucket object", "Remove the object in the bucket"
    def remove(bucket, object)
      bucket = s3.buckets[bucket]
      bucket.objects[object].delete
    end

    desc "get bucket object", "Get the object in the bucket"
    def get(bucket, object)
      bucket = s3.buckets[bucket]
      if options[:unencrypted]
        open object, 'w' do |io| io.write bucket.objects[object].read end
      else
        open object, 'w' do |io| io.write bucket.objects[object].read(:encryption_key => crypt) end
      end
    end

    private
    def credentials
      @credentials ||= read_credentials
    end

    def private_key
      @private_key ||= File.expand_path(options[:priv]) 
    end

    def public_key
      @public_key ||= File.expand_path(options[:pub])
    end

    def crypt
      if File.exists?(private_key)
        @crypt ||= OpenSSL::PKey::RSA.new File.read(private_key)
      else
        @crypt ||= gen_key
      end
    end
<commit_msg>Removed default priv and pub key locations for testing<commit_after>require 'aws-sdk'
require 'openssl'
require 'thor'

module S3Encrypt
  require "s3encrypt/version"

  class CLI < Thor
    class_option  :credential_file, 
                  :aliases => :c, 
                  :desc => "AWS credential file",
                  :default => '~/.s3encrypt'
    class_option  :access_key, 
                  :aliases => :a, 
                  :desc => "AWS access key"
    class_option  :secret_key, 
                  :aliases => :s, 
                  :desc => "AWS secret key"
    class_option  :pub, 
                  :aliases => :p, 
                  :desc => "Public key file"
#                  :default => '~/.s3encrypt.pub'
    class_option  :priv, 
                  :aliases => :k, 
                  :desc => "Private key file"
#                  :default => '~/.s3encrypt.pem'
    class_option  :bucket, 
                  :aliases => :b, 
                  :desc => "S3 Bucket to upload file to",
                  :default => 's3encrypt'
    class_option  :unencrypted, 
                  :type => :boolean,
                  :aliases => :u, 
                  :desc => "Do not decrypt file"

    desc "create-key", "Creates key files for encryption"
    def create_key
      if File.exists?(private_key)
        puts "Please remove #{private_key} before recreating it!"
      else
        gen_key
     end
    end

    desc "list-buckets", "Lists all of your buckets"
    def list_buckets
      s3.buckets.each do |bucket|
        puts bucket.name
      end
    end

    desc "create-bucket name", "Create an s3 bucket"
    method_option :region, :default => "US"
    def create_bucket(name)
      s3.buckets.create(name)
    end

    desc "delete-bucket name", "Delete an s3 bucket and all its contents"
    def delete_bucket(name)
      bucket = s3.buckets[name]
      bucket.delete!
    end

    desc "list-objects bucket", "List all the keys in a specific bucket"
    def list_objects(bucket)
      bucket = s3.buckets[bucket]
      bucket.objects.each do |obj|
        puts obj.key
      end
    end

    desc "put bucket object", "Put the object in the bucket"
    def put(bucket, object)
      bucket = s3.buckets[bucket]
      bucket.objects[object].write(File.open(object), 
                                   :encryption_key => pubcrypt, 
                                   :encryption_materials_location => :instruction_file)
    end

    desc "remove bucket object", "Remove the object in the bucket"
    def remove(bucket, object)
      bucket = s3.buckets[bucket]
      bucket.objects[object].delete
    end

    desc "get bucket object", "Get the object in the bucket"
    def get(bucket, object)
      bucket = s3.buckets[bucket]
      if options[:unencrypted]
        open object, 'w' do |io| io.write bucket.objects[object].read end
      else
        if bucket.objects[object + '.instruction'].exists?
          puts "Object found #{object}.instruction"
        end
        open object, 'w' do |io| 
          io.write bucket.objects[object].read(:encryption_key => crypt, 
                                               :encryption_materials_location => :instruction_file) end
      end
    end

    private
    def credentials
      @credentials ||= read_credentials
    end

    def private_key
      @private_key ||= File.expand_path(options[:priv]) 
    end

    def public_key
      @public_key ||= File.expand_path(options[:pub])
    end

    def crypt
      if File.exists?(private_key)
        @crypt ||= OpenSSL::PKey::RSA.new File.read(private_key)
      else
        @crypt ||= gen_key
      end
    end

{'fraction_non_alphanumeric': 0.10221835580687255, 'fraction_numerical': 0.004639698419602726, 'mean_word_length': 1.8586821384169083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7509989', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2007, 'n_words': 572}