Class: Leml::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/leml/core.rb

Constant Summary collapse

KEY_FILE =
Rails.root.join('config', 'leml.key')
SECRETS =
Rails.root.join('config', 'leml.yml')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCore

Returns a new instance of Core.

Raises:



65
66
67
68
69
70
71
# File 'lib/leml/core.rb', line 65

def initialize
  @key = File.exist?(KEY_FILE) ? File.read(KEY_FILE).chop : ENV['LEML_KEY']
  raise NoLemlKeyError if @key.blank?
  @encryptor = ActiveSupport::MessageEncryptor.new(@key, cipher: 'aes-256-cbc')
  @secrets = YAML.load_file(SECRETS)
  @previous_key_hash = {}
end

Class Method Details

.setupObject



10
11
12
13
14
# File 'lib/leml/core.rb', line 10

def setup
  key_initialize
  yaml_initialize
  complete_message
end

Instance Method Details

#editObject

Raises:



78
79
80
81
82
83
84
85
86
# File 'lib/leml/core.rb', line 78

def edit
  raise NoEditorError if ENV['EDITOR'].blank?
  Dir.mktmpdir do |dir|
    tmp_file = create_decrypted_tmp_file(dir)
    system("#{ENV['EDITOR']} #{tmp_file.to_s}")
    reload_secrets_file(tmp_file)
    puts 'OK, your secrets is encrypted.'
  end
end

#merge_secretsObject



73
74
75
76
# File 'lib/leml/core.rb', line 73

def merge_secrets
  return unless @key.present? && File.exist?(SECRETS)
  Rails.application.secrets.merge!(decrypt(@secrets)[Rails.env].deep_symbolize_keys) if @secrets
end

#showObject



88
89
90
91
# File 'lib/leml/core.rb', line 88

def show
  return unless @secrets
  print(decrypt(@secrets).to_yaml)
end