<commit_before>module Heirloom
  module CLI
    class Rotate

      include Heirloom::CLI::Shared

      def initialize
        @opts = read_options
        @logger = HeirloomLogger.new :log_level => @opts[:level]
        @config = load_config :logger => @logger,
                              :opts   => @opts

        ensure_valid_options :provided => @opts,
                             :required => [:name],
                             :config   => @config

        @catalog = Heirloom::Catalog.new :name    => @opts[:name],
                                         :config  => @config

        # Can't use fetch as Trollop sets :id to nil
        id = @opts[:id] ||( latest_id :name   => @opts[:name],                                              
                                      :config => @config)

        @archive = Archive.new :name   => @opts[:name],
                               :config => @config,
                               :id     => id

        unless @opts[:bucket_prefix]
          ensure_archive_exists :archive => @archive,
                                :config  => @config
        end

        # Lookup region & bucket_prefix from simpledb unless specified
        # To Do, valid validation message that simpledb exists
        @region = @opts[:region] || @catalog.regions.first
        @bucket_prefix = @opts[:bucket_prefix] || @catalog.bucket_prefix
      end
      
      def rotate
        ensure_path_is_directory     :path => @opts[:output], :config => @config
        ensure_directory_is_writable :path => @opts[:output], :config => @config
        secret = read_secret :opts   => @opts,
                             :config => @config
        archive = @archive.download :output        => @opts[:output],
                                    :extract       => @opts[:extract],
                                    :region        => @region,
                                    :bucket_prefix => @bucket_prefix,
                                    :secret        => secret
        # do rotation
        exit 1 unless archive<commit_msg>wip - key rotation<commit_after>module Heirloom
  module CLI
    class Rotate

      include Heirloom::CLI::Shared

      # how to re-use what is in upload?
      def initialize
        @opts = read_options
        @logger = HeirloomLogger.new :log_level => @opts[:level]
        @config = load_config :logger => @logger,
                              :opts   => @opts

        ensure_valid_options :provided => @opts,
                             :required => [:name],
                             :config   => @config

        @catalog = Heirloom::Catalog.new :name   => @opts[:name],
                                         :config => @config

        # Can't use fetch as Trollop sets :id to nil
        id = @opts[:id] || (latest_id :name => @opts[:name], :config => @config)

        @archive = Archive.new :name   => @opts[:name],
                               :config => @config,
                               :id     => id

        unless @opts[:bucket_prefix]
          ensure_archive_exists :archive => @archive,
                                :config  => @config
        end

        # Lookup region & bucket_prefix from simpledb unless specified
        # To Do, valid validation message that simpledb exists
        @region = @opts[:region] || @catalog.regions.first
        @bucket_prefix = @opts[:bucket_prefix] || @catalog.bucket_prefix
      end
      
      def rotate
        temp_dir = create_temp_directory
        
        unless @archive.download :output        => temp_dir,
                                 :extract       => @opts[:extract],
                                 :region        => @region,
                                 :bucket_prefix => @bucket_prefix,
                                 :secret        => secret
          @logger.error "Download failed."
          exit 1
        end

        @file = Tempfile.new('archive.tar.gz')

        # do we need the original exclude options
        unless @archive.build :bucket_prefix => @bucket_prefix,
                              :directory     => temp_dir,
                              :exclude       => @opts[:exclude],
                              :file          => @file.path,
                              :secret        => secret
          @logger.error "Build failed."
          exit 1
        end
        
        @archive.destroy if @archive.exists?

        @archive.upload :bucket_prefix   => @bucket_prefix,
                        :regions         => @regions,
                        :public_readable => @opts[:public],
                        :file            => @file.path,
                        :secret          => secret

        @file.close!
{'fraction_non_alphanumeric': 0.09974640743871513, 'fraction_numerical': 0.0006339814032121725, 'mean_word_length': 1.214787084698175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '210413', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1105, 'n_words': 286}