istox 0.3.2 → 0.3.3

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: 0f204c5ffdfb9a40f6c2321cc863af4be2d859daabd265c4e38ef77f5a253ae3
4
- data.tar.gz: ccd9b724f91399670ed6cc8ff583cc458ebf40bec8d4e524b20fe8ef5b7aa1b8
3
+ metadata.gz: c9bf3a17183d7fb91c6d6a36bb13dc59086424459a3aa798dccd6696fd4bf871
4
+ data.tar.gz: 869342180a08d2391a5b6d1b624f8279c054301a9b1ddfea74a94349c821bd17
5
5
  SHA512:
6
- metadata.gz: 9858a1c492f1e12a4e4c32a2e36982d333a2e504ada7ce25e3724335855a244f525a2d75dea733aad6940267d659e82bfc3b12f2afaa3acb638b0b22ab5cc63f
7
- data.tar.gz: 236e8870b856d0c89b315b4ce67c5b8a20c7c89e2135987878a9e85f144517074851040a41f295766defc3fb9ab83ce720cc1e3812a362c41684e35330063618
6
+ metadata.gz: f56dbd0b7e69a18b7f4340cf7aa7597f42a909b8e93c69c37f00bd65e76736b14f40cd9392ea3dad00f1bc6cedc1a11583868c89842b48eccc92dc4b24467d65
7
+ data.tar.gz: 7a901a264db41abe8d32686b777c28966154e9b6fe2d115a439c57ad3e465a32be45cd86fe7d6fb4f6c3aeff66651fa32301eac868b50b5a87df0c81542dbe86
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.2.15)
4
+ istox (0.3.2)
5
5
  amazing_print
6
6
  awesome_print
7
7
  aws-sdk-sns (~> 1)
@@ -17,7 +17,6 @@ PATH
17
17
  redis (>= 2.0.0)
18
18
  redis-namespace (>= 1.0.0)
19
19
  redis-rails (~> 5.0.2)
20
- vault (~> 0.1)
21
20
 
22
21
  GEM
23
22
  remote: https://rubygems.org/
@@ -63,7 +62,7 @@ GEM
63
62
  i18n (>= 0.7, < 2)
64
63
  minitest (~> 5.1)
65
64
  tzinfo (~> 1.1)
66
- amazing_print (1.3.0)
65
+ amazing_print (1.4.0)
67
66
  amq-protocol (2.3.2)
68
67
  arel (9.0.0)
69
68
  awesome_print (1.9.2)
@@ -112,43 +111,49 @@ GEM
112
111
  i18n (~> 0.5)
113
112
  fakeredis (0.7.0)
114
113
  redis (>= 3.2, < 5.0)
115
- faraday (1.5.1)
114
+ faraday (1.9.3)
116
115
  faraday-em_http (~> 1.0)
117
116
  faraday-em_synchrony (~> 1.0)
118
117
  faraday-excon (~> 1.1)
119
- faraday-httpclient (~> 1.0.1)
118
+ faraday-httpclient (~> 1.0)
119
+ faraday-multipart (~> 1.0)
120
120
  faraday-net_http (~> 1.0)
121
- faraday-net_http_persistent (~> 1.1)
121
+ faraday-net_http_persistent (~> 1.0)
122
122
  faraday-patron (~> 1.0)
123
- multipart-post (>= 1.2, < 3)
123
+ faraday-rack (~> 1.0)
124
+ faraday-retry (~> 1.0)
124
125
  ruby2_keywords (>= 0.0.4)
125
126
  faraday-em_http (1.0.0)
126
127
  faraday-em_synchrony (1.0.0)
127
128
  faraday-excon (1.1.0)
128
129
  faraday-httpclient (1.0.1)
130
+ faraday-multipart (1.0.3)
131
+ multipart-post (>= 1.2, < 3)
129
132
  faraday-net_http (1.0.1)
130
133
  faraday-net_http_persistent (1.2.0)
131
134
  faraday-patron (1.0.0)
