Sha256: eaa90218851085f085ebbb935fb485068c68b88f38cc6ac2ce8f1ce6a581fecd

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 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)
        @writer.write_to_file("#{@mise}/keys/.keep", '')
        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

1 entries across 1 versions & 1 rubygems

Version Path
roro-0.3.33 lib/roro/crypto/key_writer.rb