Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Cloud secrets from Rails credentials #782

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/flipper/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Engine < Rails::Engine
end

initializer "flipper.default", before: :load_config_initializers do |app|
# Load cloud secrets from Rails credentials
ENV["FLIPPER_CLOUD_TOKEN"] ||= app.credentials.dig(:flipper, :cloud_token)
ENV["FLIPPER_CLOUD_SYNC_SECRET"] ||= app.credentials.dig(:flipper, :cloud_sync_secret)

require 'flipper/cloud' if cloud?

Flipper.configure do |config|
Expand Down
20 changes: 19 additions & 1 deletion spec/flipper/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Class.new(Rails::Application) do
config.eager_load = false
config.logger = ActiveSupport::Logger.new($stdout)
end
end.instance
end

before do
Expand Down Expand Up @@ -242,6 +242,24 @@
end
end

context 'with cloud secrets in Rails.credentials' do
before do
allow(application).to receive(:credentials).and_return({
flipper: {
cloud_token: "credentials-token",
cloud_sync_secret: "credentials-secret",
}
})
end

it "enables cloud" do
application.initialize!
expect(ENV["FLIPPER_CLOUD_TOKEN"]).to eq("credentials-token")
expect(ENV["FLIPPER_CLOUD_SYNC_SECRET"]).to eq("credentials-secret")
expect(Flipper.instance).to be_a(Flipper::Cloud::DSL)
end
end

it "includes model methods" do
subject
require 'active_record'
Expand Down