Skip to content

Commit

Permalink
Move secrets to credentials to stop secrets deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
syed-ali-tw committed Nov 27, 2024
1 parent 1932ab6 commit 6c88973
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 6c88973

Please sign in to comment.