wso2_toolbox 0.1.0 → 0.2.0
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 -0
- data/.env.pipelines +2 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +46 -2
- data/README.md +13 -0
- data/bitbucket-pipelines.yml +1 -0
- data/lib/wso2_toolbox.rb +17 -0
- data/lib/wso2_toolbox/configuration.rb +7 -0
- data/lib/wso2_toolbox/token_manager.rb +15 -0
- data/lib/wso2_toolbox/token_manager/adapters/local_file_adapter.rb +68 -0
- data/lib/wso2_toolbox/token_manager/adapters/rails_cached_adapter.rb +40 -0
- data/lib/wso2_toolbox/token_manager/api_manager_service.rb +34 -0
- data/lib/wso2_toolbox/version.rb +1 -1
- data/wso2_toolbox.gemspec +7 -1
- metadata +96 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ebff4181acd11b571bc23e57ace37558244704
|
4
|
+
data.tar.gz: 16ac1b56304a0d245801dfd696185b44eb1c37f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65caa9a9cdcf53408258bf877a2a08d111fdb100ebc5df9151b62aead005b2cbeccd771543b4e3c148bbd6f2c8f79a268cd06ce0be0fbfc86d0e058dd99155d8
|
7
|
+
data.tar.gz: abefaf7531afce6b1a976852527ea8623b9fd8cae13f059c33af501a28ba6c51547b416c7ac1809f5906c606dd1136d5ac5257bc7fab9c4a0c0c5c22aea73f8d
|
data/.env.development
ADDED
data/.env.pipelines
ADDED
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wso2_toolbox (0.
|
4
|
+
wso2_toolbox (0.2.0)
|
5
5
|
actionpack (>= 5.0)
|
6
6
|
activesupport (>= 5.0)
|
7
|
+
request_store (~> 1.3.2)
|
8
|
+
rest-client (>= 2.0.2)
|
7
9
|
|
8
10
|
GEM
|
9
11
|
remote: https://rubygems.org/
|
@@ -26,20 +28,44 @@ GEM
|
|
26
28
|
i18n (~> 0.7)
|
27
29
|
minitest (~> 5.1)
|
28
30
|
tzinfo (~> 1.1)
|
31
|
+
addressable (2.5.2)
|
32
|
+
public_suffix (>= 2.0.2, < 4.0)
|
29
33
|
builder (3.2.3)
|
34
|
+
byebug (9.1.0)
|
35
|
+
coderay (1.1.2)
|
30
36
|
concurrent-ruby (1.0.5)
|
37
|
+
crack (0.4.3)
|
38
|
+
safe_yaml (~> 1.0.0)
|
31
39
|
crass (1.0.3)
|
32
40
|
diff-lcs (1.3)
|
41
|
+
domain_name (0.5.20170404)
|
42
|
+
unf (>= 0.0.5, < 1.0.0)
|
43
|
+
dotenv (2.2.1)
|
33
44
|
erubi (1.7.0)
|
45
|
+
hashdiff (0.3.7)
|
46
|
+
http-cookie (1.0.3)
|
47
|
+
domain_name (~> 0.5)
|
34
48
|
i18n (0.9.1)
|
35
49
|
concurrent-ruby (~> 1.0)
|
36
50
|
loofah (2.1.1)
|
37
51
|
crass (~> 1.0.2)
|
38
52
|
nokogiri (>= 1.5.9)
|
53
|
+
method_source (0.9.0)
|
54
|
+
mime-types (3.1)
|
55
|
+
mime-types-data (~> 3.2015)
|
56
|
+
mime-types-data (3.2016.0521)
|
39
57
|
mini_portile2 (2.3.0)
|
40
58
|
minitest (5.10.3)
|
59
|
+
netrc (0.11.0)
|
41
60
|
nokogiri (1.8.1)
|
42
61
|
mini_portile2 (~> 2.3.0)
|
62
|
+
pry (0.11.3)
|
63
|
+
coderay (~> 1.1.0)
|
64
|
+
method_source (~> 0.9.0)
|
65
|
+
pry-byebug (3.5.1)
|
66
|
+
byebug (~> 9.1)
|
67
|
+
pry (~> 0.10)
|
68
|
+
public_suffix (3.0.1)
|
43
69
|
rack (2.0.3)
|
44
70
|
rack-test (0.8.2)
|
45
71
|
rack (>= 1.0, < 3)
|
@@ -53,6 +79,11 @@ GEM
|
|
53
79
|
rails-html-sanitizer (1.0.3)
|
54
80
|
loofah (~> 2.0)
|
55
81
|
rake (10.5.0)
|
82
|
+
request_store (1.3.2)
|
83
|
+
rest-client (2.0.2)
|
84
|
+
http-cookie (>= 1.0.2, < 2.0)
|
85
|
+
mime-types (>= 1.16, < 4.0)
|
86
|
+
netrc (~> 0.8)
|
56
87
|
rspec (3.7.0)
|
57
88
|
rspec-core (~> 3.7.0)
|
58
89
|
rspec-expectations (~> 3.7.0)
|
@@ -66,22 +97,35 @@ GEM
|
|
66
97
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
98
|
rspec-support (~> 3.7.0)
|
68
99
|
rspec-support (3.7.0)
|
100
|
+
safe_yaml (1.0.4)
|
69
101
|
shoulda-matchers (3.1.2)
|
70
102
|
activesupport (>= 4.0.0)
|
71
103
|
thread_safe (0.3.6)
|
72
104
|
tzinfo (1.2.4)
|
73
105
|
thread_safe (~> 0.1)
|
106
|
+
unf (0.1.4)
|
107
|
+
unf_ext
|
108
|
+
unf_ext (0.0.7.4)
|
109
|
+
vcr (4.0.0)
|
110
|
+
webmock (3.2.1)
|
111
|
+
addressable (>= 2.3.6)
|
112
|
+
crack (>= 0.3.2)
|
113
|
+
hashdiff
|
74
114
|
|
75
115
|
PLATFORMS
|
76
116
|
ruby
|
77
117
|
|
78
118
|
DEPENDENCIES
|
79
119
|
bundler (~> 1.16)
|
120
|
+
dotenv
|
121
|
+
pry-byebug
|
80
122
|
rails-controller-testing (~> 1.0)
|
81
123
|
rake (~> 10.0)
|
82
124
|
rspec (~> 3.0)
|
83
125
|
shoulda-matchers (~> 3.1)
|
126
|
+
vcr
|
127
|
+
webmock
|
84
128
|
wso2_toolbox!
|
85
129
|
|
86
130
|
BUNDLED WITH
|
87
|
-
1.16.
|
131
|
+
1.16.1
|
data/README.md
CHANGED
@@ -22,6 +22,19 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
Firstly, need set credentials to generate token. Create `config/initializers/wso2_toolbox.rb` file and
|
26
|
+
fill in the attributes:
|
27
|
+
```
|
28
|
+
Wso2Toolbox.configure do |config|
|
29
|
+
config.token_url = ENV['GENERATE_TOKEN_DEV_URL']
|
30
|
+
config.token_username = ENV['GENERATE_TOKEN_DEV_USERNAME']
|
31
|
+
config.token_password = ENV['GENERATE_TOKEN_DEV_PASSWORD']
|
32
|
+
end
|
33
|
+
|
34
|
+
Then, you can generate a token calling `Wso2Toolbox::TokenManager.generate_token`,
|
35
|
+
that it will set the new token in your request.
|
36
|
+
|
37
|
+
```
|
25
38
|
### Example controller
|
26
39
|
|
27
40
|
```
|
data/bitbucket-pipelines.yml
CHANGED
data/lib/wso2_toolbox.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
require 'wso2_toolbox/version'
|
2
2
|
require 'wso2_toolbox/identity_headers'
|
3
|
+
require 'wso2_toolbox/configuration'
|
4
|
+
require 'wso2_toolbox/token_manager'
|
5
|
+
require 'wso2_toolbox/token_manager/api_manager_service'
|
6
|
+
require 'wso2_toolbox/token_manager/adapters/local_file_adapter'
|
3
7
|
|
4
8
|
module Wso2Toolbox
|
9
|
+
class << self
|
10
|
+
def reset
|
11
|
+
@configuration = Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
5
22
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/numeric/time'
|
4
|
+
|
5
|
+
module Wso2Toolbox
|
6
|
+
module TokenManager
|
7
|
+
def self.generate_token
|
8
|
+
if defined?(RailsSettings)
|
9
|
+
TokenManager::Adapters::RailsCachedAdapter.generate_token
|
10
|
+
else
|
11
|
+
TokenManager::Adapters::LocalFileAdapter.generate_token
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# forzen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'request_store'
|
5
|
+
require 'active_support/core_ext/numeric/time'
|
6
|
+
|
7
|
+
module Wso2Toolbox
|
8
|
+
module TokenManager
|
9
|
+
module Adapters
|
10
|
+
module LocalFileAdapter
|
11
|
+
class << self
|
12
|
+
TOKEN_DELAY = 5.minutes
|
13
|
+
|
14
|
+
def generate_token
|
15
|
+
new_token unless active_token?
|
16
|
+
store_token(read(:token_for_job))
|
17
|
+
end
|
18
|
+
|
19
|
+
private_class_method
|
20
|
+
|
21
|
+
def new_token
|
22
|
+
token_params =
|
23
|
+
Wso2Toolbox::TokenManager::ApiManagerService.create_token
|
24
|
+
|
25
|
+
write(:token_time_for_job,
|
26
|
+
Time.now + token_params[:expires_in].seconds)
|
27
|
+
write(:token_for_job,
|
28
|
+
"#{token_params[:token_type]} #{token_params[:access_token]}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def store_token(token)
|
32
|
+
RequestStore.store[:token] = token
|
33
|
+
end
|
34
|
+
|
35
|
+
def active_token?
|
36
|
+
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
|
+
|
44
|
+
def write(key, value)
|
45
|
+
local_storage { |store| store[key] = value }
|
46
|
+
end
|
47
|
+
|
48
|
+
def local_storage
|
49
|
+
file = File.open(file_path, 'a+').read
|
50
|
+
file_read = file == '' ? '{}' : file
|
51
|
+
|
52
|
+
local_store = JSON.parse(file_read)
|
53
|
+
yield(local_store)
|
54
|
+
|
55
|
+
File.open(file_path, 'w+') do |f|
|
56
|
+
f.write(local_store.to_json)
|
57
|
+
f.rewind
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_path
|
62
|
+
@file_path ||= 'tmp/localstorage.json'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/numeric/time'
|
4
|
+
|
5
|
+
module Wso2Toolbox
|
6
|
+
module TokenManager
|
7
|
+
module Adapters
|
8
|
+
module RailsCachedAdaper
|
9
|
+
class << self
|
10
|
+
TOKEN_DELAY = 5.minutes
|
11
|
+
|
12
|
+
def generate_token
|
13
|
+
new_token unless active_token?
|
14
|
+
store_token(Setting.token_for_job)
|
15
|
+
end
|
16
|
+
|
17
|
+
private_class_method
|
18
|
+
|
19
|
+
def new_token
|
20
|
+
token_params =
|
21
|
+
Wso2Toolbox::TokenManager::ApiManagerService.create_token
|
22
|
+
Setting.token_for_job =
|
23
|
+
"#{token_params[:token_type]} #{token_params[:access_token]}"
|
24
|
+
Setting.token_time_for_job =
|
25
|
+
Time.now + token_params[:expires_in].seconds
|
26
|
+
end
|
27
|
+
|
28
|
+
def store_token(token)
|
29
|
+
RequestStore.store[:token] = token
|
30
|
+
end
|
31
|
+
|
32
|
+
def active_token?
|
33
|
+
return false unless Setting.token_time_for_job
|
34
|
+
Time.parse(Setting.token_time_for_job) - TOKEN_DELAY > Time.now
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module Wso2Toolbox
|
6
|
+
module TokenManager
|
7
|
+
module ApiManagerService
|
8
|
+
class << self
|
9
|
+
def create_token
|
10
|
+
post(build_params)
|
11
|
+
end
|
12
|
+
|
13
|
+
private_class_method
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= Wso2Toolbox.configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_params
|
20
|
+
{
|
21
|
+
username: config.token_username,
|
22
|
+
password: config.token_password
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def post(params)
|
27
|
+
response = RestClient.post(config.token_url, params.to_json,
|
28
|
+
content_type: :json)
|
29
|
+
JSON.parse(response).with_indifferent_access
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/wso2_toolbox/version.rb
CHANGED
data/wso2_toolbox.gemspec
CHANGED
@@ -19,10 +19,16 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency 'actionpack', '>= 5.0'
|
21
21
|
spec.add_dependency 'activesupport', '>= 5.0'
|
22
|
+
spec.add_dependency 'request_store', '~> 1.3.2'
|
23
|
+
spec.add_dependency 'rest-client', '>= 2.0.2'
|
22
24
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.15.4'
|
26
|
+
spec.add_development_dependency 'dotenv'
|
27
|
+
spec.add_development_dependency 'pry-byebug'
|
24
28
|
spec.add_development_dependency 'rails-controller-testing', '~> 1.0'
|
25
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
31
|
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
32
|
+
spec.add_development_dependency 'vcr'
|
33
|
+
spec.add_development_dependency 'webmock'
|
28
34
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abner Carleto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -38,20 +38,76 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: request_store
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
75
|
+
version: 1.15.4
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
80
|
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: 1.15.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
- !ruby/object:Gem::Dependency
|
56
112
|
name: rails-controller-testing
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +164,34 @@ dependencies:
|
|
108
164
|
- - "~>"
|
109
165
|
- !ruby/object:Gem::Version
|
110
166
|
version: '3.1'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: vcr
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
111
195
|
description:
|
112
196
|
email:
|
113
197
|
- abner.carleto@cedrotech.com
|
@@ -115,6 +199,8 @@ executables: []
|
|
115
199
|
extensions: []
|
116
200
|
extra_rdoc_files: []
|
117
201
|
files:
|
202
|
+
- ".env.development"
|
203
|
+
- ".env.pipelines"
|
118
204
|
- ".gitignore"
|
119
205
|
- ".rspec"
|
120
206
|
- ".ruby-gemset"
|
@@ -127,10 +213,15 @@ files:
|
|
127
213
|
- bin/setup
|
128
214
|
- bitbucket-pipelines.yml
|
129
215
|
- lib/wso2_toolbox.rb
|
216
|
+
- lib/wso2_toolbox/configuration.rb
|
130
217
|
- lib/wso2_toolbox/identity_headers.rb
|
131
218
|
- lib/wso2_toolbox/rspec_utils.rb
|
132
219
|
- lib/wso2_toolbox/rspec_utils/shared_examples.rb
|
133
220
|
- lib/wso2_toolbox/rspec_utils/shared_examples/identity_headers.rb
|
221
|
+
- lib/wso2_toolbox/token_manager.rb
|
222
|
+
- lib/wso2_toolbox/token_manager/adapters/local_file_adapter.rb
|
223
|
+
- lib/wso2_toolbox/token_manager/adapters/rails_cached_adapter.rb
|
224
|
+
- lib/wso2_toolbox/token_manager/api_manager_service.rb
|
134
225
|
- lib/wso2_toolbox/version.rb
|
135
226
|
- wso2_toolbox.gemspec
|
136
227
|
homepage: https://bitbucket.org/guideinvestimentos/wso2_toolbox
|
@@ -152,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
243
|
version: '0'
|
153
244
|
requirements: []
|
154
245
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.6.
|
246
|
+
rubygems_version: 2.6.13
|
156
247
|
signing_key:
|
157
248
|
specification_version: 4
|
158
249
|
summary: WSO2 useful tools
|