From 45ef4abaf9c26dce8c7958ef7c9ccafaf9db7325 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Mon, 17 Jul 2023 14:42:59 -0400 Subject: [PATCH] Avoid any possibility of sync writing back to remote --- lib/flipper/cloud/configuration.rb | 9 +++------ spec/flipper/cloud/configuration_spec.rb | 2 +- spec/flipper/cloud_spec.rb | 15 +++++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/flipper/cloud/configuration.rb b/lib/flipper/cloud/configuration.rb index 23a1fc8e4..47a5eab10 100644 --- a/lib/flipper/cloud/configuration.rb +++ b/lib/flipper/cloud/configuration.rb @@ -156,11 +156,8 @@ def sync_method private def app_adapter - sync_method == :webhook ? dual_write_adapter : poll_adapter - end - - def dual_write_adapter - Flipper::Adapters::DualWrite.new(local_adapter, http_adapter) + read_adapter = sync_method == :webhook ? local_adapter : poll_adapter + Flipper::Adapters::DualWrite.new(read_adapter, http_adapter) end def poller @@ -172,7 +169,7 @@ def poller end def poll_adapter - Flipper::Adapters::Poll.new(poller, dual_write_adapter) + Flipper::Adapters::Poll.new(poller, local_adapter) end def http_adapter diff --git a/spec/flipper/cloud/configuration_spec.rb b/spec/flipper/cloud/configuration_spec.rb index 12ff2972f..241c61d44 100644 --- a/spec/flipper/cloud/configuration_spec.rb +++ b/spec/flipper/cloud/configuration_spec.rb @@ -86,7 +86,7 @@ stub_request(:get, /flippercloud\.io/).to_return(status: 200, body: "{}") instance = described_class.new(required_options) - expect(instance.adapter).to be_instance_of(Flipper::Adapters::Poll) + expect(instance.adapter).to be_instance_of(Flipper::Adapters::DualWrite) end it "can override adapter block" do diff --git a/spec/flipper/cloud_spec.rb b/spec/flipper/cloud_spec.rb index 8fcfad46e..8d7bf8bbc 100644 --- a/spec/flipper/cloud_spec.rb +++ b/spec/flipper/cloud_spec.rb @@ -25,11 +25,10 @@ it 'configures the correct adapter' do # pardon the nesting... memoized_adapter = @instance.adapter - poll_adapter = memoized_adapter.adapter - dual_write_adapter = poll_adapter.adapter - - expect(poll_adapter).to be_instance_of(Flipper::Adapters::Poll) + dual_write_adapter = memoized_adapter.adapter expect(dual_write_adapter).to be_instance_of(Flipper::Adapters::DualWrite) + poll_adapter = dual_write_adapter.local + expect(poll_adapter).to be_instance_of(Flipper::Adapters::Poll) http_adapter = dual_write_adapter.remote client = http_adapter.client @@ -43,8 +42,12 @@ context 'initialize with token and options' do it 'sets correct url' do - @instance = described_class.new(token: 'asdf', url: 'https://www.fakeflipper.com/sadpanda') - uri = @instance.adapter.adapter.adapter.remote.client.uri + instance = described_class.new(token: 'asdf', url: 'https://www.fakeflipper.com/sadpanda') + # pardon the nesting... + memoized = instance.adapter + dual_write = memoized.adapter + remote = dual_write.remote + uri = remote.client.uri expect(uri.scheme).to eq('https') expect(uri.host).to eq('www.fakeflipper.com') expect(uri.path).to eq('/sadpanda')