flipper-cloud 0.20.3 → 0.20.4

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: 7ac2ac6d779943f69836c9d8c6e4bcd58d45b31947114b09c154f2045285c006
4
- data.tar.gz: f80e71c83eea9aa839dc80141fb56b2e8701f0ba431b3baa62b62ac77bbfff4f
3
+ metadata.gz: 4a7975de45022ee964e72588441cebfcbb2381feb4657342c7423064a709d239
4
+ data.tar.gz: 0d707e5f5ecda9181a6673df0537696d9c8046fe3a01956bee5091e72c39e58f
5
5
  SHA512:
6
- metadata.gz: 50bd6b0bf3aaa5b1a825b297a1cac4ebf6d6e849bc25dd0d1bd6d8fea38b47677da4095f3ba9c5237b622aebd5c49cb905176efb8e40d7b9a0cc2e88ba0f5a55
7
- data.tar.gz: 25ab8c3a7e347383660023830a8ff46af6e14176f6875c6812b92825c7abbcd8133b56c9fb971139417f3ce2843c0925c408c7968b456864cc9af3680cf5cbb0
6
+ metadata.gz: 1833dab42fd2c96295317d99061a90b1e38b592bea66b4c7b672f013cd915cb09f476984545a244741cac62f37054a66e09e00eb1a0a287fd4b689153098baaa
7
+ data.tar.gz: 00a7ade548bf735d0cd9ca2fbca6a74e1beb6b15c4719a34b06923db6ff9a56b8a43387a6810ec5ee204fd32dab0a916cd5d3f245176473b658dad75a31eb4f9
Binary file
@@ -1,8 +1,7 @@
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/ui/basic.ru -p 9999
3
- # env FLIPPER_CLOUD_TOKEN=<token> FLIPPER_CLOUD_SYNC_SECRET=<secret> FLIPPER_CLOUD_SYNC_METHOD=webhook bundle exec shotgun examples/ui/basic.ru -p 9999
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
4
4
  # http://localhost:9999/
5
- # http://localhost:9999/webhooks
6
5
 
7
6
  require 'pathname'
8
7
  root_path = Pathname(__FILE__).dirname.join('..').expand_path
@@ -7,6 +7,8 @@ module Flipper
7
7
  class Middleware
8
8
  # Internal: The path to match for webhook requests.
9
9
  WEBHOOK_PATH = %r{\A/webhooks\/?\Z}
10
+ # Internal: The root path to match for requests.
11
+ ROOT_PATH = %r{\A/\Z}
10
12
 
11
13
  def initialize(app, options = {})
12
14
  @app = app
@@ -19,7 +21,7 @@ module Flipper
19
21
 
20
22
  def call!(env)
21
23
  request = Rack::Request.new(env)
22
- if request.post? && request.path_info.match(WEBHOOK_PATH)
24
+ if request.post? && (request.path_info.match(ROOT_PATH) || request.path_info.match(WEBHOOK_PATH))
23
25
  status = 200
