zuora_connect 2.0.5 → 2.0.8
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 +4 -17
- data/app/helpers/zuora_connect/application_helper.rb +10 -0
- data/app/models/zuora_connect/app_instance_base.rb +109 -66
- data/app/models/zuora_connect/telegraf.rb +2 -2
- data/app/models/zuora_connect/zuora_user.rb +1 -0
- data/app/views/zuora_connect/static/error_handled.html.erb +77 -0
- data/app/views/zuora_connect/static/error_unhandled.erb +82 -0
- data/app/views/zuora_connect/static/launch.html.erb +74 -75
- data/config/initializers/patches.rb +9 -0
- data/config/routes.rb +0 -2
- data/db/migrate/20190520232222_add_unique_index.rb +6 -0
- data/lib/middleware/json_parse_errors.rb +22 -0
- data/lib/middleware/request_id_middleware.rb +1 -1
- data/lib/resque/dynamic_queues.rb +5 -1
- data/lib/resque/plugins/custom_logger.rb +1 -1
- data/lib/zuora_connect.rb +59 -42
- data/lib/zuora_connect/configuration.rb +3 -3
- data/lib/zuora_connect/controllers/helpers.rb +253 -183
- data/lib/zuora_connect/engine.rb +2 -1
- data/lib/zuora_connect/railtie.rb +10 -6
- data/lib/zuora_connect/version.rb +1 -1
- metadata +52 -52
- data/app/views/zuora_connect/static/invalid_app_instance_error.html.erb +0 -65
- data/app/views/zuora_connect/static/invalid_launch_request.html.erb +0 -81
- data/app/views/zuora_connect/static/permission_error.html.erb +0 -80
- data/app/views/zuora_connect/static/session_error.html.erb +0 -63
- data/lib/zuora_connect/views/helpers.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e5ea622ca62754fdc938f16fe460f049338d685ed227e91e310d38b03baa31f
|
4
|
+
data.tar.gz: 174d5c0f676e86b6136f4336b4167492b64bca04360bf89445ac29c16f09ba76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d1f1428a5695933545d5f1c85cc91bd267abefb21b659ba58b4c2162e5422f8093f73abdbd23ab789cd4ac13abad393fd8a81cf28bfcbb4b7183100511acc1
|
7
|
+
data.tar.gz: 85d83effb0a5033b6a06dc1349ce725e69081bb1c5aca69936b99e9cdf547aa28fad0e33eafffd048e88a01a9878f787f79f51486d026208594b3fe1ca360ebe
|
@@ -1,25 +1,11 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class StaticController < ApplicationController
|
3
|
-
before_action :authenticate_connect_app_request, :except => [:metrics, :health, :
|
4
|
-
before_action :clear_connect_app_session, :only => [:metrics, :health, :
|
5
|
-
after_action :persist_connect_app_session, :except => [:metrics, :health, :
|
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]
|
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
|
-
|
23
9
|
def metrics
|
24
10
|
type = params[:type].present? ? params[:type] : "versions"
|
25
11
|
render json: ZuoraConnect::AppInstance.get_metrics(type).to_json, status: 200
|
@@ -48,6 +34,7 @@ module ZuoraConnect
|
|
48
34
|
def initialize_app
|
49
35
|
begin
|
50
36
|
authenticate_connect_app_request
|
37
|
+
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
51
38
|
render json: {
|
52
39
|
message: "Success",
|
53
40
|
status: 200
|
@@ -1,5 +1,15 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
module ApplicationHelper
|
3
|
+
def is_app_admin?
|
4
|
+
return @appinstance.blank? ? false : session["#{@appinstance.id}::admin"]
|
5
|
+
end
|
3
6
|
|
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
|
4
14
|
end
|
5
15
|
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', 'es', 'zh', 'de']
|
20
20
|
INTERNAL_HOSTS = []
|
21
21
|
LOGIN_TENANT_DESTINATION = 'target_login'
|
22
22
|
|
@@ -89,7 +89,11 @@ module ZuoraConnect
|
|
89
89
|
Thread.current[:appinstance] = self
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def default_ougai_items
|
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)
|
93
97
|
self.api_version = "v2"
|
94
98
|
self.username = username
|
95
99
|
self.password = password
|
@@ -123,26 +127,26 @@ module ZuoraConnect
|
|
123
127
|
|
124
128
|
if session.empty?
|
125
129
|
self.new_session_message = "REFRESHING - Session Empty"
|
126
|
-
ZuoraConnect.logger.
|
130
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
127
131
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
128
132
|
self.refresh(session: session)
|
129
133
|
|
130
134
|
elsif (self.id != session["appInstance"].to_i)
|
131
135
|
self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
|
132
|
-
ZuoraConnect.logger.
|
136
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
133
137
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
134
138
|
self.refresh(session: session)
|
135
139
|
|
136
140
|
elsif session["#{self.id}::task_data"].blank?
|
137
141
|
self.new_session_message = "REFRESHING - Task Data Blank"
|
138
|
-
ZuoraConnect.logger.
|
142
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
139
143
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
140
144
|
self.refresh(session: session)
|
141
145
|
|
142
146
|
elsif session["#{self.id}::last_refresh"].blank?
|
143
147
|
self.new_session_message = "REFRESHING - No Time on Cookie"
|
144
148
|
recoverable_session = true
|
145
|
-
ZuoraConnect.logger.
|
149
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
146
150
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
147
151
|
self.refresh(session: session)
|
148
152
|
|
@@ -150,7 +154,7 @@ module ZuoraConnect
|
|
150
154
|
elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
|
151
155
|
self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
|
152
156
|
recoverable_session = true
|
153
|
-
ZuoraConnect.logger.
|
157
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
154
158
|
self.refresh(session: session)
|
155
159
|
|
156
160
|
else
|
@@ -159,14 +163,14 @@ module ZuoraConnect
|
|
159
163
|
else
|
160
164
|
self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
|
161
165
|
end
|
162
|
-
ZuoraConnect.logger.
|
166
|
+
ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
|
163
167
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
164
168
|
end
|
165
169
|
end
|
166
170
|
return self
|
167
171
|
rescue ZuoraConnect::Exceptions::HoldingPattern => ex
|
168
172
|
while self.marked_for_refresh?
|
169
|
-
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
|
173
|
+
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'", self.default_ougai_items)
|
170
174
|
sleep(HOLDING_PATTERN_SLEEP)
|
171
175
|
end
|
172
176
|
self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
|
@@ -174,10 +178,11 @@ module ZuoraConnect
|
|
174
178
|
retry
|
175
179
|
rescue => ex
|
176
180
|
if recoverable_session
|
177
|
-
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache")
|
181
|
+
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex, self.default_ougai_items)
|
178
182
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
179
183
|
return self
|
180
184
|
else
|
185
|
+
ZuoraConnect.logger.error("Failed new session", ex, self.default_ougai_items)
|
181
186
|
raise
|
182
187
|
end
|
183
188
|
ensure
|
@@ -187,70 +192,108 @@ module ZuoraConnect
|
|
187
192
|
ZuoraConnect.logger.error(ex) if !IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
188
193
|
end
|
189
194
|
Time.zone = self.timezone
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
ElasticAPM
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
195
|
+
if self.task_data.present?
|
196
|
+
tenants = self.task_data.fetch('tenant_ids', [])
|
197
|
+
organizations = self.task_data.fetch('organizations', [])
|
198
|
+
if defined?(ElasticAPM) && ElasticAPM.running?
|
199
|
+
ElasticAPM.set_tag(:tenant_id, tenants.first)
|
200
|
+
ElasticAPM.set_tag(:organization, organizations.first)
|
201
|
+
end
|
202
|
+
self.logitem(item: {tenant_ids: tenants, organization: organizations})
|
203
|
+
|
204
|
+
params = {
|
205
|
+
:name => self.task_data.dig('name'),
|
206
|
+
:zuora_entity_ids => (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']},
|
207
|
+
:zuora_tenant_ids => tenants.map(&:to_s),
|
208
|
+
}
|
209
|
+
zuora_domain = self.send(LOGIN_TENANT_DESTINATION).client.rest_domain
|
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
|
205
215
|
end
|
206
216
|
|
207
217
|
def refresh(session: {}, session_fallback: false)
|
208
218
|
refresh_count ||= 0
|
209
219
|
#Check how app was deployed
|
210
|
-
if !self
|
220
|
+
if !self['zuora_logins'].present?
|
211
221
|
start = Time.now
|
212
222
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
213
223
|
response_time = Time.now - start
|
214
224
|
|
215
|
-
ZuoraConnect.logger.debug("
|
225
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}", self.default_ougai_items)
|
216
226
|
if response.code == 200
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
227
|
+
begin
|
228
|
+
parsed_json = JSON.parse(response.body)
|
229
|
+
rescue JSON::ParserError => ex
|
230
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
|
231
|
+
end
|
232
|
+
self.build_task(task_data: parsed_json, session: session)
|
221
233
|
else
|
222
234
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
223
235
|
end
|
224
236
|
else
|
225
|
-
self.build_task(task_data:
|
226
|
-
self.last_refresh = Time.now.to_i
|
227
|
-
self.cache_app_instance
|
228
|
-
self.reset_mark_for_refresh
|
237
|
+
self.build_task(task_data: self.zuora_logins, session: session)
|
229
238
|
end
|
230
|
-
|
239
|
+
self.last_refresh = Time.now.to_i
|
240
|
+
self.cache_app_instance
|
241
|
+
self.reset_mark_for_refresh
|
242
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
231
243
|
if (refresh_count += 1) < 3
|
232
|
-
|
244
|
+
sleep(30)
|
245
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
|
233
246
|
retry
|
234
247
|
else
|
235
|
-
ZuoraConnect.logger.fatal("
|
248
|
+
ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex, self.default_ougai_items)
|
236
249
|
raise
|
237
250
|
end
|
238
251
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
239
252
|
if (refresh_count += 1) < 3
|
253
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
|
240
254
|
if ex.code == 401
|
241
|
-
ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
242
255
|
self.refresh_oauth
|
243
|
-
else
|
244
|
-
ZuoraConnect.logger.warn("[#{self.id}] REFRESH TASK - Failed #{ex.code} - Retrying(#{refresh_count})")
|
245
256
|
end
|
246
257
|
retry
|
247
258
|
else
|
248
|
-
ZuoraConnect.logger.fatal("
|
259
|
+
ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex, self.default_ougai_items)
|
249
260
|
raise
|
250
261
|
end
|
251
262
|
end
|
252
263
|
|
253
|
-
#### START
|
264
|
+
#### START KMS ENCRYPTION Methods ####
|
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 ####
|
254
297
|
def logitem(item: {}, reset: false)
|
255
298
|
self.logitems = {} if self.logitems.class != Hash
|
256
299
|
if item.class == Hash
|
@@ -334,9 +377,9 @@ module ZuoraConnect
|
|
334
377
|
end
|
335
378
|
return @data
|
336
379
|
end
|
337
|
-
#### END Task
|
380
|
+
#### END Task Methods ####
|
338
381
|
|
339
|
-
#### START Task
|
382
|
+
#### START Task Methods ####
|
340
383
|
def build_task(task_data: {}, session: {})
|
341
384
|
session = {} if session.blank?
|
342
385
|
self.task_data = task_data
|
@@ -401,7 +444,7 @@ module ZuoraConnect
|
|
401
444
|
else
|
402
445
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
403
446
|
end
|
404
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
447
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
405
448
|
if (update_login_count += 1) < 3
|
406
449
|
retry
|
407
450
|
else
|
@@ -429,7 +472,7 @@ module ZuoraConnect
|
|
429
472
|
else
|
430
473
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
431
474
|
end
|
432
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
475
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
433
476
|
if (update_task_count += 1) < 3
|
434
477
|
retry
|
435
478
|
else
|
@@ -445,13 +488,13 @@ module ZuoraConnect
|
|
445
488
|
raise
|
446
489
|
end
|
447
490
|
end
|
448
|
-
#### END Task
|
491
|
+
#### END Task Methods ####
|
449
492
|
|
450
|
-
#### START Connect OAUTH
|
493
|
+
#### START Connect OAUTH Methods ####
|
451
494
|
def check_oauth_state(method)
|
452
495
|
#Refresh token if already expired
|
453
496
|
if self.oauth_expired?
|
454
|
-
ZuoraConnect.logger.debug("
|
497
|
+
ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired", self.default_ougai_items)
|
455
498
|
self.refresh_oauth
|
456
499
|
end
|
457
500
|
end
|
@@ -470,7 +513,7 @@ module ZuoraConnect
|
|
470
513
|
}
|
471
514
|
response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
|
472
515
|
response_time = Time.now - start
|
473
|
-
ZuoraConnect.logger.debug("
|
516
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}", self.default_ougai_items)
|
474
517
|
|
475
518
|
if response.code == 200
|
476
519
|
response_body = JSON.parse(response.body)
|
@@ -480,14 +523,15 @@ module ZuoraConnect
|
|
480
523
|
self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
|
481
524
|
self.save(:validate => false)
|
482
525
|
else
|
483
|
-
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token
|
526
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token", response.body, response.code)
|
484
527
|
end
|
485
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
528
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
486
529
|
if (refresh_oauth_count += 1) < 3
|
487
|
-
|
530
|
+
sleep(5)
|
531
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
|
488
532
|
retry
|
489
533
|
else
|
490
|
-
ZuoraConnect.logger.fatal("
|
534
|
+
ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex, self.default_ougai_items)
|
491
535
|
raise
|
492
536
|
end
|
493
537
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
@@ -498,14 +542,14 @@ module ZuoraConnect
|
|
498
542
|
return if !self.oauth_expired?
|
499
543
|
|
500
544
|
if (refresh_oauth_count += 1) < 3
|
501
|
-
ZuoraConnect.logger.
|
545
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
|
502
546
|
retry
|
503
547
|
else
|
504
|
-
ZuoraConnect.logger.fatal("
|
548
|
+
ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex, self.default_ougai_items)
|
505
549
|
raise
|
506
550
|
end
|
507
551
|
end
|
508
|
-
#### END Connect OAUTH
|
552
|
+
#### END Connect OAUTH Methods ####
|
509
553
|
|
510
554
|
#### START AppInstance Temporary Persistance Methods ####
|
511
555
|
def marked_for_refresh?
|
@@ -543,7 +587,7 @@ module ZuoraConnect
|
|
543
587
|
begin
|
544
588
|
redis_get_command ||= 0
|
545
589
|
cached_instance = Redis.current.get("AppInstance:#{self.id}")
|
546
|
-
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS
|
590
|
+
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
547
591
|
if (redis_get_command += 1) < 3
|
548
592
|
retry
|
549
593
|
else
|
@@ -551,10 +595,10 @@ module ZuoraConnect
|
|
551
595
|
end
|
552
596
|
end
|
553
597
|
if cached_instance.blank?
|
554
|
-
ZuoraConnect.logger.debug("
|
598
|
+
ZuoraConnect.logger.debug("Cached AppInstance Missing", self.default_ougai_items)
|
555
599
|
return session
|
556
600
|
else
|
557
|
-
ZuoraConnect.logger.debug("
|
601
|
+
ZuoraConnect.logger.debug("Cached AppInstance Found", self.default_ougai_items)
|
558
602
|
return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
|
559
603
|
end
|
560
604
|
else
|
@@ -566,7 +610,7 @@ module ZuoraConnect
|
|
566
610
|
if defined?(Redis.current)
|
567
611
|
#Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
|
568
612
|
if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
|
569
|
-
ZuoraConnect.logger.debug("
|
613
|
+
ZuoraConnect.logger.debug("Caching AppInstance", self.default_ougai_items)
|
570
614
|
Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
|
571
615
|
end
|
572
616
|
end
|
@@ -627,9 +671,10 @@ module ZuoraConnect
|
|
627
671
|
begin
|
628
672
|
return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
|
629
673
|
rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
|
630
|
-
ZuoraConnect.logger.
|
674
|
+
ZuoraConnect.logger.error("Error Decrypting", ex, self.default_ougai_items) if log_fatal
|
631
675
|
return rescue_return
|
632
676
|
rescue JSON::ParserError => ex
|
677
|
+
ZuoraConnect.logger.error("JSON Parse Error", ex, self.default_ougai_items) if log_fatal
|
633
678
|
return encryptor.decrypt_and_verify(CGI::unescape(data))
|
634
679
|
end
|
635
680
|
end
|
@@ -996,9 +1041,7 @@ module ZuoraConnect
|
|
996
1041
|
|
997
1042
|
def method_missing(method_sym, *arguments, &block)
|
998
1043
|
if method_sym.to_s.include?("login")
|
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}")
|
1044
|
+
ZuoraConnect.logger.fatal("Method Missing #{method_sym}. Instance Data: #{self.task_data} Instance Logins: #{self.logins}", self.default_ougai_items)
|
1002
1045
|
end
|
1003
1046
|
super
|
1004
1047
|
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}")) if Rails.env.to_s != 'production'
|
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}")) if Rails.env.to_s != 'production'
|
60
60
|
end
|
61
61
|
|
62
62
|
def format_metric_log(message, dump = nil)
|