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 +4 -4
- data/.env.development +4 -4
- data/.env.pipelines +5 -5
- data/CHANGELOG.md +8 -4
- data/Gemfile.lock +5 -5
- data/lib/wso2_toolbox/token_manager/adapters/local_file_adapter.rb +23 -19
- data/lib/wso2_toolbox/token_manager/adapters/lock_file.rb +46 -0
- data/lib/wso2_toolbox/token_manager/adapters/rails_cached_adapter.rb +2 -1
- data/lib/wso2_toolbox/token_manager/api_manager_service.rb +1 -1
- data/lib/wso2_toolbox/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b4a79a88655140563f69967e68f44cc3ce12a69
|
4
|
+
data.tar.gz: fc3b960eee69401540260ebfb6294e85b558b14f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94853c92496bf7e132e53d9c5bbb7d301d608b90bfea6f7287c70d69ef96e4a24ac47a23dec16e32ef9157322227239754024afc78fb67428159b44a758cdcad
|
7
|
+
data.tar.gz: c51dd568b9488d0b3f2a0d19e7223ec02b1b9f8f3885b2d5c866d5535cc2c3ea611f20b71fef50f8529240cdc9783d1ab99ad9f08881cf774eb178d34b0011ef
|
data/.env.development
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generate token credentials
|
2
|
-
TOKEN_USERNAME='
|
2
|
+
TOKEN_USERNAME='admin_guide'
|
3
3
|
TOKEN_PASSWORD='Toor@2017'
|
4
|
-
TOKEN_URL='http://
|
5
|
-
TOKEN_REFRESH_URL='http://
|
6
|
-
TOKEN_REVOKE_URL='http://
|
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'
|
data/.env.pipelines
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
2
|
-
TOKEN_USERNAME='
|
1
|
+
# Generate token credentials
|
2
|
+
TOKEN_USERNAME='admin_guide'
|
3
3
|
TOKEN_PASSWORD='Toor@2017'
|
4
|
-
TOKEN_URL='http://
|
5
|
-
TOKEN_REFRESH_URL='http://
|
6
|
-
TOKEN_REVOKE_URL='http://
|
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'
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
9
|
+
## [0.3.1] - 2018-11-07
|
10
10
|
### Changed
|
11
|
-
- Fix
|
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.
|
21
|
+
## [0.2.1] - 2018-01-15
|
18
22
|
### Changed
|
19
|
-
-
|
23
|
+
- Fix time parser
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wso2_toolbox (0.
|
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.
|
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.
|
54
|
+
mime-types (3.2.2)
|
55
55
|
mime-types-data (~> 3.2015)
|
56
|
-
mime-types-data (3.
|
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.
|
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
|
-
|
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
|
-
|
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(
|
50
|
-
|
58
|
+
file = File.open(FILE_PATH, 'a+').read
|
59
|
+
parsed_stored = file == '' ? {} : JSON.parse(file)
|
51
60
|
|
52
|
-
|
53
|
-
yield(local_store)
|
61
|
+
yield(parsed_stored)
|
54
62
|
|
55
|
-
File.open(
|
56
|
-
f.write(
|
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
|
-
|
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
|
|
data/lib/wso2_toolbox/version.rb
CHANGED
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.
|
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-
|
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
|