Skip to content

Commit 9b5b8b4

Browse files
authored
Merge pull request rails#52679 from porras/credentials_diff_with_custom_environment
Support custom environments on bin/rails credentials:diff
2 parents fc99b88 + e78746a commit 9b5b8b4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

railties/lib/rails/commands/credentials/credentials_command.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def relative_path(path)
128128
end
129129

130130
def extract_environment_from_path(path)
131-
available_environments.find { |env| path.end_with?("#{env}.yml.enc") }
131+
available_environments.find { |env| path.end_with?("#{env}.yml.enc") } || extract_custom_environment(path)
132+
end
133+
134+
def extract_custom_environment(path)
135+
path =~ %r{config/credentials/(.+)\.yml\.enc} && $1
132136
end
133137
end
134138
end

railties/test/commands/credentials_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ class Rails::Command::CredentialsTest < ActiveSupport::TestCase
285285
assert_match(raw_content, run_diff_command("config/credentials.yml.enc"))
286286
end
287287

288+
test "diff for custom environment" do
289+
run_edit_command(environment: "custom")
290+
291+
assert_match(/access_key_id: 123/, run_diff_command("config/credentials/custom.yml.enc"))
292+
end
293+
294+
test "diff for custom environment when key is not available" do
295+
run_edit_command(environment: "custom")
296+
remove_file "config/credentials/custom.key"
297+
298+
raw_content = File.read(app_path("config", "credentials", "custom.yml.enc"))
299+
assert_match(raw_content, run_diff_command("config/credentials/custom.yml.enc"))
300+
end
301+
288302
test "diff returns raw encrypted content when errors occur" do
289303
run_edit_command(environment: "development")
290304

0 commit comments

Comments
 (0)