zuora_connect 2.0.5zj → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/zuora_connect/static_controller.rb +17 -4
- data/app/helpers/zuora_connect/application_helper.rb +0 -10
- data/app/models/zuora_connect/app_instance_base.rb +66 -109
- data/app/models/zuora_connect/telegraf.rb +2 -2
- data/app/models/zuora_connect/zuora_user.rb +0 -1
- data/app/views/zuora_connect/static/invalid_app_instance_error.html.erb +65 -0
- data/app/views/zuora_connect/static/invalid_launch_request.html.erb +81 -0
- data/app/views/zuora_connect/static/launch.html.erb +75 -74
- data/app/views/zuora_connect/static/permission_error.html.erb +80 -0
- data/app/views/zuora_connect/static/session_error.html.erb +63 -0
- data/config/routes.rb +2 -0
- data/lib/middleware/request_id_middleware.rb +1 -1
- data/lib/resque/plugins/custom_logger.rb +1 -1
- data/lib/zuora_connect.rb +42 -59
- data/lib/zuora_connect/configuration.rb +3 -3
- data/lib/zuora_connect/controllers/helpers.rb +183 -253
- data/lib/zuora_connect/engine.rb +1 -2
- data/lib/zuora_connect/railtie.rb +6 -10
- data/lib/zuora_connect/version.rb +1 -1
- data/lib/zuora_connect/views/helpers.rb +9 -0
- metadata +54 -54
- data/app/views/zuora_connect/static/error_handled.html.erb +0 -77
- data/app/views/zuora_connect/static/error_unhandled.erb +0 -82
- data/config/initializers/patches.rb +0 -9
- data/db/migrate/20190520232222_add_unique_index.rb +0 -6
- data/lib/middleware/json_parse_errors.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5143516252b30663cce6eff40b07c9364cdcbe566b5a17fea4b55a6d86d23dbd
|
4
|
+
data.tar.gz: e967de5bf2ec2a7ba2c6160472e7ca222ca5102827257c69abc96638f15a40f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab2c1ec88ec22ab427921e538aeb1133fef59016fa8b019970a421e0909c94ede7ed51888915e0856a276b4113cfdac703e1062c379a621f07d919695d66628
|
7
|
+
data.tar.gz: 1334c2fbe71031f57d182f5a2e5364491189f9ce475c4b271be364f78be78c2bb47b098ec95b6ab57292b6d2557bbdcfcc89053711be77976afe0725a6f8cd33
|
@@ -1,11 +1,25 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class StaticController < ApplicationController
|
3
|
-
before_action :authenticate_connect_app_request, :except => [:metrics, :health, :initialize_app]
|
4
|
-
before_action :clear_connect_app_session, :only => [:metrics, :health, :initialize_app]
|
5
|
-
after_action :persist_connect_app_session, :except => [:metrics, :health, :initialize_app]
|
3
|
+
before_action :authenticate_connect_app_request, :except => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
4
|
+
before_action :clear_connect_app_session, :only => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
5
|
+
after_action :persist_connect_app_session, :except => [:metrics, :health, :session_error, :invalid_app_instance_error, :initialize_app]
|
6
6
|
|
7
7
|
skip_before_action :verify_authenticity_token, :only => [:initialize_app]
|
8
8
|
|
9
|
+
def session_error
|
10
|
+
respond_to do |format|
|
11
|
+
format.html
|
12
|
+
format.json { render json: { message: "Session Error", status: 500 }, status: 500 }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def invalid_app_instance_error
|
17
|
+
respond_to do |format|
|
18
|
+
format.html
|
19
|
+
format.json {render json: { message: "Invalid App Instance", status: 500 }, status: 500 }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
def metrics
|
10
24
|
type = params[:type].present? ? params[:type] : "versions"
|
11
25
|
render json: ZuoraConnect::AppInstance.get_metrics(type).to_json, status: 200
|
@@ -34,7 +48,6 @@ module ZuoraConnect
|
|
34
48
|
def initialize_app
|
35
49
|
begin
|
36
50
|
authenticate_connect_app_request
|
37
|
-
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
38
51
|
render json: {
|
39
52
|
message: "Success",
|
40
53
|
status: 200
|
@@ -1,15 +1,5 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
module ApplicationHelper
|
3
|
-
def is_app_admin?
|
4
|
-
return @appinstance.blank? ? false : session["#{@appinstance.id}::admin"]
|
5
|
-
end
|
6
3
|
|
7
|
-
def zuora_user
|
8
|
-
return @zuora_user
|
9
|
-
end
|
10
|
-
|
11
|
-
def connect_meta_tags
|
12
|
-
"<meta name=\"z-hallway-prefix\" content=\"#{ Thread.current[:isHallway] }\">".html_safe
|
13
|
-
end
|
14
4
|
end
|
15
5
|
end
|
@@ -16,7 +16,7 @@ module ZuoraConnect
|
|
16
16
|
BLANK_OBJECT_ID_LOOKUP = 'BlankValueSupplied'
|
17
17
|
HOLDING_PATTERN_SLEEP = 5.seconds
|
18
18
|
CONNECT_COMMUNICATION_SLEEP= 5.seconds
|
19
|
-
IGNORED_LOCALS = ['fr', 'ja', '
|
19
|
+
IGNORED_LOCALS = ['fr', 'ja', 'sp']
|
20
20
|
INTERNAL_HOSTS = []
|
21
21
|
LOGIN_TENANT_DESTINATION = 'target_login'
|
22
22
|
|
@@ -89,11 +89,7 @@ module ZuoraConnect
|
|
89
89
|
Thread.current[:appinstance] = self
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
93
|
-
return {app_instance_id: self.id}
|
94
|
-
end
|
95
|
-
|
96
|
-
def new_session(session: self.data_lookup, username: self.access_token, password: self.refresh_token, holding_pattern: false, **args)
|
92
|
+
def new_session(session: self.data_lookup, username: self.access_token, password: self.refresh_token, holding_pattern: false, log_level: Logger::DEBUG)
|
97
93
|
self.api_version = "v2"
|
98
94
|
self.username = username
|
99
95
|
self.password = password
|
@@ -127,26 +123,26 @@ module ZuoraConnect
|
|
127
123
|
|
128
124
|
if session.empty?
|
129
125
|
self.new_session_message = "REFRESHING - Session Empty"
|
130
|
-
ZuoraConnect.logger.
|
126
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
131
127
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
132
128
|
self.refresh(session: session)
|
133
129
|
|
134
130
|
elsif (self.id != session["appInstance"].to_i)
|
135
131
|
self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
|
136
|
-
ZuoraConnect.logger.
|
132
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
137
133
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
138
134
|
self.refresh(session: session)
|
139
135
|
|
140
136
|
elsif session["#{self.id}::task_data"].blank?
|
141
137
|
self.new_session_message = "REFRESHING - Task Data Blank"
|
142
|
-
ZuoraConnect.logger.
|
138
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
143
139
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
144
140
|
self.refresh(session: session)
|
145
141
|
|
146
142
|
elsif session["#{self.id}::last_refresh"].blank?
|
147
143
|
self.new_session_message = "REFRESHING - No Time on Cookie"
|
148
144
|
recoverable_session = true
|
149
|
-
ZuoraConnect.logger.
|
145
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
150
146
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
151
147
|
self.refresh(session: session)
|
152
148
|
|
@@ -154,7 +150,7 @@ module ZuoraConnect
|
|
154
150
|
elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
|
155
151
|
self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
|
156
152
|
recoverable_session = true
|
157
|
-
ZuoraConnect.logger.
|
153
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
158
154
|
self.refresh(session: session)
|
159
155
|
|
160
156
|
else
|
@@ -163,14 +159,14 @@ module ZuoraConnect
|
|
163
159
|
else
|
164
160
|
self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
|
165
161
|
end
|
166
|
-
ZuoraConnect.logger.
|
162
|
+
ZuoraConnect.logger.add(log_level, self.new_session_message)
|
167
163
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
168
164
|
end
|
169
165
|
end
|
170
166
|
return self
|
171
167
|
rescue ZuoraConnect::Exceptions::HoldingPattern => ex
|
172
168
|
while self.marked_for_refresh?
|
173
|
-
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'"
|
169
|
+
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
|
174
170
|
sleep(HOLDING_PATTERN_SLEEP)
|
175
171
|
end
|
176
172
|
self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
|
@@ -178,11 +174,10 @@ module ZuoraConnect
|
|
178
174
|
retry
|
179
175
|
rescue => ex
|
180
176
|
if recoverable_session
|
181
|
-
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache"
|
177
|
+
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache")
|
182
178
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
183
179
|
return self
|
184
180
|
else
|
185
|
-
ZuoraConnect.logger.error("Failed new session", ex, self.default_ougai_items)
|
186
181
|
raise
|
187
182
|
end
|
188
183
|
ensure
|
@@ -192,108 +187,70 @@ module ZuoraConnect
|
|
192
187
|
ZuoraConnect.logger.error(ex) if !IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
193
188
|
end
|
194
189
|
Time.zone = self.timezone
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = zuora_domain
|
211
|
-
params.merge!({:zuora_domain => zuora_domain }) if self.methods.include?(LOGIN_TENANT_DESTINATION.to_sym)
|
212
|
-
params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
|
213
|
-
self.update_columns(params) if params.present?
|
214
|
-
end
|
190
|
+
tenants = self.task_data.dig('tenant_ids') || []
|
191
|
+
organizations = self.task_data.dig('organizations') || []
|
192
|
+
if defined?(ElasticAPM) && ElasticAPM.running?
|
193
|
+
ElasticAPM.set_tag(:tenant_id, tenants.first)
|
194
|
+
ElasticAPM.set_tag(:organization, organizations.first)
|
195
|
+
end
|
196
|
+
self.logitem(item: {tenant_ids: tenants, organization: organizations})
|
197
|
+
params = {
|
198
|
+
:name => self.task_data.dig('name'),
|
199
|
+
:zuora_domain => self.target_login.client.rest_domain,
|
200
|
+
:zuora_entity_ids => self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities').map{|e| e['id']},
|
201
|
+
:zuora_tenant_ids => self.task_data['tenant_ids'],
|
202
|
+
}
|
203
|
+
params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
|
204
|
+
self.update_columns(params) if params.present?
|
215
205
|
end
|
216
206
|
|
217
207
|
def refresh(session: {}, session_fallback: false)
|
218
208
|
refresh_count ||= 0
|
219
209
|
#Check how app was deployed
|
220
|
-
if !self
|
210
|
+
if !self.zuora_logins.present?
|
221
211
|
start = Time.now
|
222
212
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
223
213
|
response_time = Time.now - start
|
224
214
|
|
225
|
-
ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}"
|
215
|
+
ZuoraConnect.logger.debug("[#{self.id}] REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
|
226
216
|
if response.code == 200
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
end
|
232
|
-
self.build_task(task_data: parsed_json, session: session)
|
217
|
+
self.build_task(task_data: JSON.parse(response.body), session: session)
|
218
|
+
self.last_refresh = Time.now.to_i
|
219
|
+
self.cache_app_instance
|
220
|
+
self.reset_mark_for_refresh
|
233
221
|
else
|
234
222
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
235
223
|
end
|
236
224
|
else
|
237
|
-
self.build_task(task_data: self.zuora_logins, session: session)
|
225
|
+
self.build_task(task_data: JSON.parse(self.zuora_logins), session: session)
|
226
|
+
self.last_refresh = Time.now.to_i
|
227
|
+
self.cache_app_instance
|
228
|
+
self.reset_mark_for_refresh
|
238
229
|
end
|
239
|
-
|
240
|
-
self.cache_app_instance
|
241
|
-
self.reset_mark_for_refresh
|
242
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
230
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
243
231
|
if (refresh_count += 1) < 3
|
244
|
-
|
245
|
-
ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
|
232
|
+
ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - #{ex.class} Retrying(#{refresh_count})")
|
246
233
|
retry
|
247
234
|
else
|
248
|
-
ZuoraConnect.logger.fatal("REFRESH TASK -
|
235
|
+
ZuoraConnect.logger.fatal("[#{self.id}] REFRESH TASK - #{ex.class} Failed #{refresh_count}x")
|
249
236
|
raise
|
250
237
|
end
|
251
238
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
252
239
|
if (refresh_count += 1) < 3
|
253
|
-
ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
|
254
240
|
if ex.code == 401
|
241
|
+
ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
255
242
|
self.refresh_oauth
|
243
|
+
else
|
244
|
+
ZuoraConnect.logger.warn("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
256
245
|
end
|
257
246
|
retry
|
258
247
|
else
|
259
|
-
ZuoraConnect.logger.fatal("REFRESH TASK -
|
248
|
+
ZuoraConnect.logger.fatal("[#{self.id}] REFRESH TASK - Failed #{ex.code} - #{refresh_count}x")
|
260
249
|
raise
|
261
250
|
end
|
262
251
|
end
|
263
252
|
|
264
|
-
#### START
|
265
|
-
def zuora_logins=(val)
|
266
|
-
write_attribute(:zuora_logins, kms_encrypt(val.to_json))
|
267
|
-
end
|
268
|
-
|
269
|
-
def zuora_logins
|
270
|
-
return JSON.parse(kms_decrypt(super))
|
271
|
-
end
|
272
|
-
|
273
|
-
def kms_decrypt(value)
|
274
|
-
kms_client = Aws::KMS::Client.new({region: Rails.application.secrets.aws['AWS_REGION'], credentials: self.aws_auth_client}.delete_if { |k, v| v.blank? })
|
275
|
-
resp = kms_client.decrypt({ciphertext_blob: [value].pack("H*") })
|
276
|
-
return resp.plaintext
|
277
|
-
end
|
278
|
-
|
279
|
-
def kms_encrypt(value)
|
280
|
-
kms_client = Aws::KMS::Client.new({region: Rails.application.secrets.aws['AWS_REGION'], credentials: self.aws_auth_client}.delete_if {|k,v| v.blank? })
|
281
|
-
kms_key = ENV['AWS_KMS_ARN'] || Rails.application.secrets.aws['AWS_KMS_ARN']
|
282
|
-
|
283
|
-
resp = kms_client.encrypt({key_id: kms_key, plaintext: value})
|
284
|
-
return resp.ciphertext_blob.unpack('H*').first
|
285
|
-
end
|
286
|
-
|
287
|
-
def aws_auth_client
|
288
|
-
if Rails.env.to_s == 'development'
|
289
|
-
return Aws::Credentials.new(Rails.application.secrets.aws['AWS_ACCESS_KEY_ID'], Rails.application.secrets.aws['AWS_SECRET_ACCESS_KEY'])
|
290
|
-
else
|
291
|
-
return nil
|
292
|
-
end
|
293
|
-
end
|
294
|
-
#### END KMS ENCRYPTION Methods ####
|
295
|
-
|
296
|
-
#### START Metrics Methods ####
|
253
|
+
#### START Metrics Mathods ####
|
297
254
|
def logitem(item: {}, reset: false)
|
298
255
|
self.logitems = {} if self.logitems.class != Hash
|
299
256
|
if item.class == Hash
|
@@ -377,9 +334,9 @@ module ZuoraConnect
|
|
377
334
|
end
|
378
335
|
return @data
|
379
336
|
end
|
380
|
-
#### END Task
|
337
|
+
#### END Task Mathods ####
|
381
338
|
|
382
|
-
#### START Task
|
339
|
+
#### START Task Mathods ####
|
383
340
|
def build_task(task_data: {}, session: {})
|
384
341
|
session = {} if session.blank?
|
385
342
|
self.task_data = task_data
|
@@ -444,7 +401,7 @@ module ZuoraConnect
|
|
444
401
|
else
|
445
402
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
446
403
|
end
|
447
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
404
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
448
405
|
if (update_login_count += 1) < 3
|
449
406
|
retry
|
450
407
|
else
|
@@ -472,7 +429,7 @@ module ZuoraConnect
|
|
472
429
|
else
|
473
430
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
474
431
|
end
|
475
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
432
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
476
433
|
if (update_task_count += 1) < 3
|
477
434
|
retry
|
478
435
|
else
|
@@ -488,13 +445,13 @@ module ZuoraConnect
|
|
488
445
|
raise
|
489
446
|
end
|
490
447
|
end
|
491
|
-
#### END Task
|
448
|
+
#### END Task Mathods ####
|
492
449
|
|
493
|
-
#### START Connect OAUTH
|
450
|
+
#### START Connect OAUTH methods ####
|
494
451
|
def check_oauth_state(method)
|
495
452
|
#Refresh token if already expired
|
496
453
|
if self.oauth_expired?
|
497
|
-
ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired"
|
454
|
+
ZuoraConnect.logger.debug("[#{self.id}] Before '#{method}' method, Oauth expired")
|
498
455
|
self.refresh_oauth
|
499
456
|
end
|
500
457
|
end
|
@@ -513,7 +470,7 @@ module ZuoraConnect
|
|
513
470
|
}
|
514
471
|
response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
|
515
472
|
response_time = Time.now - start
|
516
|
-
ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}"
|
473
|
+
ZuoraConnect.logger.debug("[#{self.id}] REFRESH OAUTH - In #{response_time.round(2).to_s}")
|
517
474
|
|
518
475
|
if response.code == 200
|
519
476
|
response_body = JSON.parse(response.body)
|
@@ -523,15 +480,14 @@ module ZuoraConnect
|
|
523
480
|
self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
|
524
481
|
self.save(:validate => false)
|
525
482
|
else
|
526
|
-
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token", response.body, response.code)
|
483
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token for #{self.id}", response.body, response.code)
|
527
484
|
end
|
528
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
485
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
529
486
|
if (refresh_oauth_count += 1) < 3
|
530
|
-
|
531
|
-
ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
|
487
|
+
ZuoraConnect.logger.info("[#{self.id}] REFRESH OAUTH - #{ex.class} Retrying(#{refresh_oauth_count})")
|
532
488
|
retry
|
533
489
|
else
|
534
|
-
ZuoraConnect.logger.fatal("REFRESH OAUTH -
|
490
|
+
ZuoraConnect.logger.fatal("[#{self.id}] REFRESH OAUTH - #{ex.class} Failed #{refresh_oauth_count}x")
|
535
491
|
raise
|
536
492
|
end
|
537
493
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
@@ -542,14 +498,14 @@ module ZuoraConnect
|
|
542
498
|
return if !self.oauth_expired?
|
543
499
|
|
544
500
|
if (refresh_oauth_count += 1) < 3
|
545
|
-
ZuoraConnect.logger.
|
501
|
+
ZuoraConnect.logger.info("[#{self.id}] REFRESH OAUTH - Failed #{ex.code} - Retrying(#{refresh_oauth_count})")
|
546
502
|
retry
|
547
503
|
else
|
548
|
-
ZuoraConnect.logger.fatal("REFRESH OAUTH -
|
504
|
+
ZuoraConnect.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed #{ex.code} - #{refresh_oauth_count}x")
|
549
505
|
raise
|
550
506
|
end
|
551
507
|
end
|
552
|
-
#### END Connect OAUTH
|
508
|
+
#### END Connect OAUTH methods ####
|
553
509
|
|
554
510
|
#### START AppInstance Temporary Persistance Methods ####
|
555
511
|
def marked_for_refresh?
|
@@ -587,7 +543,7 @@ module ZuoraConnect
|
|
587
543
|
begin
|
588
544
|
redis_get_command ||= 0
|
589
545
|
cached_instance = Redis.current.get("AppInstance:#{self.id}")
|
590
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
546
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
591
547
|
if (redis_get_command += 1) < 3
|
592
548
|
retry
|
593
549
|
else
|
@@ -595,10 +551,10 @@ module ZuoraConnect
|
|
595
551
|
end
|
596
552
|
end
|
597
553
|
if cached_instance.blank?
|
598
|
-
ZuoraConnect.logger.debug("Cached AppInstance Missing"
|
554
|
+
ZuoraConnect.logger.debug("[#{self.id}] Cached AppInstance Missing")
|
599
555
|
return session
|
600
556
|
else
|
601
|
-
ZuoraConnect.logger.debug("Cached AppInstance Found"
|
557
|
+
ZuoraConnect.logger.debug("[#{self.id}] Cached AppInstance Found")
|
602
558
|
return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
|
603
559
|
end
|
604
560
|
else
|
@@ -610,7 +566,7 @@ module ZuoraConnect
|
|
610
566
|
if defined?(Redis.current)
|
611
567
|
#Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
|
612
568
|
if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
|
613
|
-
ZuoraConnect.logger.debug("Caching AppInstance"
|
569
|
+
ZuoraConnect.logger.debug("[#{self.id}] Caching AppInstance")
|
614
570
|
Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
|
615
571
|
end
|
616
572
|
end
|
@@ -671,10 +627,9 @@ module ZuoraConnect
|
|
671
627
|
begin
|
672
628
|
return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
|
673
629
|
rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
|
674
|
-
ZuoraConnect.logger.
|
630
|
+
ZuoraConnect.logger.add(Logger::ERROR, "Error Decrypting for #{self.id}") if log_fatal
|
675
631
|
return rescue_return
|
676
632
|
rescue JSON::ParserError => ex
|
677
|
-
ZuoraConnect.logger.error("JSON Parse Error", ex, self.default_ougai_items) if log_fatal
|
678
633
|
return encryptor.decrypt_and_verify(CGI::unescape(data))
|
679
634
|
end
|
680
635
|
end
|
@@ -1041,7 +996,9 @@ module ZuoraConnect
|
|
1041
996
|
|
1042
997
|
def method_missing(method_sym, *arguments, &block)
|
1043
998
|
if method_sym.to_s.include?("login")
|
1044
|
-
ZuoraConnect.logger.fatal("Method Missing #{method_sym}
|
999
|
+
ZuoraConnect.logger.fatal("Method Missing #{method_sym}")
|
1000
|
+
ZuoraConnect.logger.fatal("Instance Data: #{self.task_data}")
|
1001
|
+
ZuoraConnect.logger.fatal("Instance Logins: #{self.logins}")
|
1045
1002
|
end
|
1046
1003
|
super
|
1047
1004
|
end
|
@@ -19,7 +19,7 @@ module ZuoraConnect
|
|
19
19
|
end
|
20
20
|
rescue => ex
|
21
21
|
self.host = nil
|
22
|
-
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}"))
|
22
|
+
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}"))
|
23
23
|
end
|
24
24
|
|
25
25
|
def write(direction: 'Unknown', tags: {}, values: {})
|
@@ -56,7 +56,7 @@ module ZuoraConnect
|
|
56
56
|
self.host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
|
57
57
|
rescue => ex
|
58
58
|
self.connect
|
59
|
-
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}"))
|
59
|
+
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}"))
|
60
60
|
end
|
61
61
|
|
62
62
|
def format_metric_log(message, dump = nil)
|