istox 0.3.0 → 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: bf92c8de5dc5407049f3a216cbf0d63df754aa1c4d23473a2a87a9628d71bbc8
4
- data.tar.gz: 2cfce3c6ef9c45edcff3f9c34d8e27def16e6ed6cf94343acd9d810052d2ecb8
3
+ metadata.gz: c9bf3a17183d7fb91c6d6a36bb13dc59086424459a3aa798dccd6696fd4bf871
4
+ data.tar.gz: 869342180a08d2391a5b6d1b624f8279c054301a9b1ddfea74a94349c821bd17
5
5
  SHA512:
6
- metadata.gz: f91e99b9bb7ae5fab66068e14d7c049187662b7265afcb45c7538af6b72bbd4c0e8d60eb7b0afd0e3eb60412709b32a42f38a3eebab8f07d8ef56d64f5fa76cd
7
- data.tar.gz: 7f48b151239306cdfe9b754c195f7f2d01608efddec8342aaf10f779f6693fdf4b9ece2cf3208345e79ae3e605cc94b9ec5382ed229895a7fc7e28645bc5afe0
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'
@@ -3,10 +3,12 @@ require 'istox/helpers/logger'
3
3
  module Istox
4
4
  class GrpcClient
5
5
  class << self
6
- def add_host(host_type, url)
6
+ def add_host(host_type, url, cert: nil)
7
7
  @@hosts = {} unless defined?(@@hosts)
8
+ @@certs = {} unless defined?(@@certs)
8
9
 
9
10
  @@hosts[host_type] = url
11
+ @@certs[host_type] = cert
10
12
  end
11
13
 
12
14
  def add_interceptors(interceptor)
@@ -16,7 +18,7 @@ module Istox
16
18
  end
17
19
 
18
20
  def configure_grpc_logger
19
- Gruf.grpc_logger = log
21
+ Gruf.grpc_logger = log
20
22
  end
21
23
 
22
24
  def call(host_type, service, method, grpc_retries_count: 1, **keyword_args)
@@ -78,11 +80,14 @@ module Istox
78
80
  @@services = {} unless defined?(@@services)
79
81
 
80
82
  host_url = @@hosts[host_type]
83
+ cert_path = @@certs[host_type]
81
84
  raise StandardError, 'Unable to find host, have you forgotten to add host to grpc client?' unless host_url
82
85
 
83
86
  log.info 'Reinitiating to grpc host at ' + host_url
84
87
  t1 = Time.now
85
- @@services[get_key(host_type, service)] = ::Gruf::Client.new(service: service, options: { hostname: host_url }, client_options: client_options)
88
+ @@services[get_key(host_type, service)] = ::Gruf::Client.new(service: service,
89
+ options: { hostname: host_url, ssl_certificate_file: cert_path },
90
+ client_options: client_options)
86
91
  log.info "Time taken for reinitiating grpc host: #{Time.now - t1} seconds"
87
92
  end
88
93
 
@@ -24,6 +24,22 @@ module Istox
24
24
  db: 6
25
25
  ))
26
26
  end
27
+
28
+ # for send_grid email templates cache
29
+ def sendgrid_email_templates
30
+ @sendgrid_email_templates ||= Redis::Namespace.new(:sendgrid_email_templates, redis: Redis.new(
31
+ url: ENV['REDIS_URL'] || 'redis://127.0.0.1:16379',
32
+ db: 5
33
+ ))
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
27
43
  end
28
44
  end
29
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.0'.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.0
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-01-26 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