Class: LocalVault::CLI::RailsImport

Inherits:
Object
  • Object
show all
Defined in:
lib/localvault/cli/rails_import.rb

Overview

Finds a Rails app's credentials keys so they can be stored in the vault and injected as RAILS_MASTER_KEY instead of living in a file.

Reads only. Removing the key files is the operator's call — this reports what is still on disk and leaves it alone.

Defined Under Namespace

Classes: Key

Constant Summary collapse

MASTER_KEY_PATH =
"config/master.key".freeze
CREDENTIALS_PATH =
"config/credentials.yml.enc".freeze

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ RailsImport

Returns a new instance of RailsImport.



14
15
16
# File 'lib/localvault/cli/rails_import.rb', line 14

def initialize(root = Dir.pwd)
  @root = root
end

Instance Method Details

#keysObject

Every key file this app has: the default master key plus one per environment (config/credentials/production.key).



26
27
28
# File 'lib/localvault/cli/rails_import.rb', line 26

def keys
  [master_key, *environment_keys].compact
end

#rails_app?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/localvault/cli/rails_import.rb', line 18

def rails_app?
  File.exist?(File.join(@root, CREDENTIALS_PATH)) ||
    File.exist?(File.join(@root, MASTER_KEY_PATH)) ||
    Dir.exist?(File.join(@root, "config/credentials"))
end