From ddcd8dfc699cb630906748b9aa164a9b4cd8423b Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Tue, 12 Aug 2025 14:37:45 +0200 Subject: [PATCH] Drop Rails.application.secrets usage That feature is gone and we already use environment variables... https://github.com/rails/rails/pull/47801 --- app/helpers/users_helper.rb | 5 -- app/views/payments/_payment.html.haml | 2 +- config/initializers/devise.rb | 8 ++- config/initializers/sentry.rb | 2 +- config/initializers/stripe.rb | 2 +- config/secrets.yml.example | 73 -------------------------- spec/features/ticket_purchases_spec.rb | 6 +-- 7 files changed, 9 insertions(+), 89 deletions(-) delete mode 100644 config/secrets.yml.example diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 906e6f3b..0cf86258 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -14,11 +14,6 @@ module UsersHelper providers = [] Devise.omniauth_providers.each do |provider| - provider_key = "#{provider}_key" - provider_secret = "#{provider}_secret" - unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank? - providers << provider - end providers << provider if ENV.fetch("OSEM_#{provider.upcase}_KEY", nil).present? && ENV.fetch("OSEM_#{provider.upcase}_SECRET", nil).present? end diff --git a/app/views/payments/_payment.html.haml b/app/views/payments/_payment.html.haml index 3fa79e6b..c8481182 100644 --- a/app/views/payments/_payment.html.haml +++ b/app/views/payments/_payment.html.haml @@ -23,5 +23,5 @@ %script.stripe-button{ src: "https://checkout.stripe.com/checkout.js", data: { amount: @total_amount_to_pay.cents, label: "Pay #{humanized_money_with_symbol @total_amount_to_pay}", email: current_user.email, currency: @total_amount_to_pay.currency, name: ENV.fetch('OSEM_NAME', 'OSEM'), - description: "book your tickets", key: Rails.application.secrets.stripe_publishable_key, locale: "auto"}} + description: "book your tickets", key: ENV.fetch('STRIPE_PUBLISHABLE_KEY'), locale: "auto"}} = link_to 'Edit Purchase', conference_tickets_path(@conference.short_title), class: 'btn btn-default' diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 69c2d9e3..66d240fa 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -7,11 +7,9 @@ Devise.setup do |config| # Pass each provider to User model in :omniauth_providers (for open_id providers use their name) config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user' - config.omniauth :google_oauth2, ENV.fetch('OSEM_GOOGLE_KEY', Rails.application.secrets.google_key), ENV.fetch('OSEM_GOOGLE_SECRET', Rails.application.secrets.google_secret), - name: 'google', - scope: 'email' - config.omniauth :facebook, ENV.fetch('OSEM_FACEBOOK_KEY', Rails.application.secrets.facebook_key), ENV.fetch('OSEM_FACEBOOK_SECRET', Rails.application.secrets.facebook_secret) - config.omniauth :github, ENV.fetch('OSEM_GITHUB_KEY', Rails.application.secrets.github_key), ENV.fetch('OSEM_GITHUB_SECRET', Rails.application.secrets.github_secret) + config.omniauth :google_oauth2, ENV.fetch('OSEM_GOOGLE_KEY', nil), ENV.fetch('OSEM_GOOGLE_SECRET', nil), name: 'google', scope: 'email' + config.omniauth :facebook, ENV.fetch('OSEM_FACEBOOK_KEY', nil), ENV.fetch('OSEM_FACEBOOK_SECRET', nil) + config.omniauth :github, ENV.fetch('OSEM_GITHUB_KEY', nil), ENV.fetch('OSEM_GITHUB_SECRET', nil) # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 06ff5874..ebee88d4 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,5 +1,5 @@ Sentry.init do |config| - config.dsn = ENV.fetch('OSEM_SENTRY_DSN', Rails.application.secrets.sentry_dsn) + config.dsn = ENV.fetch('OSEM_SENTRY_DSN', nil) config.breadcrumbs_logger = [:active_support_logger] # To activate performance monitoring, set one of these options. diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb index 555cc16f..f40ad45d 100644 --- a/config/initializers/stripe.rb +++ b/config/initializers/stripe.rb @@ -1 +1 @@ -Stripe.api_key = Rails.application.secrets.stripe_secret_key +Stripe.api_key = ENV.fetch('STRIPE_SECRET_KEY', nil) diff --git a/config/secrets.yml.example b/config/secrets.yml.example deleted file mode 100644 index c0d92bbf..00000000 --- a/config/secrets.yml.example +++ /dev/null @@ -1,73 +0,0 @@ -development: - # Generate your own with rake secret - # secret_key_base: '12345' - - ########## OMNIAUTH Providers ########## - # This is just sample data so mocks work - google_key: 'sample' - google_secret: 'sample' - - facebook_key: 'sample' - facebook_secret: 'sample' - - suse_key: 'sample' - suse_secret: 'sample' - - # Register on stripe and add TEST keys here - # https://dashboard.stripe.com/account/apikeys - stripe_publishable_key: <%= ENV['STRIPE_PUBLISHABLE_KEY'] %> - stripe_secret_key: <%= ENV['STRIPE_SECRET_KEY'] %> - -test: - # Generate your own with rake secret - # secret_key_base: '12345' - - # Register on stripe and add TEST keys here - # https://dashboard.stripe.com/account/apikeys - stripe_publishable_key: <%= ENV['STRIPE_PUBLISHABLE_KEY'] %> - stripe_secret_key: <%= ENV['STRIPE_SECRET_KEY'] %> - -production: - # Generate your own with rake secret or use the environment - # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - - # Your sentry.io DSN key - # sentry_dsn: '12345' - - ########## OMNIAUTH Providers ########## - # Leave the variables' names empty, unless you use the providers, in which - # case you need to register your applicaton and add the actual keys. - # - # If you add a provider, keep the format of the variables: - # *provider*_key and *provider*_secret - - # If you add a provider that does not require a key, you still have to - # create the 2 variables with sample data or they won't show up in the app. - - # Register your appllication with Google from - # https://code.google.com/apis/console#:access - google_key: '' - google_secret: '' - - # Register your application with Facebook from - # https://developers.facebook.com/ - facebook_key: '' - facebook_secret: '' - - # Developers do not need to register their application for suse account to - # work. You must, however, add some sample value to the variables, for the - # login option to appear. For example: - #suse_key: 'sample data' - #suse_secret: 'sample data' - suse_key: '' - suse_secret: '' - - # Register your application with GitHub from - # https://github.com/settings/applications - github_key: '' - github_secret: '' - - # Register on stripe and add LIVE keys here - # https://dashboard.stripe.com/account/apikeys - stripe_publishable_key: <%= ENV['STRIPE_PUBLISHABLE_KEY'] %> - stripe_secret_key: <%= ENV['STRIPE_SECRET_KEY'] %> diff --git a/spec/features/ticket_purchases_spec.rb b/spec/features/ticket_purchases_spec.rb index 22250679..7f41dfc6 100644 --- a/spec/features/ticket_purchases_spec.rb +++ b/spec/features/ticket_purchases_spec.rb @@ -42,7 +42,7 @@ feature Registration do purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first expect(purchase.quantity).to eq(2) - if Rails.application.secrets.stripe_publishable_key + if ENV.fetch('STRIPE_PUBLISHABLE_KEY', nil) find('.stripe-button-el').click stripe_iframe = all('iframe[name=stripe_checkout_app]').last @@ -81,7 +81,7 @@ feature Registration do purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first expect(purchase.quantity).to eq(2) - if Rails.application.secrets.stripe_publishable_key + if ENV.fetch('STRIPE_PUBLISHABLE_KEY', nil) find('.stripe-button-el').click stripe_iframe = all('iframe[name=stripe_checkout_app]').last @@ -172,7 +172,7 @@ feature Registration do purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first expect(purchase.quantity).to eq(2) - if Rails.application.secrets.stripe_publishable_key + if ENV.fetch('STRIPE_PUBLISHABLE_KEY', nil) find('.stripe-button-el').click stripe_iframe = all('iframe[name=stripe_checkout_app]').last