Merge pull request #52679 from porras/credentials_diff_with_custom_environment

Support custom environments on bin/rails credentials:diff
This commit is contained in:
Rafael Mendonça França 2024-08-28 16:30:41 -03:00 committed by GitHub
commit 9b5b8b4b32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -128,7 +128,11 @@ module Rails
end
def extract_environment_from_path(path)
available_environments.find { |env| path.end_with?("#{env}.yml.enc") }
available_environments.find { |env| path.end_with?("#{env}.yml.enc") } || extract_custom_environment(path)
end
def extract_custom_environment(path)
path =~ %r{config/credentials/(.+)\.yml\.enc} && $1
end
end
end

View File

@ -285,6 +285,20 @@ class Rails::Command::CredentialsTest < ActiveSupport::TestCase
assert_match(raw_content, run_diff_command("config/credentials.yml.enc"))
end
test "diff for custom environment" do
run_edit_command(environment: "custom")
assert_match(/access_key_id: 123/, run_diff_command("config/credentials/custom.yml.enc"))
end
test "diff for custom environment when key is not available" do
run_edit_command(environment: "custom")
remove_file "config/credentials/custom.key"
raw_content = File.read(app_path("config", "credentials", "custom.yml.enc"))
assert_match(raw_content, run_diff_command("config/credentials/custom.yml.enc"))
end
test "diff returns raw encrypted content when errors occur" do
run_edit_command(environment: "development")