Class: Rails::Command::CredentialsCommand

Inherits:
Base
  • Object
show all
Includes:
Diffing, EnvironmentArgument, Helpers::Editor
Defined in:
railties/lib/rails/commands/credentials/credentials_command.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Diffing

Instance Method Summary collapse

Methods included from Diffing

#enroll_project_in_credentials_diffing, #ensure_rails_credentials_driver_is_set

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included

Methods inherited from Base

banner, base_name, command_name, default_command_root, desc, engine?, executable, exit_on_failure?, #help, hide_command!, inherited, namespace, perform, printing_commands, usage_path

Methods included from Actions

#load_generators, #load_tasks, #require_application!, #require_application_and_environment!, #require_environment!, #set_application_directory!

Instance Method Details

#diff(content_path = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'railties/lib/rails/commands/credentials/credentials_command.rb', line 56

def diff(content_path = nil)
  if @content_path = content_path
    extract_environment_option_from_argument(default_environment: extract_environment_from_path(content_path))
    require_application!

    say credentials.read.presence || credentials.content_path.read
  else
    require_application!
    enroll_project_in_credentials_diffing if options[:enroll]
  end
rescue ActiveSupport::MessageEncryptor::InvalidMessage
  say credentials.content_path.read
end

#editObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'railties/lib/rails/commands/credentials/credentials_command.rb', line 27

def edit
  extract_environment_option_from_argument(default_environment: nil)
  require_application!

  ensure_editor_available(command: "bin/rails credentials:edit") || (return)

  ensure_encryption_key_has_been_added if credentials.key.nil?
  ensure_credentials_have_been_added
  ensure_rails_credentials_driver_is_set

  catch_editing_exceptions do
    change_credentials_in_system_editor
  end

  say "File encrypted and saved."
rescue ActiveSupport::MessageEncryptor::InvalidMessage
  say "Couldn't decrypt #{content_path}. Perhaps you passed the wrong key?"
end

#showObject



46
47
48
49
50
51
# File 'railties/lib/rails/commands/credentials/credentials_command.rb', line 46

def show
  extract_environment_option_from_argument(default_environment: nil)
  require_application!

  say credentials.read.presence || missing_credentials_message
end