flipper-cloud 0.20.1 → 0.20.2

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: 35dc166068996854a78fc08810a942999539735d61f8f0215d6c10101a57d23d
4
- data.tar.gz: bdccf48ff9d058fc20ded13e1c64d7f64964c2daad12fe0ccc11b8aafcd2d0ab
3
+ metadata.gz: ad99886efa608844beb4f7efdd5603ff60280c2ac5ca871a8de2e5fcbb2459f5
4
+ data.tar.gz: f5f162782dd28d9d5e55616030202eb47899438f700d12ec7de218bc9bdba353
5
5
  SHA512:
6
- metadata.gz: a2f6190b1ff9a30ce518a0044323c55a9997db8cf3ec383c4d425ce5eb02121e99a355ca370928df1b9a23ea5add521133fb30a051b56a93b8ce088707d1f2a3
7
- data.tar.gz: 132a9a42b22803fa362b85acfd1c741519ce7eff91d5443bf47b8d0d869cd29d6a161ded0e15ef80fa7a642d46b948a454a0c633a72ff5cbbc22949dd2459622
6
+ metadata.gz: 44632f5b5c82b6c72c447716f8946768c03d2388c60fbfcdc07b43ee79389f094d49da3c1a1b5c4f34b4a1172e72b1dd2dbc67128838210f9cb3fb0dace41193
7
+ data.tar.gz: d6968fb80d7cdc47ebb5bb692780e6eee715faf845644302c28cc5f86217c19c939df18456382e5e614d9a72f39d3793298d054aa7d8d076d143ae3393eee8fc
@@ -1,5 +1,5 @@
1
1
  # Usage (from the repo root):
2
- # env TOKEN=<token> bundle exec ruby examples/cloud/basic.rb
2
+ # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/basic.rb
3
3
  require 'pathname'
4
4
  require 'logger'
5
5
  root_path = Pathname(__FILE__).dirname.join('..').expand_path
@@ -7,7 +7,7 @@ lib_path = root_path.join('lib')
7
7
  $:.unshift(lib_path)
8
8
 
9
9
  require 'flipper/cloud'
10
- flipper = Flipper::Cloud.new(ENV.fetch('TOKEN'))
10
+ flipper = Flipper::Cloud.new
11
11
 
12
12
  flipper[:stats].enable
13
13
 
@@ -1,3 +1,4 @@
1
+ # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/cached_in_memory.rb
1
2
  require File.expand_path('../../example_setup', __FILE__)
2
3
 
3
4
  require 'flipper/cloud'
@@ -5,12 +6,11 @@ require 'flipper/adapters/active_support_cache_store'
5
6
  require 'active_support/cache'
6
7
  require 'active_support/cache/memory_store'
7
8
 
8
- token = ENV.fetch("TOKEN") { abort "TOKEN environment variable not set." }
9
9
  feature_name = ENV.fetch("FEATURE") { "testing" }.to_sym
10
10
 
11
11
  Flipper.configure do |config|
12
12
  config.default do
13
- Flipper::Cloud.new(token) do |cloud|
13
+ Flipper::Cloud.new do |cloud|
14
14
  cloud.debug_output = STDOUT
15
15
  cloud.adapter do |adapter|
16
16
  Flipper::Adapters::ActiveSupportCacheStore.new(adapter,
@@ -1,5 +1,5 @@
1
1
  # Usage (from the repo root):
2
- # env TOKEN=<token> bundle exec ruby examples/cloud/basic.rb
2
+ # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/import.rb
3
3
  require 'pathname'
4
4
  require 'logger'
5
5
  root_path = Pathname(__FILE__).dirname.join('..').expand_path
@@ -10,14 +10,14 @@ require 'flipper'
10
10
  require 'flipper/cloud'
11
11
 
12
12
  memory_adapter = Flipper::Adapters::Memory.new
13
- memory_flipper = Flipper.new(memory_adapter)
13
+ flipper = Flipper.new(memory_adapter)
14
14
 
15
- memory_flipper.enable(:test)
16
- memory_flipper.enable(:search)
17
- memory_flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
18
- memory_flipper.enable_percentage_of_time(:logging, 5)
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)
19
19
 
20
- flipper = Flipper::Cloud.new(ENV.fetch('TOKEN'))
20
+ cloud = Flipper::Cloud.new
21
21
 
22
- # wipes cloud clean and makes it identical to memory flipper
23
- flipper.import(memory_flipper)
22
+ # makes cloud identical to memory flipper
23
+ cloud.import(flipper)
@@ -5,13 +5,13 @@
5
5
  # never raise. You could get a slow request every now and then if cloud is
6
6
  # unavailable, but we are hoping to fix that soon by doing the cloud update in a
7
7
  # background thread.
8
+ # env FLIPPER_CLOUD_TOKEN=<token> bundle exec ruby examples/cloud/local_adapter.rb
8
9
  require File.expand_path('../../example_setup', __FILE__)
9
10
 
10
11
  require 'logger'
11
12
  require 'flipper/cloud'
12
13
  require 'flipper/adapters/redis'
13
14
 
14
- token = ENV.fetch("TOKEN") { abort "TOKEN environment variable not set." }
15
15
  feature_name = ENV.fetch("FEATURE") { "testing" }.to_sym
16
16
 
17
17
  redis = Redis.new(logger: Logger.new(STDOUT))
@@ -19,7 +19,7 @@ redis.flushdb
19
19
 
