123456789_123456789_123456789_123456789_123456789_

Class: Rails::Command::EncryptedCommand

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base, Thor
Instance Chain:
self, Helpers::Editor, Base, Actions, Thor
Inherits: Rails::Command::Base
Defined in: railties/lib/rails/commands/encrypted/encrypted_command.rb

Class Attribute Summary

Base - Inherited

.bin, .bin?,
.engine?

Returns true when the app is a Rails engine.

.exit_on_failure?

Class Method Summary

Base - Inherited

.banner,
.base_name

Sets the base_name taking into account the current class namespace.

.command_name

Return command name without namespaces.

.default_command_root

Default file root to place extra files a command might need, placed one folder above the command file.

.desc

Tries to get the description from a USAGE file one folder above the command root.

.executable,
.hide_command!

Convenience method to hide this command from the available ones when running rails command.

.namespace

Convenience method to get the namespace from the class name.

.printing_commands,
.usage_path

Path to lookup a USAGE description in a file.

.create_command

Allow the command method to be called perform.

.namespaced_name, .resolve_path, .class_usage,
.help

Override Thor’s class-level help to also show the USAGE.

.inherited, .perform

Instance Method Summary

Instance Method Details

#change_encrypted_configuration_in_system_editor (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 55

def change_encrypted_configuration_in_system_editor
  using_system_editor do
    encrypted_configuration.change { |tmp_path| system_editor(tmp_path) }
    say "File encrypted and saved."
    warn_if_encrypted_configuration_is_invalid
  end
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
  say error.message
rescue ActiveSupport::MessageEncryptor::InvalidMessage
  say "Couldn't decrypt #{content_path}. Perhaps you passed the wrong key?"
end

#content_path (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 33

def content_path
  @content_path ||= args[0]
end

#edit

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 16

def edit(*)
  load_environment_config!

  ensure_encryption_key_has_been_added
  ensure_encrypted_configuration_has_been_added

  change_encrypted_configuration_in_system_editor
end

#encrypted_configuration (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 41

def encrypted_configuration
  @encrypted_configuration ||= Rails.application.encrypted(content_path, key_path: key_path)
end

#encrypted_file_generator (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 82

def encrypted_file_generator
  require "rails/generators"
  require "rails/generators/rails/encrypted_file/encrypted_file_generator"

  Rails::Generators::EncryptedFileGenerator.new
end

#encryption_key_file_generator (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 75

def encryption_key_file_generator
  require "rails/generators"
  require "rails/generators/rails/encryption_key_file/encryption_key_file_generator"

  Rails::Generators::EncryptionKeyFileGenerator.new
end

#ensure_encrypted_configuration_has_been_added (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 51

def ensure_encrypted_configuration_has_been_added
  encrypted_file_generator.add_encrypted_file_silently(content_path, key_path)
end

#ensure_encryption_key_has_been_added (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 45

def ensure_encryption_key_has_been_added
  return if encrypted_configuration.key?
  encryption_key_file_generator.add_key_file(key_path)
  encryption_key_file_generator.ignore_key_file(key_path)
end

#key_path (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 37

def key_path
  options[:key]
end

#missing_encrypted_configuration_message (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 89

def missing_encrypted_configuration_message
  if !encrypted_configuration.key?
    "Missing '#{key_path}' to decrypt data. See `#{executable(:help)}`"
  else
    "File '#{content_path}' does not exist. Use `#{executable(:edit)} #{content_path}` to change that."
  end
end

#show

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 26

def show(*)
  load_environment_config!

  say encrypted_configuration.read.presence || missing_encrypted_configuration_message
end

#warn_if_encrypted_configuration_is_invalid (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/encrypted/encrypted_command.rb', line 67

def warn_if_encrypted_configuration_is_invalid
  encrypted_configuration.validate!
rescue ActiveSupport::EncryptedConfiguration::InvalidContentError => error
  say "WARNING: #{error.message}", :red
  say ""
  say "Your application will not be able to load '#{content_path}' until the error has been fixed.", :red
end