wso2_toolbox 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: 7f8a8eff153546833fe2467480aad2bf4e3be98b
4
- data.tar.gz: f4850b59de521a4245bc11674a95967bda0d5a9f
3
+ metadata.gz: 0b4a79a88655140563f69967e68f44cc3ce12a69
4
+ data.tar.gz: fc3b960eee69401540260ebfb6294e85b558b14f
5
5
  SHA512:
6
- metadata.gz: ad943f3a94528589c06902bf4db315bfe17f69efff60e2a8c21ebe22b2531c9b954590b680c8021c9ca77bba4b2126130872694916eb3541c8f29f24fcaa5726
7
- data.tar.gz: 15ac3d2a80c82ba018d04bb9aaa586b47836d5b4774c8c3aae19d584bef07124206a42e61dd8a790c1ce658c2bd05775c5aa114b65e597d040b8f3c94bb8e5dc
6
+ metadata.gz: 94853c92496bf7e132e53d9c5bbb7d301d608b90bfea6f7287c70d69ef96e4a24ac47a23dec16e32ef9157322227239754024afc78fb67428159b44a758cdcad
7
+ data.tar.gz: c51dd568b9488d0b3f2a0d19e7223ec02b1b9f8f3885b2d5c866d5535cc2c3ea611f20b71fef50f8529240cdc9783d1ab99ad9f08881cf774eb178d34b0011ef
@@ -1,6 +1,6 @@
1
1
  # Generate token credentials
2
- TOKEN_USERNAME='svc-cedrobco_h'
2
+ TOKEN_USERNAME='admin_guide'
3
3
  TOKEN_PASSWORD='Toor@2017'
4
- TOKEN_URL='http://172.16.13.67:8010/auth/users/login'
5
- TOKEN_REFRESH_URL='http://172.16.13.67:8010/auth/refresh_token'
6
- TOKEN_REVOKE_URL='http://172.16.13.67:8010/auth/revoke_token'
4
+ TOKEN_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/users/login'
5
+ TOKEN_REFRESH_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/refresh_token'
6
+ TOKEN_REVOKE_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/revoke_token'
@@ -1,6 +1,6 @@
1
- # generate token URL
2
- TOKEN_USERNAME='svc-cedrobco_h'
1
+ # Generate token credentials
2
+ TOKEN_USERNAME='admin_guide'
3
3
  TOKEN_PASSWORD='Toor@2017'
4
- TOKEN_URL='http://172.16.13.67:8010/auth/users/login'
5
- TOKEN_REFRESH_URL='http://172.16.13.67:8010/auth/refresh_token'
6
- TOKEN_REVOKE_URL='http://172.16.13.67:8010/auth/revoke_token'
4
+ TOKEN_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/users/login'
5
+ TOKEN_REFRESH_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/refresh_token'
6
+ TOKEN_REVOKE_URL='http://pt-api-qa.guideinvestimentos.com.br:8010/auth/revoke_token'
@@ -6,14 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [0.2.1] - 2018-01-15
9
+ ## [0.3.1] - 2018-11-07
10
10
  ### Changed
11
- - Fix time parser
11
+ - Fix bug in local file adpter, when 2 or more process try to update same file
12
+
13
+ ## [0.3.0] - 2018-05-11
14
+ ### Changed
15
+ - Refresh auth token when invalid
12
16
 
13
17
  ## [0.2.2] - 2018-01-15
14
18
  ### Changed
15
19
  - Fix time parser
16
20
 
17
- ## [0.3.0] - 2018-05-11
21
+ ## [0.2.1] - 2018-01-15
18
22
  ### Changed
19
- - Refresh auth token when invalid
23
+ - Fix time parser
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wso2_toolbox (0.2.3)
4
+ wso2_toolbox (0.3.1)
5
5
  actionpack (>= 5.0)
6
6
  activesupport (>= 5.0)
7
7
  request_store (~> 1.3.2)
@@ -38,7 +38,7 @@ GEM
38
38
  safe_yaml (~> 1.0.0)
39
39
  crass (1.0.3)
40
40
  diff-lcs (1.3)
41
- domain_name (0.5.20170404)
41
+ domain_name (0.5.20180417)
42
42
  unf (>= 0.0.5, < 1.0.0)
43
43
  dotenv (2.2.1)
44
44
  erubi (1.7.0)
@@ -51,9 +51,9 @@ GEM
51
51
  crass (~> 1.0.2)
52
52
  nokogiri (>= 1.5.9)
53
53
  method_source (0.9.0)
54
- mime-types (3.1)
54
+ mime-types (3.2.2)
55
55
  mime-types-data (~> 3.2015)
56
- mime-types-data (3.2016.0521)
56
+ mime-types-data (3.2018.0812)
57
57
  mini_portile2 (2.3.0)
58
58
  minitest (5.10.3)
59
59
  netrc (0.11.0)
@@ -128,4 +128,4 @@ DEPENDENCIES
128
128
  wso2_toolbox!
129
129
 
130
130
  BUNDLED WITH
131
- 1.16.1
131
+ 1.16.2
@@ -3,12 +3,16 @@
3
3
  require 'json'
4
4
  require 'request_store'
5
5
  require 'active_support/core_ext/numeric/time'