132
- faraday_middleware (1.0.0)
135
+ faraday-rack (1.0.0)
136
+ faraday-retry (1.0.3)
137
+ faraday_middleware (1.2.0)
133
138
  faraday (~> 1.0)
134
- ffi (1.15.3)
139
+ ffi (1.15.5)
135
140
  globalid (0.4.2)
136
141
  activesupport (>= 4.2.0)
137
- google-protobuf (3.17.3-universal-darwin)
138
- googleapis-common-protos-types (1.1.0)
142
+ google-protobuf (3.19.4-x86_64-darwin)
143
+ googleapis-common-protos-types (1.3.0)
139
144
  google-protobuf (~> 3.14)
140
145
  graphlient (0.5.0)
141
146
  faraday (>= 1.0)
142
147
  faraday_middleware
143
148
  graphql-client
144
- graphql (1.12.14)
145
- graphql-client (0.16.0)
149
+ graphql (1.13.6)
150
+ graphql-client (0.17.0)
146
151
  activesupport (>= 3.0)
147
- graphql (~> 1.8)
148
- grpc (1.38.0-universal-darwin)
149
- google-protobuf (~> 3.15)
152
+ graphql (~> 1.10)
153
+ grpc (1.43.1-universal-darwin)
154
+ google-protobuf (~> 3.18)
150
155
  googleapis-common-protos-types (~> 1.0)
151
- grpc-tools (1.38.0)
156
+ grpc-tools (1.43.1)
152
157
  hashie (3.5.7)
153
158
  i18n (0.9.5)
154
159
  concurrent-ruby (~> 1.0)
@@ -178,11 +183,11 @@ GEM
178
183
  nokogiri (1.11.7)
179
184
  mini_portile2 (~> 2.5.0)
180
185
  racc (~> 1.4)
181
- oj (3.12.2)
186
+ oj (3.13.11)
182
187
  ougai (2.0.0)
183
188
  oj (~> 3.10)
184
- paranoia (2.4.3)
185
- activerecord (>= 4.0, < 6.2)
189
+ paranoia (2.6.0)
190
+ activerecord (>= 5.1, < 7.1)
186
191
  pry (0.12.2)
187
192
  coderay (~> 1.1.0)
188
193
  method_source (~> 0.9.0)
@@ -220,28 +225,28 @@ GEM
220
225
  rake (>= 0.8.7)
221
226
  thor (>= 0.19.0, < 2.0)
222
227
  rake (10.5.0)
223
- rb-fsevent (0.11.0)
228
+ rb-fsevent (0.11.1)
224
229
  rb-inotify (0.10.1)
225
230
  ffi (~> 1.0)
226
- rbtree (0.4.4)
231
+ rbtree (0.4.5)
227
232
  redis (4.3.1)
228
- redis-actionpack (5.2.0)
229
- actionpack (>= 5, < 7)
233
+ redis-actionpack (5.3.0)
234
+ actionpack (>= 5, < 8)
230
235
  redis-rack (>= 2.1.0, < 3)
231
236
  redis-store (>= 1.1.0, < 2)
232
- redis-activesupport (5.2.1)
233
- activesupport (>= 3, < 7)
237
+ redis-activesupport (5.3.0)
238
+ activesupport (>= 3, < 8)
234
239
  redis-store (>= 1.3, < 2)
235
240
  redis-namespace (1.8.1)
236
241
  redis (>= 3.0.4)
237
- redis-rack (2.1.3)
242
+ redis-rack (2.1.4)
238
243
  rack (>= 2.0.8, < 3)
239
244
  redis-store (>= 1.2, < 2)
240
245
  redis-rails (5.0.2)
241
246
  redis-actionpack (>= 5.0, < 6)
242
247
  redis-activesupport (>= 5.0, < 6)
243
248
  redis-store (>= 1.2, < 2)
244
- redis-store (1.9.0)
249
+ redis-store (1.9.1)
245
250
  redis (>= 4, < 5)
246
251
  rspec (3.8.0)
