Skip to content

Commit

Permalink
Merge pull request #23254 from jrafanie/use-application-credentials-i…
Browse files Browse the repository at this point in the history
…nstead-of-secrets

Use Rails.application.credentials instead of deprecated secrets
  • Loading branch information
agrare committed Nov 4, 2024
2 parents f00ba4d + 4c49059 commit dca9857
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 0 additions & 5 deletions app/models/mixins/miq_web_server_worker_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ def configure_secret_token(token = MiqDatabase.first.session_secret_token)
return if Rails.application.config.secret_key_base

Rails.application.config.secret_key_base = token

# To set a secret token after the Rails.application is initialized,
# we need to reset the secrets since they are cached:
# https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/application.rb#L386-L401
Rails.application.secrets = nil
end

def rails_server
Expand Down
6 changes: 3 additions & 3 deletions spec/models/firmware_registry/rest_api_depot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
VCR.turn_on!
end

let(:host) { Rails.application.secrets.fwreg_rest_api_depot.try(:[], 'host') || 'host' }
let(:user) { Rails.application.secrets.fwreg_rest_api_depot.try(:[], 'userid') || 'username' }
let(:pass) { Rails.application.secrets.fwreg_rest_api_depot.try(:[], 'password') || 'password' }
let(:host) { Rails.application.credentials.fwreg_rest_api_depot.try(:[], 'host') || 'host' }
let(:user) { Rails.application.credentials.fwreg_rest_api_depot.try(:[], 'userid') || 'username' }
let(:pass) { Rails.application.credentials.fwreg_rest_api_depot.try(:[], 'password') || 'password' }
let(:url) { "http://#{host}/images/" }

describe '.fetch_from_remote' do
Expand Down
10 changes: 5 additions & 5 deletions spec/models/mixins/miq_web_server_worker_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
end

before do
@token = Rails.application.config.secret_key_base
@secrets = Rails.application.secrets
@token = Rails.application.config.secret_key_base
@credentials = Rails.application.credentials
MiqDatabase.seed
end

after do
Rails.application.config.secret_key_base = @token
Rails.application.secrets = @secrets
Rails.application.credentials = @credentials
end

it ".configure_secret_token defaults to MiqDatabase session_secret_token" do
Expand All @@ -43,8 +43,8 @@
it ".configure_secret_token does not reset secrets when token already configured" do
existing_value = SecureRandom.hex(64)
Rails.application.config.secret_key_base = existing_value
Rails.application.secrets = nil
Rails.application.secrets
Rails.application.credentials = nil
Rails.application.credentials

test_class.configure_secret_token
expect(Rails.application.config.secret_key_base).to eq(existing_value)
Expand Down

0 comments on commit dca9857

Please sign in to comment.