24
26
  headers = {
25
27
  "Content-Type" => "application/json",
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.3'.freeze
2
+ VERSION = '0.20.4'.freeze
3
3
  end
@@ -53,7 +53,7 @@ RSpec.describe Flipper::Cloud::Middleware do
53
53
  env = {
54
54
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
55
55
  }
56
- post '/webhooks', request_body, env
56
+ post '/', request_body, env
57
57
 
58
58
  expect(last_response.status).to eq(200)
59
59
  expect(JSON.parse(last_response.body)).to eq({
@@ -80,7 +80,7 @@ RSpec.describe Flipper::Cloud::Middleware do
80
80
  env = {
81
81
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
82
82
  }
83
- post '/webhooks', request_body, env
83
+ post '/', request_body, env
84
84
 
85
85
  expect(last_response.status).to eq(400)
86
86
  expect(stub).not_to have_been_requested
@@ -101,7 +101,7 @@ RSpec.describe Flipper::Cloud::Middleware do
101
101
  env = {
102
102
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
103
103
  }
104
- post '/webhooks', request_body, env
104
+ post '/', request_body, env
105
105
 
106
106
  expect(last_response.status).to eq(402)
107
107
  expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
@@ -124,7 +124,7 @@ RSpec.describe Flipper::Cloud::Middleware do
124
124
  env = {
125
125
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
126
126
  }
127
- post '/webhooks', request_body, env
127
+ post '/', request_body, env
128
128
 
129
129
  expect(last_response.status).to eq(500)
130
130
  expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
@@ -147,7 +147,7 @@ RSpec.describe Flipper::Cloud::Middleware do
147
147
  env = {
148
148
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
149
149
  }
150
- post '/webhooks', request_body, env
150
+ post '/', request_body, env
151
151
 
152
152
  expect(last_response.status).to eq(500)
153
153
  expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Net::OpenTimeout")
@@ -168,7 +168,7 @@ RSpec.describe Flipper::Cloud::Middleware do
168
168
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
169
169
  'flipper' => env_flipper,
170
170
  }
171
- post '/webhooks', request_body, env
171
+ post '/', request_body, env
172
172
 
173
173
  expect(last_response.status).to eq(200)
174
174
  expect(stub).to have_been_requested
@@ -187,7 +187,7 @@ RSpec.describe Flipper::Cloud::Middleware do
187
187
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
188
188
  'flipper' => env_flipper,
189
189
  }
190
- post '/webhooks', request_body, env
190
+ post '/', request_body, env
191
191
 
192
192
  expect(last_response.status).to eq(200)
193
193
  expect(stub).to have_been_requested
@@ -207,7 +207,7 @@ RSpec.describe Flipper::Cloud::Middleware do
207
207
  'flipper' => flipper,
208
208
  'flipper_cloud' => env_flipper,
209
209
  }
210
- post '/webhooks', request_body, env
210
+ post '/', request_body, env
211
211
 
212
212
  expect(last_response.status).to eq(200)
213
213
  expect(stub).to have_been_requested
@@ -218,6 +218,27 @@ RSpec.describe Flipper::Cloud::Middleware do
218
218
  let(:app) { Flipper::Cloud.app(-> { flipper }) }
219
219
 
220
220
  it 'works' do
221
+ stub = stub_request_for_token('regular')
222
+ env = {
223
+ "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
224
+ }
225
+ post '/', request_body, env
226
+
227
+ expect(last_response.status).to eq(200)
228
+ expect(stub).to have_been_requested
229
+ end
230
+ end
231
+
232
+ context 'when using older /webhooks path' do
233
+ let(:app) { Flipper::Cloud.app(flipper) }
234
+
235
+ it 'uses instance to sync' do
236
+ Flipper.register(:admins) { |*args| false }
237
+ Flipper.register(:staff) { |*args| false }
238
+ Flipper.register(:basic) { |*args| false }
239
+ Flipper.register(:plus) { |*args| false }
240
+ Flipper.register(:premium) { |*args| false }
241
+
221
242
  stub = stub_request_for_token('regular')
222
243
  env = {
223
244
  "HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
@@ -225,13 +246,22 @@ RSpec.describe Flipper::Cloud::Middleware do
225
246
  post '/webhooks', request_body, env
226
247
 
227
248
  expect(last_response.status).to eq(200)
249
+ expect(JSON.parse(last_response.body)).to eq({
250
+ "groups" => [
251
+ {"name" => "admins"},
252
+ {"name" => "staff"},
253
+ {"name" => "basic"},
254
+ {"name" => "plus"},
255
+ {"name" => "premium"},
256
+ ],
257
+ })
228
258
  expect(stub).to have_been_requested
229
259
  end
230
260
  end
231
261
 
232
262
  describe 'Request method unsupported' do
233
263
  it 'skips middleware' do
234
- get '/webhooks'
264
+ get '/'
235
265
  expect(last_response.status).to eq(404)
236
266
  expect(last_response.content_type).to eq("application/json")
237
267
  expect(last_response.body).to eq("{}")
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.3
4
+ version: 0.20.4
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-01-10 00:00:00.000000000 Z
11
+ date: 2021-03-06 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.3
19
+ version: 0.20.4
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.3
26
+ version: 0.20.4
27
27
  description:
28
28
  email:
29
29
  - nunemaker@gmail.com
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - docs/images/flipper_cloud.png
34
35
  - examples/cloud/app.ru
35
36
  - examples/cloud/basic.rb
36
37
  - examples/cloud/cached_in_memory.rb