ft_gem 3.0.9 → 3.1.0

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: 58fbec10bcb730b69f3f8f4289ec9eb5f21437f47cc545bd2050616c19e66d19
4
- data.tar.gz: 27096da6d9084cdcfa3a6f86ef891d1d01684a37d513019a72f653ce526365ab
3
+ metadata.gz: 882b46bd6292e36ab8cd057adcd6982091a0bb50549c038955466bcd547ea134
4
+ data.tar.gz: 00516c790a74ec6d5b03036ac9784371f25da4e70bd532d6c8b522cf91199e31
5
5
  SHA512:
6
- metadata.gz: 968d5f9103a0ef28d7e2bc7adeca1a88735de32726802eb27fd00d8fa97b3d386424a599dc6e9b64d8f6c621654e701a371f0564d3157eb4102473ff4e293a0b
7
- data.tar.gz: 718da1efc3697fbc481792eb7bc2d5d3ca335db5bf2eab24a4f0ec9f27351cbc35df2b81ad1b8d5b6ae6d2aceb1c887b862cdba4d2b7e4b193e456037e188ff6
6
+ metadata.gz: b680e623e2eb1268c119bd0a059c2a0a5f25a7763ac58e7682fba4dbe8c3a7ec46d02b291dbf002145e140c2907b3ba326aac0c44dd253f72e9481a1523714b0
7
+ data.tar.gz: 5aadadf5af0047d30584a4a70e4e819539f934fb2d09fbad5b012c5181daa3e614944df5990d9de5438bfe7b31834e5b1c99a6bbef0062188948b91fb76fde48
@@ -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:, 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,8 @@ 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
- client_percentage.to_i <= toggle_percentage.to_i
16
+ whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggles[index.to_i]['attributes']['whitelist-urls'])
17
+ client_percentage.to_i <= toggle_percentage.to_i && whitelisted
17
18
  rescue StandardError => e
18
19
  Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
19
20
  false
@@ -27,7 +28,8 @@ module FtGem
27
28
  client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: toggle['attributes']['name'])
28
29
  new_cookie.push("#{toggle['attributes']['name']}:#{client_percentage}")
29
30
  end
30
- cookies[TOGGLE_COOKIE_NAME] = { value: Base64.encode64(new_cookie.join(',')).to_s, domain: ENV['COOKIE_DOMAIN'] }
31
+ cookies.delete TOGGLE_COOKIE_NAME, domain: ENV['COOKIE_DOMAIN']
32
+ cookies[TOGGLE_COOKIE_NAME] = { value: Base64.encode64(new_cookie.join(',')).to_s, secure: true }
31
33
  rescue StandardError => e
32
34
  Rails.logger.error "FTApiGem::update_feature_toggles error #{e.backtrace}"
33
35
  nil
@@ -1,7 +1,7 @@
1
1
  class FtShared
2
2
  def fetch(name:)
3
3
  Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
4
- JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", {query: { name: name },headers:authentication_header}).to_json)['data']
4
+ JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: authentication_header).to_json)['data']
5
5
  end
6
6
  rescue StandardError => e
7
7
  Rails.logger.error "FtHelper::fetch error #{e.backtrace}"
@@ -10,7 +10,7 @@ class FtShared
10
10
 
11
11
  def all_toggles
12
12
  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/",{headers:authentication_header}).to_json)['data']
13
+ JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/", headers: authentication_header).to_json)['data']
14
14
  end
15
15
  rescue StandardError => e
16
16
  Rails.logger.error "FtHelper::all_toggles error #{e.backtrace}"
@@ -20,4 +20,18 @@ class FtShared
20
20
  def authentication_header
21
21
  { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
22
22
  end
23
+
24
+ def whitelisted?(url:, whitelist_urls:)
25
+ return true if whitelist_urls.empty? || url.nil?
26
+ whitelisted = false
27
+ whitelist_urls.each do |whitelist_url|
28
+ if whitelist_url[whitelist_url.length - 1] == '*'
29
+ whitelist_url.chomp!('*')
30
+ whitelisted = true if url.starts_with?(whitelist_url)
31
+ elsif whitelist_url == url
32
+ whitelisted = true
33
+ end
34
+ end
35
+ whitelisted
36
+ end
23
37
  end
@@ -1,10 +1,11 @@
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']['percentage'].to_i == 100
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
10
  Rails.logger.error "FtHelper::status error #{e.backtrace}"
10
11
  false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
@@ -66,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.7.8
69
+ rubygems_version: 3.0.3
71
70
  signing_key:
72
71
  specification_version: 4
73
72
  summary: Client side feature toggle