247
252
  rspec-core (~> 3.8.0)
@@ -265,7 +270,7 @@ GEM
265
270
  rspec-support (~> 3.8.0)
266
271
  rspec-support (3.8.0)
267
272
  ruby2_keywords (0.0.5)
268
- set (1.0.1)
273
+ set (1.0.2)
269
274
  slop (4.9.1)
270
275
  sorted_set (1.0.3)
271
276
  rbtree
@@ -284,8 +289,6 @@ GEM
284
289
  tzinfo (1.2.9)
285
290
  thread_safe (~> 0.1)
286
291
  uniform_notifier (1.11.0)
287
- vault (0.16.0)
288
- aws-sigv4
289
292
  websocket-driver (0.7.5)
290
293
  websocket-extensions (>= 0.1.0)
291
294
  websocket-extensions (0.1.5)
data/istox.gemspec CHANGED
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
45
45
  spec.add_dependency 'redis', '>= 2.0.0'
46
46
  spec.add_dependency 'redis-namespace', '>= 1.0.0'
47
47
  spec.add_dependency 'redis-rails', '~> 5.0.2'
48
- spec.add_dependency 'vault', '~> 0.1'
48
+ # spec.add_dependency 'vault', '~> 0.1'
49
49
  spec.add_development_dependency 'aws-xray-sdk'
50
50
  spec.add_development_dependency 'bullet', '~> 5.7.5'
51
51
  spec.add_development_dependency 'bundler', '~> 1.16'
@@ -32,6 +32,14 @@ module Istox
32
32
  db: 5
33
33
  ))
34
34
  end
35
+
36
+ # for otp of SNS
37
+ def otp_redis
38
+ @otp_redis ||= Redis::Namespace.new(:otp, redis: Redis.new(
39
+ url: ENV['REDIS_URL'] || 'redis://127.0.0.1:16379',
40
+ db: 10
41
+ ))
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -1,85 +1,106 @@
1
1
  require 'istox/helpers/logger'
2
- require 'vault'
2
+ # require 'vault'
3
3
 
4
4
  module Istox
5
5
  module Vault
6
- module TOTP
7
- class << self
8
- def create(sid, host)
9
- log.debug { "Generate vault TOTP for key #{totp_key(sid).inspect}" }
10
-
11
- write_data(totp_key(sid),
12
- generate: true,
13
- issuer: host,
14
- account_name: sid,
15
- period: 300,
16
- qr_size: 300)
17
- end
18
-
19
- def generate_code(sid)
20
- log.debug { "Generate 6-digit OTP code: key #{totp_code_key(sid)}" }
21
- read_data(totp_code_key(sid)).data[:code]
22
- end
23
-
24
- def validate?(sid, code)
25
- log.debug { "Validate TOTP code: key #{totp_code_key(sid)}, code: #{code}" }
26
- result = write_data(totp_code_key(sid), code: code).data[:valid]
27
-
28
- unless result
29
- code = read_data(totp_code_key(sid)).data[:code]
30
- log.debug { "Code is not valid, it should be #{code}" }
31
- end
32
-
33
- result
34
- end
35
-
36
- private
37
-
38
- def read_data(key)
39
- ::Vault.logical.read(key)
40
- end
41
-
42
- def write_data(key, params)
43
- ::Vault.logical.write(key, params)
44
- end
45
-
46
- def totp_key(sid)
47
- "totp/keys/#{sid}"
48
- end
49
-
50
- def totp_code_key(sid)
51
- "totp/code/#{sid}"
52
- end
53
- end
54
- end
6
+ # module TOTP
7
+ # class << self
8
+ # # def create(sid, host)
9
+ # # log.debug { "Generate vault TOTP for key #{totp_key(sid).inspect}" }
10
+
11
+ # # write_data(totp_key(sid),
12
+ # # generate: true,
13
+ # # issuer: host,
14
+ # # account_name: sid,
15
+ # # period: 300,
16
+ # # qr_size: 300)
17
+ # # end
18
+
19
+ # # def generate_code(sid)
20
+ # # log.debug { "Generate 6-digit OTP code: key #{totp_code_key(sid)}" }
21
+ # # read_data(totp_code_key(sid)).data[:code]
22
+ # # end
23
+
24
+ # # def validate?(sid, code)
25
+ # # log.debug { "Validate TOTP code: key #{totp_code_key(sid)}, code: #{code}" }
26
+ # # result = write_data(totp_code_key(sid), code: code).data[:valid]
27
+
28
+ # # unless result
29
+ # # code = read_data(totp_code_key(sid)).data[:code]
30
+ # # log.debug { "Code is not valid, it should be #{code}" }
31
+ # # end
32
+
33
+ # # result
34
+ # # end
35
+
36
+ # # private
37
+
38
+ # # def read_data(key)
39
+ # # ::Vault.logical.read(key)
40
+ # # end
41
+
42
+ # # def write_data(key, params)
43
+ # # ::Vault.logical.write(key, params)
44
+ # # end
45
+
46
+ # # def totp_key(sid)
47
+ # # "totp/keys/#{sid}"
48
+ # # end
49
+
50
+ # # def totp_code_key(sid)
51
+ # # "totp/code/#{sid}"
52
+ # # end
53
+ # # end
54
+ # end
55
55
 
