flipper-cloud 0.20.4 → 0.21.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a7975de45022ee964e72588441cebfcbb2381feb4657342c7423064a709d239
4
- data.tar.gz: 0d707e5f5ecda9181a6673df0537696d9c8046fe3a01956bee5091e72c39e58f
3
+ metadata.gz: 9ba3c2db9aa7175de2301fb4fea82a25164e935b0f0fe5d7ce38911eee319cf9
4
+ data.tar.gz: e97f8ec07dcc20057d6934e1cf933be9517d53549317539900630e43a7ffd23e
5
5
  SHA512:
6
- metadata.gz: 1833dab42fd2c96295317d99061a90b1e38b592bea66b4c7b672f013cd915cb09f476984545a244741cac62f37054a66e09e00eb1a0a287fd4b689153098baaa
7
- data.tar.gz: 00a7ade548bf735d0cd9ca2fbca6a74e1beb6b15c4719a34b06923db6ff9a56b8a43387a6810ec5ee204fd32dab0a916cd5d3f245176473b658dad75a31eb4f9
6
+ metadata.gz: 62d4f0cc6817cfa654e1980156ca7e4d9ba81d1c0bb761f37651455b20f0b4732ceafe1adbf5a30ca09f8c1f8b80b8609c9d61ef969b82be48eedd183e4a5c15
7
+ data.tar.gz: 4540506c2b1c4eabe0140f3757e0414977ef876454755106bedfffd8159a880ffea37b6bca24bde30e9e6b79259ad86e30afb415219f7a22104c91bcd4edfbe8
@@ -1,13 +1,9 @@
1
1
  # Usage (from the repo root):
2
- # env FLIPPER_CLOUD_TOKEN=<token> FLIPPER_CLOUD_SYNC_SECRET=<secret> FLIPPER_CLOUD_SYNC_METHOD=webhook bundle exec rackup examples/cloud/app.ru -p 9999
3
- # env FLIPPER_CLOUD_TOKEN=<token> FLIPPER_CLOUD_SYNC_SECRET=<secret> FLIPPER_CLOUD_SYNC_METHOD=webhook bundle exec shotgun examples/cloud/app.ru -p 9999
2
+ # env FLIPPER_CLOUD_TOKEN=<token> FLIPPER_CLOUD_SYNC_SECRET=<secret> bundle exec rackup examples/cloud/app.ru -p 9999
3
+ # env FLIPPER_CLOUD_TOKEN=<token> FLIPPER_CLOUD_SYNC_SECRET=<secret> bundle exec shotgun examples/cloud/app.ru -p 9999
4
4
  # http://localhost:9999/
5
5
 
6
- require 'pathname'
7
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
8
- lib_path = root_path.join('lib')
9
- $:.unshift(lib_path)
10
-
6
+ require 'bundler/setup'
11
7
  require 'flipper/cloud'
12
8
  Flipper.configure do |config|
13
9
  config.default { Flipper::Cloud.new }
@@ -1,11 +1,6 @@
1
1
  # Usage (from the repo root):
2
2
  # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/basic.rb
3
- require 'pathname'
4
- require 'logger'
5
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
- lib_path = root_path.join('lib')
7
- $:.unshift(lib_path)
8
-
3
+ require 'bundler/setup'
9
4
  require 'flipper/cloud'
10
5
  flipper = Flipper::Cloud.new
11
6
 
@@ -1,6 +1,5 @@
1
1
  # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/cached_in_memory.rb
2
- require File.expand_path('../../example_setup', __FILE__)
3
-
2
+ require 'bundler/setup'
4
3
  require 'flipper/cloud'
5
4
  require 'flipper/adapters/active_support_cache_store'
6
5
  require 'active_support/cache'
@@ -1,23 +1,15 @@
1
1
  # Usage (from the repo root):
2
2
  # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/import.rb
3
- require 'pathname'
4
- require 'logger'
5
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
- lib_path = root_path.join('lib')
7
- $:.unshift(lib_path)
8
-
3
+ require 'bundler/setup'
9
4
  require 'flipper'
10
5
  require 'flipper/cloud'
11
6
 
12
- memory_adapter = Flipper::Adapters::Memory.new
13
- flipper = Flipper.new(memory_adapter)
14
-
15
- flipper.enable(:test)
16
- flipper.enable(:search)
17
- flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
18
- flipper.enable_percentage_of_time(:logging, 5)
7
+ Flipper.enable(:test)
8
+ Flipper.enable(:search)
9
+ Flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
10
+ Flipper.enable_percentage_of_time(:logging, 5)
19
11
 
20
12
  cloud = Flipper::Cloud.new
21
13
 
22
14
  # makes cloud identical to memory flipper
23
- cloud.import(flipper)
15
+ cloud.import(Flipper)
@@ -6,8 +6,7 @@
6
6
  # unavailable, but we are hoping to fix that soon by doing the cloud update in a
7
7
  # background thread.
8
8
  # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/local_adapter.rb
9
- require File.expand_path('../../example_setup', __FILE__)
10
-
9
+ require 'bundler/setup'
11
10
  require 'logger'
