Skip to content

Commit 1d22ea8

Browse files
Merge pull request rails#47801 from p8/railties/deprecate-all-secrets-commands
Remove deprecated `secrets:setup` and deprecate `secrets:edit/show`
2 parents 50189c4 + 333bb6b commit 1d22ea8

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

railties/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
* Deprecate `secrets:edit/show` and remove `secrets:setup`
2+
3+
`bin/rails secrets:setup` has been deprecated since Rails 5.2 in favor of
4+
credentials. This command has been removed.
5+
6+
`bin/rails secrets:show` and `bin/rails secrets:edit` have been deprecated
7+
in favor of credentials.
8+
Run `bin/rails credentials:help` for more information
9+
10+
*Petrik de Heus*
11+
112
* `bin/rails --help` will now list only framework and plugin commands. Rake
213
tasks defined in `lib/tasks/*.rake` files will no longer be included. For a
314
list of those tasks, use `rake -T`.

railties/lib/rails/commands/secrets/secrets_command.rb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module Command
99
class SecretsCommand < Rails::Command::Base # :nodoc:
1010
include Helpers::Editor
1111

12-
desc "setup", "Deprecated in favor of credentials -- run `bin/rails credentials:help`"
13-
def setup
14-
deprecate_in_favor_of_credentials_and_exit
15-
end
16-
17-
desc "edit", "Open the secrets in `$EDITOR` for editing"
12+
desc "edit", "**deprecated** Open the secrets in `$EDITOR` for editing"
1813
def edit
14+
Rails.deprecator.warn(<<~MSG.squish)
15+
`bin/rails secrets:edit` is deprecated in favor of credentials and will be removed in Rails 7.2.
16+
Run `bin/rails credentials:help` for more information.
17+
MSG
18+
1919
boot_application!
2020

2121
using_system_editor do
@@ -26,24 +26,21 @@ def edit
2626
say error.message
2727
rescue Errno::ENOENT => error
2828
if error.message.include?("secrets.yml.enc")
29-
deprecate_in_favor_of_credentials_and_exit
29+
exit 1
3030
else
3131
raise
3232
end
3333
end
3434

35-
desc "show", "Show the decrypted secrets"
35+
desc "show", "**deprecated** Show the decrypted secrets"
3636
def show
37+
Rails.deprecator.warn(<<~MSG.squish)
38+
`bin/rails secrets:show` is deprecated in favor of credentials and will be removed in Rails 7.2.
39+
Run `bin/rails credentials:help` for more information.
40+
MSG
41+
3742
say Rails::Secrets.read
3843
end
39-
40-
private
41-
def deprecate_in_favor_of_credentials_and_exit
42-
say "Encrypted secrets is deprecated in favor of credentials. Run:"
43-
say "bin/rails credentials:help"
44-
45-
exit 1
46-
end
4744
end
4845
end
4946
end

railties/test/command/base_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "rails/command"
55
require "rails/commands/generate/generate_command"
66
require "rails/commands/notes/notes_command"
7-
require "rails/commands/secrets/secrets_command"
7+
require "rails/commands/credentials/credentials_command"
88
require "rails/commands/db/system/change/change_command"
99

1010
class Rails::Command::BaseTest < ActiveSupport::TestCase
@@ -14,7 +14,7 @@ class Rails::Command::BaseTest < ActiveSupport::TestCase
1414
end
1515

1616
test "printing commands returns namespaced commands" do
17-
assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands.map(&:first)
17+
assert_equal %w(credentials:edit credentials:show credentials:diff), Rails::Command::CredentialsCommand.printing_commands.map(&:first)
1818
assert_equal %w(db:system:change), Rails::Command::Db::System::ChangeCommand.printing_commands.map(&:first)
1919
end
2020

railties/test/commands/secrets_test.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,6 @@ class Rails::Command::SecretsTest < ActiveSupport::TestCase
1414
assert_match "No $EDITOR to open file in", run_edit_command(editor: "")
1515
end
1616

17-
test "encrypted secrets are deprecated when using credentials" do
18-
assert_match "Encrypted secrets is deprecated", run_setup_command
19-
assert_equal 1, $?.exitstatus
20-
assert_not File.exist?("config/secrets.yml.enc")
21-
end
22-
23-
test "encrypted secrets are deprecated when running edit without setup" do
24-
assert_match "Encrypted secrets is deprecated", run_setup_command
25-
assert_equal 1, $?.exitstatus
26-
assert_not File.exist?("config/secrets.yml.enc")
27-
end
28-
29-
test "encrypted secrets are deprecated for 5.1 config/secrets.yml apps" do
30-
Dir.chdir(app_path) do
31-
FileUtils.rm("config/credentials.yml.enc")
32-
FileUtils.touch("config/secrets.yml")
33-
34-
assert_match "Encrypted secrets is deprecated", run_setup_command
35-
assert_equal 1, $?.exitstatus
36-
assert_not File.exist?("config/secrets.yml.enc")
37-
end
38-
end
39-
4017
test "edit secrets" do
4118
# Use expected default MessageEncryptor serializer for Rails < 7.1 to be compatible with hardcoded secrets.yml.enc
4219
add_to_config <<-RUBY

0 commit comments

Comments
 (0)