20
20
  Flipper.configure do |config|
21
21
  config.default do
22
- Flipper::Cloud.new(token) do |cloud|
22
+ Flipper::Cloud.new do |cloud|
23
23
  cloud.debug_output = STDOUT
24
24
  cloud.local_adapter = Flipper::Adapters::Redis.new(redis)
25
25
  cloud.sync_interval = 10
@@ -1,3 +1,4 @@
1
+ require "socket"
1
2
  require "flipper/adapters/http"
2
3
  require "flipper/adapters/memory"
3
4
  require "flipper/adapters/dual_write"
@@ -153,6 +154,11 @@ module Flipper
153
154
  headers: {
154
155
  "Flipper-Cloud-Token" => @token,
155
156
  "Feature-Flipper-Token" => @token,
157
+ "Client-Lang" => "ruby",
158
+ "Client-Lang-Version" => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
159
+ "Client-Platform" => RUBY_PLATFORM,
160
+ "Client-Engine" => defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
161
+ "Client-Hostname" => Socket.gethostname,
156
162
  },
157
163
  })
158
164
  end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.1'.freeze
2
+ VERSION = '0.20.2'.freeze
3
3
  end
@@ -114,4 +114,89 @@ RSpec.describe Flipper::Cloud do
114
114
  described_class.new('asdf', open_timeout: 1)
115
115
  end
116
116
  end
117
+
118
+ it 'can import' do
119
+ stub_request(:post, /www\.flippercloud\.io\/adapter\/features.*/).
120
+ with(headers: {
121
+ 'Feature-Flipper-Token'=>'asdf',
122
+ 'Flipper-Cloud-Token'=>'asdf',
123
+ }).to_return(status: 200, body: "{}", headers: {})
124
+
125
+ flipper = Flipper.new(Flipper::Adapters::Memory.new)
126
+
127
+ flipper.enable(:test)
128
+ flipper.enable(:search)
129
+ flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
130
+ flipper.enable_percentage_of_time(:logging, 5)
131
+
132
+ cloud_flipper = Flipper::Cloud.new("asdf")
133
+
134
+ get_all = {
135
+ "logging" => {actors: Set.new, boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: "5"},
136
+ "search" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
137
+ "stats" => {actors: Set["jnunemaker"], boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
138
+ "test" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
139
+ }
140
+
141
+ expect(flipper.adapter.get_all).to eq(get_all)
142
+ cloud_flipper.import(flipper)
143
+ expect(flipper.adapter.get_all).to eq(get_all)
144
+ expect(cloud_flipper.adapter.get_all).to eq(get_all)
145
+ end
146
+
147
+ it 'raises error for failure while importing' do
148
+ stub_request(:post, /www\.flippercloud\.io\/adapter\/features.*/).
149
+ with(headers: {
150
+ 'Feature-Flipper-Token'=>'asdf',
151
+ 'Flipper-Cloud-Token'=>'asdf',
152
+ }).to_return(status: 500, body: "{}")
153
+
154
+ flipper = Flipper.new(Flipper::Adapters::Memory.new)
155
+
156
+ flipper.enable(:test)
157
+ flipper.enable(:search)
158
+ flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
159
+ flipper.enable_percentage_of_time(:logging, 5)
160
+
161
+ cloud_flipper = Flipper::Cloud.new("asdf")
162
+
163
+ get_all = {
164
+ "logging" => {actors: Set.new, boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: "5"},
165
+ "search" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
166
+ "stats" => {actors: Set["jnunemaker"], boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
167
+ "test" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
168
+ }
169
+
170
+ expect(flipper.adapter.get_all).to eq(get_all)
171
+ expect { cloud_flipper.import(flipper) }.to raise_error(Flipper::Adapters::Http::Error)
172
+ expect(flipper.adapter.get_all).to eq(get_all)
173
+ end
174
+
175
+ it 'raises error for timeout while importing' do
176
+ stub_request(:post, /www\.flippercloud\.io\/adapter\/features.*/).
177
+ with(headers: {
178
+ 'Feature-Flipper-Token'=>'asdf',
179
+ 'Flipper-Cloud-Token'=>'asdf',
180
+ }).to_timeout
181
+
182
+ flipper = Flipper.new(Flipper::Adapters::Memory.new)
183
+
184
+ flipper.enable(:test)
185
+ flipper.enable(:search)
186
+ flipper.enable_actor(:stats, Flipper::Actor.new("jnunemaker"))
187
+ flipper.enable_percentage_of_time(:logging, 5)
188
+
189
+ cloud_flipper = Flipper::Cloud.new("asdf")
190
+
191
+ get_all = {
192
+ "logging" => {actors: Set.new, boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: "5"},
193
+ "search" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
194
+ "stats" => {actors: Set["jnunemaker"], boolean: nil, groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
195
+ "test" => {actors: Set.new, boolean: "true", groups: Set.new, percentage_of_actors: nil, percentage_of_time: nil},
196
+ }
197
+
198
+ expect(flipper.adapter.get_all).to eq(get_all)
199
+ expect { cloud_flipper.import(flipper) }.to raise_error(Net::OpenTimeout)
200
+ expect(flipper.adapter.get_all).to eq(get_all)
201
+ end
117
202
  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.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2021-01-08 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.1
19
+ version: 0.20.2
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.1
26
+ version: 0.20.2
27
27
  description:
28
28
  email:
29
29
  - nunemaker@gmail.com