ft_gem 3.0.9 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ft_gem/controllers/helpers.rb +9 -3
- data/lib/ft_gem/shared/ft_shared.rb +20 -4
- data/lib/ft_gem/view/helpers.rb +4 -3
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd51c11b15d1f46fd98c4476c8a0d0eadbead26785f022dbae2ec1b0a661b033
|
4
|
+
data.tar.gz: 0351fb12d09f8d4ead1746247f1d1d67a41f668afc58124f4bfc22853db24ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 329fd3295dd560e017f8cb60d8ee92c46137e89a9941d76f3359dc7b376630cd431adbba2487c1b52155719de079e7b0e97b7547c9da5caa18da4e3b19f7bedb
|
7
|
+
data.tar.gz: 240149ba279adfdeb18d357642f306d88b1ad6ba3e6e7eb90dfcf50235d3e9edb9e94cd7a1541e3044e18d7fc2c3fc3c811589dcfe8ce04664c24490af367734
|
@@ -5,7 +5,7 @@ module FtGem
|
|
5
5
|
TOGGLE_COOKIE_NAME = 'mnft'.freeze
|
6
6
|
require 'base64'
|
7
7
|
|
8
|
-
def feature_toggle_status(name:)
|
8
|
+
def feature_toggle_status(name:, user_id: nil, url: nil)
|
9
9
|
toggles = FtShared.new.all_toggles
|
10
10
|
update_feature_toggles(toggles: toggles)
|
11
11
|
decoded_cookie = Base64.decode64(cookies[TOGGLE_COOKIE_NAME])
|
@@ -13,7 +13,12 @@ module FtGem
|
|
13
13
|
return false if index.nil?
|
14
14
|
client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: name)
|
15
15
|
toggle_percentage = toggles[index.to_i]['attributes']['percentage']
|
16
|
-
|
16
|
+
whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggles[index.to_i]['attributes']['whitelist-urls'])
|
17
|
+
if (user_id.present? && toggles[index.to_i]['attributes']['status'] == "amber" && toggles[index.to_i]['attributes']['beta-users'].split(",").include?(user_id.to_s))
|
18
|
+
return true
|
19
|
+
else
|
20
|
+
return client_percentage.to_i <= toggle_percentage.to_i && whitelisted
|
21
|
+
end
|
17
22
|
rescue StandardError => e
|
18
23
|
Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
|
19
24
|
false
|
@@ -27,7 +32,8 @@ module FtGem
|
|
27
32
|
client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: toggle['attributes']['name'])
|
28
33
|
new_cookie.push("#{toggle['attributes']['name']}:#{client_percentage}")
|
29
34
|
end
|
30
|
-
cookies
|
35
|
+
cookies.delete TOGGLE_COOKIE_NAME, domain: ENV['COOKIE_DOMAIN']
|
36
|
+
cookies[TOGGLE_COOKIE_NAME] = { value: Base64.strict_encode64(new_cookie.join(',')).to_s, secure: true }
|
31
37
|
rescue StandardError => e
|
32
38
|
Rails.logger.error "FTApiGem::update_feature_toggles error #{e.backtrace}"
|
33
39
|
nil
|
@@ -1,23 +1,39 @@
|
|
1
1
|
class FtShared
|
2
2
|
def fetch(name:)
|
3
|
+
http_response = ''
|
3
4
|
Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
|
4
|
-
|
5
|
+
http_response = HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: authentication_header)
|
6
|
+
JSON.parse(http_response.to_json)['data']
|
5
7
|
end
|
6
8
|
rescue StandardError => e
|
7
|
-
Rails.logger.error "FtHelper::fetch error #{e.
|
9
|
+
Rails.logger.error "FtHelper::fetch error for #{name}\nerror: #{e.message}\nhttp_response: #{http_response}"
|
8
10
|
nil
|
9
11
|
end
|
10
12
|
|
11
13
|
def all_toggles
|
12
14
|
Rails.cache.fetch('all-feature-toggles', expires_in: 1.minute) do
|
13
|
-
JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles
|
15
|
+
JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles", headers: authentication_header).to_json)['data']
|
14
16
|
end
|
15
17
|
rescue StandardError => e
|
16
|
-
Rails.logger.error "FtHelper::all_toggles error #{e.
|
18
|
+
Rails.logger.error "FtHelper::all_toggles error #{e.message}"
|
17
19
|
{}
|
18
20
|
end
|
19
21
|
|
20
22
|
def authentication_header
|
21
23
|
{ Authorization: "Bearer #{MumsnetJWT.tokenify}" }
|
22
24
|
end
|
25
|
+
|
26
|
+
def whitelisted?(url:, whitelist_urls:)
|
27
|
+
return true if whitelist_urls.empty? || url.nil?
|
28
|
+
whitelisted = false
|
29
|
+
whitelist_urls.each do |whitelist_url|
|
30
|
+
if whitelist_url[whitelist_url.length - 1] == '*'
|
31
|
+
whitelist_url.chomp!('*')
|
32
|
+
whitelisted = true if url.starts_with?(whitelist_url)
|
33
|
+
elsif whitelist_url == url
|
34
|
+
whitelisted = true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
whitelisted
|
38
|
+
end
|
23
39
|
end
|
data/lib/ft_gem/view/helpers.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module FtGem
|
2
2
|
module View
|
3
3
|
module Helpers
|
4
|
-
def self.status(name:)
|
4
|
+
def self.status(name:, url: nil)
|
5
5
|
toggle = FtShared.new.fetch(name: name)
|
6
6
|
return false if toggle.nil?
|
7
|
-
toggle['attributes']['
|
7
|
+
whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggle['attributes']['whitelist-urls'])
|
8
|
+
toggle['attributes']['percentage'].to_i == 100 && whitelisted
|
8
9
|
rescue StandardError => e
|
9
|
-
Rails.logger.error "FtHelper::status error #{e.
|
10
|
+
Rails.logger.error "FtHelper::status error #{e.message}"
|
10
11
|
false
|
11
12
|
end
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ft_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Murray Catto
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumsnet_jwt
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
42
|
-
email:
|
41
|
+
description:
|
42
|
+
email:
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
@@ -48,10 +48,10 @@ files:
|
|
48
48
|
- lib/ft_gem/controllers/helpers.rb
|
49
49
|
- lib/ft_gem/shared/ft_shared.rb
|
50
50
|
- lib/ft_gem/view/helpers.rb
|
51
|
-
homepage:
|
51
|
+
homepage:
|
52
52
|
licenses: []
|
53
53
|
metadata: {}
|
54
|
-
post_install_message:
|
54
|
+
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
@@ -66,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
|
70
|
-
|
71
|
-
signing_key:
|
69
|
+
rubygems_version: 3.0.8
|
70
|
+
signing_key:
|
72
71
|
specification_version: 4
|
73
72
|
summary: Client side feature toggle
|
74
73
|
test_files: []
|