56
56
  class << self
57
- def logical
58
- ::Vault.logical
57
+ # def logical
58
+ # ::Vault.logical
59
+ # end
60
+
61
+ # def initialize(secret_key, file_location)
62
+ # ::Vault.configure do |config|
63
+ # config.address = secret_key
64
+
65
+ # if File.exist?(file_location)
66
+ # token = File.read(file_location).strip
67
+ # config.token = token
68
+ # config.ssl_verify = false
69
+ # config.timeout = 60
70
+ # else
71
+ # log.info 'Vault token not found, OTP will not be able to use'
72
+ # end
73
+ # end
74
+ # end
75
+
76
+ def get_otp(sid, _host, expired_seconds: 300)
77
+ # ::Istox::Vault::TOTP.create(sid, host)
78
+ # Istox::Vault::TOTP.generate_code(sid)
79
+
80
+ otp = 6.times.map { rand(10) }.join
81
+
82
+ otp_redis.set(sid, otp, nx: false, ex: expired_seconds.seconds)
83
+
84
+ otp
59
85
  end
60
86
 
61
- def initialize(secret_key, file_location)
62
- ::Vault.configure do |config|
63
- config.address = secret_key
64
-
65
- if File.exist?(file_location)
66
- token = File.read(file_location).strip
67
- config.token = token
68
- config.ssl_verify = false
69
- config.timeout = 60
70
- else
71
- log.info 'Vault token not found, OTP will not be able to use'
72
- end
73
- end
74
- end
87
+ def validate_otp(sid, otp)
88
+ # ::Istox::Vault::TOTP.validate?(sid, otp)
89
+
90
+ stored_otp = otp_redis.get(sid)
75
91
 
76
- def get_otp(sid, host)
77
- ::Istox::Vault::TOTP.create(sid, host)
78
- Istox::Vault::TOTP.generate_code(sid)
92
+ return false if stored_otp.blank?
93
+ return false if otp.blank?
94
+
95
+ result = otp.to_s == stored_otp.to_s
96
+
97
+ otp_redis.del(sid) if result == true
98
+
99
+ result
79
100
  end
80
101
 
81
- def validate_otp(sid, otp)
82
- ::Istox::Vault::TOTP.validate?(sid, otp)
102
+ def otp_redis
103
+ @otp_redis ||= ::Istox::RedisManager.otp_redis
83
104
  end
84
105
  end
85
106
  end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -220,20 +220,6 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: 5.0.2
223
- - !ruby/object:Gem::Dependency
224
- name: vault
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: '0.1'
230
- type: :runtime
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: '0.1'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: aws-xray-sdk
239
225
  requirement: !ruby/object:Gem::Requirement