Sha256: 5124010331b02b8d9c7db906f762ffcc58989d26070d882cb5d236498650e71d

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Roro
  module Crypto

    # Key writer Writes keys arguments for environments, directory and extension where
    # environments are the names of the keys to be generated, directory
    # is the destination folders the keys will be wrtten in and extension is
    # the extension of the key file.

    class KeyWriter
      include Roro::FileReflection

      def initialize
        @writer = FileWriter.new
        @cipher = Cipher.new
        @mise   = Roro::CLI.mise
      end

      def write_keyfile(environment, extension = '.key')
        destination = "#{@mise}/keys/#{environment}#{extension}"
        @writer.write_to_file(destination, @cipher.generate_key)
      end

      def write_keyfiles(environments = [], directory = nil, extension = nil)
        directory ||= @mise
        extension ||= '.key'
        if environments.empty?
          environments = gather_environments(directory, '.env').uniq
        end
        environments.uniq.each { |environment| write_keyfile(environment, extension) }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
roro-0.3.30 lib/roro/crypto/key_writer.rb
roro-0.3.28 lib/roro/crypto/key_writer.rb
roro-0.3.27 lib/roro/crypto/key_writer.rb
roro-0.3.25 lib/roro/crypto/key_writer.rb
roro-0.3.24 lib/roro/crypto/key_writer.rb
roro-0.3.23 lib/roro/crypto/key_writer.rb