ft_gem 3.1.14 → 3.2.7

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
- SHA256:
3
- metadata.gz: db43b97ec5443d62e7c13333b733500fed1cbd9c2f13462955ef242dd810a0c2
4
- data.tar.gz: 1941b502277a462f749f29199c068007c614e0ad175a1e65ccf8139f35dcd86b
2
+ SHA1:
3
+ metadata.gz: 212273bf41a194c45f3c3c8021ebe712be110027
4
+ data.tar.gz: cfab39aeccf578f1df5beec51255a03a2c448fdd
5
5
  SHA512:
6
- metadata.gz: 78dd064fd71a7862fa0a8ab4c61a5c30b0faf4bb3e4a0394429e1669fd9c57e6795dbb2d68ce85af9393b306e03f536db2dcde0704b8b77ba03dc8048b36189d
7
- data.tar.gz: 36cc45d908f1ce9e74963b65169d2c546962c49d9b9c415a30f341e391b7b64558f61c20a96e8e397b5b5034bb79acb2d4c19b3027261b98d9f12643e37ce09c
6
+ metadata.gz: 42faaf44b67c17c0d1d354231a42daaa52495d9e77bd996917ea44b80b5fedaee4d448a10cfb2a0503449044f4dcbe369213a337fd1b3ce3de64676a9c42e925
7
+ data.tar.gz: 9031f6721ff0d0070ef50bd6edb9985a2ac2dbaec654802e35cb46d403bd698661a4be9715cb4ec0e0a9ce77560deef5fc54e28ae4d6162f232aed4cfb92aa1e
@@ -8,16 +8,20 @@ module FtGem
8
8
 
9
9
  def feature_toggle_status(name:, user_id: nil, url: nil)
10
10
  toggles = FtShared.new.all_toggles
11
- update_feature_toggles(toggles: toggles)
12
- decoded_cookie = Base64.decode64(cookies[TOGGLE_COOKIE_NAME])
13
11
  index = toggles.index { |toggle| toggle['attributes']['name'] == name }
14
12
  return false if index.nil?
15
- client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: name)
16
- toggle_percentage = toggles[index.to_i]['attributes']['percentage']
13
+
17
14
  whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggles[index.to_i]['attributes']['whitelist-urls'])
15
+ return false unless whitelisted
16
+
17
+ return true if FtGem::Services::BetaService.public_beta?(cookie: cookies[PUBLICBETA_COOKIE_NAME], toggles: toggles, index: index)
18
+ return true if FtGem::Services::BetaService.private_beta?(user_id: user_id, toggles: toggles, index: index)
18
19
 
19
- return true && whitelisted if FtGem::Services::BetaService.public_beta?(cookie: Base64.decode64(cookies[PUBLICBETA_COOKIE_NAME]),toggles: toggles, index: index)
20
- return true && whitelisted if FtGem::Services::BetaService.private_beta?(user_id: user_id, toggles: toggles, index: index)
20
+ update_feature_toggles(toggles: toggles)
21
+ decoded_cookie = Base64.decode64(cookies[TOGGLE_COOKIE_NAME])
22
+
23
+ client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: name)
24
+ toggle_percentage = toggles[index.to_i]['attributes']['percentage']
21
25
 
22
26
  return client_percentage.to_i <= toggle_percentage.to_i && whitelisted
23
27
  rescue StandardError => e
@@ -7,14 +7,17 @@ module FtGem
7
7
 
8
8
  attributes = toggles[index.to_i].dig('attributes')
9
9
 
10
+ Rails.logger.info("########### PRIVATE BETA status: #{attributes['status']}, include users: #{attributes['beta-users'].split(",").include?(user_id.to_s)} ################")
10
11
  attributes['status'] == "privatebeta" && attributes['beta-users'].split(",").include?(user_id.to_s)
11
12
  end
12
13
 
13
- def self.public_beta?(cookie: "", toggles: nil, index: "")
14
+ def self.public_beta?(cookie: nil, toggles: nil, index: "")
14
15
  return false unless toggles.present?
15
16
 
16
17
  attributes = toggles.dig(index.to_i, 'attributes')
17
- cookie == "true" && attributes['status'] == "publicbeta"
18
+
19
+ Rails.logger.info("########### PUBLIC BETA cookie: #{cookie}, status: #{attributes['status']} ################")
20
+ attributes['status'] == "publicbeta" && cookie.present?
18
21
  end
19
22
  end
20
23
  end
@@ -1,8 +1,15 @@
1
1
  class FtShared
2
+
3
+ def svc_url
4
+ url = ENV['MICROSVC_URL']
5
+ url = ENV['SITE_URL'] unless url
6
+ url
7
+ end
8
+
2
9
  def fetch(name:)
3
10
  http_response = ''
4
11
  Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
5
- http_response = HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: authentication_header)
12
+ http_response = HTTParty.get("#{svc_url}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: header_hash)
6
13
  JSON.parse(http_response.to_json)['data']
7
14
  end
8
15
  rescue StandardError => e
@@ -12,15 +19,15 @@ class FtShared
12
19
 
13
20
  def all_toggles
14
21
  Rails.cache.fetch('all-feature-toggles', expires_in: 1.minute) do
15
- JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles", headers: authentication_header).to_json)['data']
22
+ JSON.parse(HTTParty.get("#{svc_url}/service/ft/api/v1/feature-toggles", headers: header_hash).to_json)['data']
16
23
  end
17
24
  rescue StandardError => e
18
25
  Rails.logger.error "FtHelper::all_toggles error #{e.message}"
19
26
  {}
20
27
  end
21
28
 
22
- def authentication_header
23
- { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
29
+ def header_hash
30
+ { Authorization: "Bearer #{MumsnetJWT.tokenify}", Host: "#{ENV['SITE_HOSTNAME']}" }
24
31
  end
25
32
 
26
33
  def whitelisted?(url:, whitelist_urls:)
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.1.14
4
+ version: 3.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumsnet_jwt
@@ -67,7 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.0.3
70
+ rubyforge_project:
71
+ rubygems_version: 2.5.2.3
71
72
  signing_key:
72
73
  specification_version: 4
73
74
  summary: Client side feature toggle