6
+ require 'wso2_toolbox/token_manager/adapters/lock_file'
6
7
 
7
8
  module Wso2Toolbox
8
9
  module TokenManager
9
10
  module Adapters
10
11
  module LocalFileAdapter
11
12
  class << self
13
+ include LockFile
14
+
15
+ FILE_PATH = 'tmp/localstorage.json'
12
16
  TOKEN_DELAY = 5.minutes
13
17
 
14
18
  def generate_token
@@ -16,7 +20,19 @@ module Wso2Toolbox
16
20
  store_token(read(:token_for_job))
17
21
  end
18
22
 
19
- private_class_method
23
+ def read(key)
24
+ local_storage { |store| return store.try(:[], key.to_s) }
25
+ end
26
+
27
+ def write(key, value)
28
+ try_unlock
29
+
30
+ lock_file do
31
+ local_storage { |store| store.merge!(key => value) }
32
+ end
33
+ end
34
+
35
+ private
20
36
 
21
37
  def new_token
22
38
  token_params =
@@ -34,33 +50,21 @@ module Wso2Toolbox
34
50
 
35
51
  def active_token?
36
52
  return false unless read(:token_time_for_job)
37
- Time.parse(read(:token_time_for_job)) - TOKEN_DELAY > Time.now
38
- end
39
-
40
- def read(key)
41
- local_storage { |store| return store.try(:[], key.to_s) }
42
- end
43
53
 
44
- def write(key, value)
45
- local_storage { |store| store[key] = value }
54
+ Time.parse(read(:token_time_for_job)) - TOKEN_DELAY > Time.now
46
55
  end
47
56
 
48
57
  def local_storage
49
- file = File.open(file_path, 'a+').read
50
- file_read = file == '' ? '{}' : file
58
+ file = File.open(FILE_PATH, 'a+').read
59
+ parsed_stored = file == '' ? {} : JSON.parse(file)
51
60
 
52
- local_store = JSON.parse(file_read)
53
- yield(local_store)
61
+ yield(parsed_stored)
54
62
 
55
- File.open(file_path, 'w+') do |f|
56
- f.write(local_store.to_json)
63
+ File.open(FILE_PATH, 'w+') do |f|
64
+ f.write(parsed_stored.to_json)
57
65
  f.rewind
58
66
  end
59
67
  end
60
-
61
- def file_path
62
- @file_path ||= 'tmp/localstorage.json'
63
- end
64
68
  end
65
69
  end
66
70
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Wso2Toolbox
6
+ module TokenManager
7
+ module Adapters
8
+ module LockFile
9
+ LockFileExistError = Class.new(StandardError)
10
+ ATTEMPTS = 30
11
+ TIME_INTERVAL = 1
12
+ LOCK_PATH = 'tmp/localstorage.lock'
13
+
14
+ def try_unlock
15
+ ATTEMPTS.times do |i|
16
+ raise LockFileExistError if lock_valid? && i == (ATTEMPTS - 1)
17
+
18
+ if lock_valid?
19
+ sleep(TIME_INTERVAL)
20
+ else
21
+ FileUtils.rm_r(LOCK_PATH, force: true)
22
+ break
23
+ end
24
+ end
25
+ end
26
+
27
+ def lock_file
28
+ File.open(LOCK_PATH, 'a+') do |f|
29
+ f.write File.basename(LOCK_PATH, '.*')
30
+ end
31
+
32
+ yield
33
+
34
+ FileUtils.rm_r(LOCK_PATH, force: true)
35
+ end
36
+
37
+ def lock_valid?
38
+ return false unless File.exist?(LOCK_PATH)
39
+
40
+ file_modified = File.ctime(LOCK_PATH)
41
+ file_modified + 1.minutes < Time.current
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -15,7 +15,7 @@ module Wso2Toolbox
15
15
  store_token(Setting.token_for_job)
16
16
  end
17
17
 
18
- private_class_method
18
+ private
19
19
 
20
20
  def new_token
21
21
  token_params =
@@ -56,6 +56,7 @@ module Wso2Toolbox
56
56
 
57
57
  def expired_token?
58
58
  return true unless Setting.token_time_for_job
59
+
59
60
  Time.now > Time.parse(Setting.token_time_for_job)
60
61
  end
61
62
 
@@ -19,7 +19,7 @@ module Wso2Toolbox
19
19
  post(config.revoke_token_url, token: token)
20
20
  end
21
21
 
22
- private_class_method
22
+ private
23
23
 
24
24
  def config
25
25
  @config ||= Wso2Toolbox.configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wso2Toolbox
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wso2_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abner Carleto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -221,6 +221,7 @@ files:
221
221
  - lib/wso2_toolbox/rspec_utils/shared_examples/identity_headers.rb
222
222
  - lib/wso2_toolbox/token_manager.rb
223
223
  - lib/wso2_toolbox/token_manager/adapters/local_file_adapter.rb
224
+ - lib/wso2_toolbox/token_manager/adapters/lock_file.rb
224
225
  - lib/wso2_toolbox/token_manager/adapters/rails_cached_adapter.rb
225
226
  - lib/wso2_toolbox/token_manager/api_manager_service.rb
226
227
  - lib/wso2_toolbox/version.rb