Skip to content

Commit

Permalink
Merge pull request #2440 from alphagov/fix-deprecation-warnings
Browse files Browse the repository at this point in the history
Move secrets to credentials to stop secrets deprecation warning
  • Loading branch information
syed-ali-tw authored Nov 28, 2024
2 parents df13c6e + 6c88973 commit 97c3df6
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/link_checker_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def verify_signature
end

def webhook_secret_token
Rails.application.secrets.link_checker_api_secret_token
Rails.application.credentials.link_checker_api_secret_token
end
end
2 changes: 1 addition & 1 deletion app/services/link_check_report_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def call_link_checker_api
GdsApi.link_checker_api.create_batch(
uris,
webhook_uri: callback_url,
webhook_secret_token: Rails.application.secrets.link_checker_api_secret_token,
webhook_secret_token: Rails.application.credentials.link_checker_api_secret_token,
)
end

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Application < Rails::Application
config.asset_host = ENV.fetch("ASSET_HOST", nil)

config.action_mailer.notify_settings = {
api_key: Rails.application.secrets.notify_api_key || "fake-test-api-key",
api_key: Rails.application.credentials.notify_api_key || "fake-test-api-key",
}

config.generators do |g|
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/secrets_to_credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Rails 7 has begun to deprecate Rails.application.secrets in favour
# of Rails.application.credentials, but that adds the burden of master key
# administration without giving us any benefit (because our production
# secrets are handled as env vars, not committed to our repo. Here we
# load the config/secrets.YML values into Rails.application.credentials,
# retaining the existing behaviour while dropping deprecated references.
Rails.application.credentials.merge!(Rails.application.config_for(:secrets))
2 changes: 1 addition & 1 deletion test/functional/link_check_reports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LinkCheckReportsControllerTest < ActionController::TestCase
uris: ["https://www.gov.uk"],
id: 1234,
webhook_uri: link_checker_api_callback_url(host: Plek.find("publisher")),
webhook_secret_token: Rails.application.secrets.link_checker_api_secret_token,
webhook_secret_token: Rails.application.credentials.link_checker_api_secret_token,
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/functional/link_checker_api_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def campaign_edition_link_check_report
def set_headers(post_body)
headers = {
"Content-Type": "application/json",
"X-LinkCheckerApi-Signature": generate_signature(post_body.to_json, Rails.application.secrets.link_checker_api_secret_token),
"X-LinkCheckerApi-Signature": generate_signature(post_body.to_json, Rails.application.credentials.link_checker_api_secret_token),
}

request.headers.merge! headers
Expand Down
2 changes: 1 addition & 1 deletion test/integration/edition_link_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EditionLinkCheckTest < LegacyJavascriptIntegrationTest
uris: ["https://www.gov.uk"],
id: 1234,
webhook_uri: link_checker_api_callback_url(host: Plek.find("publisher")),
webhook_secret_token: Rails.application.secrets.link_checker_api_secret_token,
webhook_secret_token: Rails.application.credentials.link_checker_api_secret_token,
)

@place = FactoryBot.create(:place_edition, introduction: "This is [link](https://www.gov.uk) text.")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/services/link_check_report_creator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_edition(govspeak)
uris: ["https://www.gov.uk"],
id: 1234,
webhook_uri: link_checker_api_callback_url(host: Plek.find("publisher")),
webhook_secret_token: Rails.application.secrets.link_checker_api_secret_token,
webhook_secret_token: Rails.application.credentials.link_checker_api_secret_token,
)
end

Expand Down

0 comments on commit 97c3df6

Please sign in to comment.