Sha256: 95b6532023edc51506a67d363e03e265d4aef1ae06c7f910c4db14ae5c6c882d

Contents?: true

Size: 821 Bytes

Versions: 3

Compression:

Stored size: 821 Bytes

Contents

require 'slosilo/adapters/abstract_adapter'

module Slosilo
  module Adapters
    class FileAdapter < AbstractAdapter
      attr_reader :dir
      
      def initialize(dir)
        @dir = dir
        @keys = {}
        Dir[File.join(@dir, "*.key")].each do |f|
          key = Slosilo::EncryptedAttributes.decrypt File.read(f)
          @keys[File.basename(f, '.key')] = key
        end
      end
      
      def put_key id, value
        raise "id should not contain a period" if id.index('.')
        fname = File.join(dir, "#{id}.key")
        File.write(fname, Slosilo::EncryptedAttributes.encrypt(value))
        File.chmod(0400, fname)
        @keys[id] = value
      end
      
      def get_key id
        @keys[id]
      end
      
      def each(&block)
        @keys.each(&block)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slosilo-0.2.4 lib/slosilo/adapters/file_adapter.rb
slosilo-0.2.3 lib/slosilo/adapters/file_adapter.rb
slosilo-0.2.2 lib/slosilo/adapters/file_adapter.rb