12
11
  require 'flipper/cloud'
13
12
  require 'flipper/adapters/redis'
@@ -13,6 +13,8 @@ module Flipper
13
13
  :webhook,
14
14
  ].freeze
15
15
 
16
+ DEFAULT_URL = "https://www.flippercloud.io/adapter".freeze
17
+
16
18
  # Public: The token corresponding to an environment on flippercloud.io.
17
19
  attr_accessor :token
18
20
 
@@ -57,10 +59,6 @@ module Flipper
57
59
  # the local in sync with cloud (default: 10).
58
60
  attr_accessor :sync_interval
59
61
 
60
- # Public: The method to be used for synchronizing your local flipper
61
- # adapter with cloud. (default: :poll, can also be :webhook).
62
- attr_reader :sync_method
63
-
64
62
  # Public: The secret used to verify if syncs in the middleware should
65
63
  # occur or not.
66
64
  attr_accessor :sync_secret
@@ -72,6 +70,11 @@ module Flipper
72
70
  raise ArgumentError, "Flipper::Cloud token is missing. Please set FLIPPER_CLOUD_TOKEN or provide the token (e.g. Flipper::Cloud.new('token'))."
73
71
  end
74
72
 
73
+ if ENV["FLIPPER_CLOUD_SYNC_METHOD"]
74
+ warn "FLIPPER_CLOUD_SYNC_METHOD is deprecated and has no effect."
75
+ end
76
+ self.sync_method = options[:sync_method] if options[:sync_method]
77
+
75
78
  @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
76
79
  @read_timeout = options.fetch(:read_timeout) { ENV.fetch("FLIPPER_CLOUD_READ_TIMEOUT", 5).to_f }
77
80
  @open_timeout = options.fetch(:open_timeout) { ENV.fetch("FLIPPER_CLOUD_OPEN_TIMEOUT", 5).to_f }
@@ -81,8 +84,7 @@ module Flipper
81
84
  @local_adapter = options.fetch(:local_adapter) { Adapters::Memory.new }
82
85
  @debug_output = options[:debug_output]
83
86
  @adapter_block = ->(adapter) { adapter }
84
- self.sync_method = options.fetch(:sync_method) { ENV.fetch("FLIPPER_CLOUD_SYNC_METHOD", :poll).to_sym }
85
- self.url = options.fetch(:url) { ENV.fetch("FLIPPER_CLOUD_URL", "https://www.flippercloud.io/adapter".freeze) }
87
+ self.url = options.fetch(:url) { ENV.fetch("FLIPPER_CLOUD_URL", DEFAULT_URL) }
86
88
  end
87
89
 
88
90
  # Public: Read or customize the http adapter. Calling without a block will
@@ -114,18 +116,14 @@ module Flipper
114
116
  }).call
115
117
  end
116
118
 
117
- def sync_method=(new_sync_method)
118
- new_sync_method = new_sync_method.to_sym
119
-
120
- unless VALID_SYNC_METHODS.include?(new_sync_method)
121
- raise ArgumentError, "Unsupported sync_method. Valid options are (#{VALID_SYNC_METHODS.to_a.join(', ')})"
122
- end
123
-
124
- if new_sync_method == :webhook && sync_secret.nil?
125
- raise ArgumentError, "Flipper::Cloud sync_secret is missing. Please set FLIPPER_CLOUD_SYNC_SECRET or provide the sync_secret used to validate webhooks."
126
- end
119
+ # Public: The method that will be used to synchronize local adapter with
120
+ # cloud. (default: :poll, will be :webhook if sync_secret is set).
121
+ def sync_method
122
+ sync_secret ? :webhook : :poll
123
+ end
127
124
 
128
- @sync_method = new_sync_method
125
+ def sync_method=(_)
126
+ warn "Flipper::Cloud: sync_method is deprecated and has no effect."
129
127
  end
130
128
 
131
129
  private
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.4'.freeze
2
+ VERSION = '0.21.0.rc1'.freeze
3
3
  end
@@ -127,53 +127,30 @@ RSpec.describe Flipper::Cloud::Configuration do
127
127
  end
128
128
  end
129
129
 
130
- it "defaults to sync_method to poll" do
131
- memory_adapter = Flipper::Adapters::Memory.new
130
+ it "defaults sync_method to :poll" do
132
131
  instance = described_class.new(required_options)
133
132
 
134
133
  expect(instance.sync_method).to eq(:poll)
135
134
  end
136
135
 
137
- it "can use webhook for sync_method" do
138
- memory_adapter = Flipper::Adapters::Memory.new
136
+ it "sets sync_method to :webhook if sync_secret provided" do
139
137
  instance = described_class.new(required_options.merge({
140
138
  sync_secret: "secret",
141
- sync_method: :webhook,
142
- local_adapter: memory_adapter,
143
139
  }))
144
140
 
145
141
  expect(instance.sync_method).to eq(:webhook)
146
142
  expect(instance.adapter).to be_instance_of(Flipper::Adapters::DualWrite)
147
143
  end
148
144
 
