Class: Roro::Crypto::KeyWriter

Inherits:
Object
  • Object
show all
Includes:
FileReflection
Defined in:
lib/roro/crypto/key_writer.rb

Overview

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.

Instance Method Summary collapse

Methods included from FileReflection

#gather_environments, #get_key, #source_files

Constructor Details

#initializeKeyWriter

Returns a new instance of KeyWriter.



14
15
16
17
18
# File 'lib/roro/crypto/key_writer.rb', line 14

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

Instance Method Details

#write_keyfile(environment, extension = '.key') ⇒ Object



20
21
22
23
# File 'lib/roro/crypto/key_writer.rb', line 20

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

#write_keyfiles(environments = [], directory = nil, extension = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/roro/crypto/key_writer.rb', line 25

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