diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index ec15021..c1d6ba2 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -33,7 +33,7 @@ jobs: - ruby: "3.2" gemfile: "gemfiles/rails7.gemfile" rbs: 'false' - - ruby: "3.2" + - ruby: "3.3" gemfile: "gemfiles/railsmaster.gemfile" rbs: 'false' - ruby: "3.1" @@ -69,9 +69,6 @@ jobs: - name: Run RSpec without rails run: | bundle exec rake spec:norails - - name: Run Rails secrets tests for uninitialized app - run: | - bundle exec rake spec:secrets - name: Run Rails autoload tests run: | bundle exec rake spec:autoload diff --git a/README.md b/README.md index 8d344b5..ec9fe91 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ end Using Ruby classes to represent configuration allows you to add helper methods and computed parameters easily, makes the configuration **testable**. -The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials/secrets, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality. +The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality. Check out the libraries using Anyway Config for more examples: @@ -270,7 +270,6 @@ This feature is similar to `Rails.application.config_for` but more powerful: | Feature | Rails | Anyway Config | | ------------- |-------------:| -----:| | Load data from `config/app.yml` | ✅ | ✅ | -| Load data from `secrets` | ❌ | ✅ | | Load data from `credentials` | ❌ | ✅ | | Load data from environment | ❌ | ✅ | | Load data from [other sources](#data-loaders) | ❌ | ✅ | diff --git a/Rakefile b/Rakefile index 870ead9..8f757d8 100644 --- a/Rakefile +++ b/Rakefile @@ -20,15 +20,6 @@ RSpec::Core::RakeTask.new("spec:norails") do |task| task.verbose = false end -desc "Run Rails secrets tests for uninitialized app" -RSpec::Core::RakeTask.new("spec:secrets") do |task| - ENV["DO_NOT_INITIALIZE_RAILS"] = "1" - ENV["USE_APP_CONFIGS"] = "0" - ENV["NORAILS"] = "0" - task.rspec_opts = "--order defined --tag secrets" - task.verbose = false -end - desc "Run Rails autoload tests for app/configs" RSpec::Core::RakeTask.new("spec:autoload") do |task| ENV["USE_APP_CONFIGS"] = "1" @@ -107,4 +98,4 @@ namespace :spec do end desc "Run the all specs" -task default: %w[rubocop rubocop:md steep spec:norails spec spec:secrets spec:autoload spec:rbs] +task default: %w[rubocop rubocop:md steep spec:norails spec spec:autoload spec:rbs] diff --git a/spec/config_spec.rb b/spec/config_spec.rb index a94cf07..63fa48d 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -455,7 +455,7 @@ def submeta=(val) end end - describe "#to_source_trace" do + describe "#to_source_trace", env_kot: false do let(:conf) { CoolConfig.new } around do |ex| @@ -606,7 +606,7 @@ def submeta=(val) end end - describe "#pretty_print" do + describe "#pretty_print", env_kot: false do let(:overrides) { {} } let(:conf) { CoolConfig.new(overrides) } diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index fa87ccf..05dfe4b 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -10,6 +10,7 @@ module Dummy class Application < Rails::Application + config.load_defaults Rails::VERSION::STRING.split(".").take(2).join(".").to_f config.logger = Logger.new("/dev/null") config.eager_load = ENV["DO_NOT_INITIALIZE_RAILS"] != "1" diff --git a/spec/dummy/config/secrets.yml b/spec/dummy/config/secrets.yml deleted file mode 100644 index 5daf753..0000000 --- a/spec/dummy/config/secrets.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure the secrets in this file are kept private -# if you're sharing your code publicly. - -development: - secret_key_base: 0acf417376117dfb765e573f21090cf03217b8f0a8eaa301813c8a25c66139b5615f0e93fada39ec81599953468e792344810390008ca6ec90db825dc6b096c8 - -test: - secret_key_base: 164c31e4e77c1f37bbe4ce13c8f975beb0c21472e1eee6f08f2186b10b198586fcac88d161b9c2ac455acfac444c1cad4bf7c695f58e04ca2bf75c4028a9e967 - cool: - user: - name: test - bull: 'mooo' - meta: - kot: "leta" - my_app: - name: 'app' - secret: 'my_secret' - elshit: 'UUU' - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/spec/dynamic_config_spec.rb b/spec/dynamic_config_spec.rb index 37a97c9..947a7a6 100644 --- a/spec/dynamic_config_spec.rb +++ b/spec/dynamic_config_spec.rb @@ -15,9 +15,6 @@ data = Anyway::Config.for(:my_app) expect(data[:test]).to eq 1 expect(data[:name]).to eq "my_app" - unless NOSECRETS - expect(data[:secret]).to eq "my_secret" - end expect(data[:credo]).to eq "my_credo" if Rails.application.respond_to?(:credentials) end @@ -49,7 +46,6 @@ data = Anyway::Config.for(:my_app) expect(data[:test]).to eq 1 expect(data[:name]).to eq "my_app" - expect(data[:secret]).to eq "my_secret" unless NOSECRETS expect(data[:credo]).to eq "my_credo" if Rails.application.respond_to?(:credentials) expect(data[:credo_local]).to eq "betheone" if Rails.application.respond_to?(:credentials) end diff --git a/spec/rails/config_spec.rb b/spec/rails/config_spec.rb index d3fd4d9..2acbd80 100644 --- a/spec/rails/config_spec.rb +++ b/spec/rails/config_spec.rb @@ -21,13 +21,12 @@ if !NORAILS if Rails.application.respond_to?(:credentials) - it "load config from secrets and credentials" do + it "load config from credentials" do expect(conf.user[:name]).to eq "secret man" - expect(conf.meta).to eq("kot" => "leta") expect(conf.user[:password]).to eq "root" end - it "sets overrides after loading secrets" do + it "sets overrides after loading" do config = CoolConfig.new(user: {"password" => "override"}) expect(config.user[:name]).to eq "secret man" expect(config.user[:password]).to eq "override" @@ -43,7 +42,7 @@ end end - context "when using local files" do + context "when using local files", env_kot: false do around do |ex| Anyway::Settings.use_local_files = true ex.run @@ -52,9 +51,7 @@ it "load config local credentials too" do expect(conf.user[:name]).to eq "secret man" - unless NOSECRETS - expect(conf.meta).to eq("kot" => "murkot") - end + expect(conf.meta).to eq("kot" => "murkot") expect(conf.user[:password]).to eq "password" end end @@ -81,7 +78,7 @@ }, "port" => {value: 8080, source: {type: :defaults}}, "meta" => { - "kot" => {value: "leta", source: NOSECRETS ? {type: :env, key: "COOL_META__KOT"} : {type: :secrets}} + "kot" => {value: "leta", source: {type: :env, key: "COOL_META__KOT"}} } } ) diff --git a/spec/rails/loaders/secrets_spec.rb b/spec/rails/loaders/secrets_spec.rb deleted file mode 100644 index af56893..0000000 --- a/spec/rails/loaders/secrets_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -describe "Anyway::Rails::Loaders::Secrets", :rails, :secrets, skip: NORAILS || !Rails.application.respond_to?(:secrets) do - subject { Anyway::Rails::Loaders::Secrets.call(**options) } - - let(:options) { {name: "cool", some_other: "value"} } - - specify do - expect(subject).to eq( - { - user: { - name: "test" - }, - bull: "mooo", - meta: { - kot: "leta" - } - } - ) - end - - context "when no secrets" do - let(:options) { {name: "cooler"} } - - it "returns empty hash" do - expect(subject).to eq({}) - end - end - - if ENV["DO_NOT_INITIALIZE_RAILS"] == "1" - it "reset ::Rails.application.secrets state" do - ::Rails.application.secrets.reset = "me" - subject - expect(::Rails.application.secrets.reset).to be_nil - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce467ae..3c2b665 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -51,10 +51,9 @@ config.filter_run :focus config.run_all_when_everything_filtered = true - if NOSECRETS - config.around(:each, type: :config) do |ex| - with_env("COOL_META__KOT" => "leta", &ex) - end + config.around(:each, type: :config) do |ex| + next ex.run if ex.metadata[:env_kot] == false + with_env("COOL_META__KOT" => "leta", &ex) end config.order = :random