149
- it "raises ArgumentError for invalid sync_method" do
150
- expect {
151
- described_class.new(required_options.merge(sync_method: :foo))
152
- }.to raise_error(ArgumentError, "Unsupported sync_method. Valid options are (poll, webhook)")
153
- end
154
-
155
- it "can use ENV var for sync_method" do
156
- with_modified_env "FLIPPER_CLOUD_SYNC_METHOD" => "webhook" do
157
- instance = described_class.new(required_options.merge({
158
- sync_secret: "secret",
159
- }))
145
+ it "sets sync_method to :webhook if FLIPPER_CLOUD_SYNC_SECRET set" do
146
+ with_modified_env "FLIPPER_CLOUD_SYNC_SECRET" => "abc" do
147
+ instance = described_class.new(required_options)
160
148
 
161
149
  expect(instance.sync_method).to eq(:webhook)
150
+ expect(instance.adapter).to be_instance_of(Flipper::Adapters::DualWrite)
162
151
  end
163
152
  end
164
153
 
165
- it "can use string sync_method instead of symbol" do
166
- memory_adapter = Flipper::Adapters::Memory.new
167
- instance = described_class.new(required_options.merge({
168
- sync_secret: "secret",
169
- sync_method: "webhook",
170
- local_adapter: memory_adapter,
171
- }))
172
-
173
- expect(instance.sync_method).to eq(:webhook)
174
- expect(instance.adapter).to be_instance_of(Flipper::Adapters::DualWrite)
175
- end
176
-
177
154
  it "can set sync_secret" do
178
155
  instance = described_class.new(required_options.merge(sync_secret: "from_config"))
179
156
  expect(instance.sync_secret).to eq("from_config")
@@ -9,7 +9,6 @@ RSpec.describe Flipper::Cloud::DSL do
9
9
  cloud_configuration = Flipper::Cloud::Configuration.new({
10
10
  token: "asdf",
11
11
  sync_secret: "tasty",
12
- sync_method: :webhook,
13
12
  })
14
13
  dsl = described_class.new(cloud_configuration)
15
14
  expect(dsl.features).to eq(Set.new)
@@ -26,7 +25,6 @@ RSpec.describe Flipper::Cloud::DSL do
26
25
  cloud_configuration = Flipper::Cloud::Configuration.new({
27
26
  token: "asdf",
28
27
  sync_secret: "tasty",
29
- sync_method: :webhook,
30
28
  })
31
29
  dsl = described_class.new(cloud_configuration)
32
30
  dsl.sync
@@ -37,7 +35,6 @@ RSpec.describe Flipper::Cloud::DSL do
37
35
  cloud_configuration = Flipper::Cloud::Configuration.new({
38
36
  token: "asdf",
39
37
  sync_secret: "tasty",
40
- sync_method: :webhook,
41
38
  })
42
39
  dsl = described_class.new(cloud_configuration)
43
40
  expect(dsl.sync_secret).to eq("tasty")
@@ -52,7 +49,6 @@ RSpec.describe Flipper::Cloud::DSL do
52
49
  cloud_configuration = Flipper::Cloud::Configuration.new({
53
50
  token: "asdf",
54
51
  sync_secret: "tasty",
55
- sync_method: :webhook,
56
52
  local_adapter: local_adapter
57
53
  })
58
54
  end
@@ -9,7 +9,6 @@ RSpec.describe Flipper::Cloud::Middleware do
9
9
  Flipper::Cloud.new("regular") do |config|
10
10
  config.local_adapter = Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new)
11
11
  config.sync_secret = "regular_tasty"
12
- config.sync_method = :webhook
13
12
  end
14
13
  }
15
14
 
@@ -17,7 +16,6 @@ RSpec.describe Flipper::Cloud::Middleware do
17
16
  Flipper::Cloud.new("env") do |config|
18
17
  config.local_adapter = Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new)
19
18
  config.sync_secret = "env_tasty"
20
- config.sync_method = :webhook
21
19
  end
22
20
  }
23
21
 
@@ -105,7 +103,7 @@ RSpec.describe Flipper::Cloud::Middleware do
105
103
 
106
104
  expect(last_response.status).to eq(402)
107
105
  expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
108
- expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to eq("Failed with status: 402")
106
+ expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to include("Failed with status: 402")
109
107
  expect(stub).to have_been_requested
110
108
  end
111
109
  end
@@ -128,7 +126,7 @@ RSpec.describe Flipper::Cloud::Middleware do
128
126
 
129
127
  expect(last_response.status).to eq(500)
130
128
  expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
131
- expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to eq("Failed with status: 503")
129
+ expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to include("Failed with status: 503")
132
130
  expect(stub).to have_been_requested
133
131
  end
134
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.4
4
+ version: 0.21.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flipper
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.4
19
+ version: 0.21.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.20.4
26
+ version: 0.21.0.rc1
27
27
  description:
28
28
  email:
29
29
  - nunemaker@gmail.com
@@ -66,9 +66,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ">="
69
+ - - ">"
70
70
  - !ruby/object:Gem::Version
71
- version: '0'
71
+ version: 1.3.1
72
72
  requirements: []
73
73
  rubygems_version: 3.0.3
74
74
  signing_key: