zuora_connect 2.0.57zc → 2.0.57
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/assets/javascripts/hallway_wrapper/after.js +3 -22
- data/app/controllers/zuora_connect/static_controller.rb +10 -35
- data/app/models/zuora_connect/app_instance_base.rb +34 -49
- data/app/views/zuora_connect/static/launch.html.erb +11 -8
- data/config/routes.rb +0 -4
- data/lib/resque/plugins/app_instance_job.rb +3 -7
- data/lib/zuora_connect.rb +0 -2
- data/lib/zuora_connect/configuration.rb +2 -3
- data/lib/zuora_connect/controllers/helpers.rb +130 -258
- data/lib/zuora_connect/engine.rb +3 -6
- data/lib/zuora_connect/railtie.rb +1 -2
- data/lib/zuora_connect/version.rb +1 -1
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae04188bc84b9fd594f1a2453128a9f7f8d489e9edd9ffd053ef51c09c32b02d
|
4
|
+
data.tar.gz: 3f19d9ed178c02807f44dbed319f5d2c5b47301de9bdc6666ce5df320cc8c40c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1249ce65d708fe4bd792c890b49946ce1dea1c1ffba97a98ef397d98e69014e5f24021b700f0b2c980c2ce2292b601fbbb9550110f7e66b4099908ee0467ac
|
7
|
+
data.tar.gz: d40bdadd5ccbe7e2416f3ab354830f05aadec4c1c5faea71dccf8a87f1df0e012bfe4a49f1ed7f0a6e29c97ac4e3c04d8548ba48094f81d01f30c55c4484753b
|
@@ -4,31 +4,12 @@ window.define = previousDefine;
|
|
4
4
|
if (isHallway()) {
|
5
5
|
$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
|
6
6
|
if ( jqxhr.status === 401) {
|
7
|
-
|
8
|
-
if (response.status === 401) {
|
9
|
-
deleteAllCookies();
|
10
|
-
window.location.href = '/apps/newlogin.do?retURL=' + window.location.pathname;
|
11
|
-
}
|
12
|
-
});
|
7
|
+
window.location.href = '/apps/newlogin.do?retURL=' + window.location.pathname;
|
13
8
|
}
|
14
9
|
});
|
15
10
|
}
|
16
11
|
|
17
12
|
function isHallway() {
|
18
|
-
var regex = new RegExp("
|
19
|
-
|
20
|
-
return window.location.pathname.match(regex)[0]
|
21
|
-
}
|
22
|
-
return null;
|
23
|
-
}
|
24
|
-
|
25
|
-
function deleteAllCookies() {
|
26
|
-
var cookies = document.cookie.split(";");
|
27
|
-
|
28
|
-
for (var i = 0; i < cookies.length; i++) {
|
29
|
-
var cookie = cookies[i];
|
30
|
-
var eqPos = cookie.indexOf("=");
|
31
|
-
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
|
32
|
-
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
|
33
|
-
}
|
13
|
+
var regex = new RegExp("^/services/");
|
14
|
+
return window.location.pathname.match(regex);
|
34
15
|
}
|
@@ -1,11 +1,10 @@
|
|
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
|
6
|
-
|
7
|
-
skip_before_action :verify_authenticity_token, :only => [:initialize_app
|
8
|
-
http_basic_authenticate_with name: ENV['PROVISION_USER'], password: ENV['PROVISION_SECRET'], :only => [:provision]
|
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
|
+
|
7
|
+
skip_before_action :verify_authenticity_token, :only => [:initialize_app]
|
9
8
|
|
10
9
|
def metrics
|
11
10
|
type = params[:type].present? ? params[:type] : "versions"
|
@@ -35,13 +34,11 @@ module ZuoraConnect
|
|
35
34
|
def initialize_app
|
36
35
|
begin
|
37
36
|
authenticate_connect_app_request
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
}, status: 200
|
44
|
-
end
|
37
|
+
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
38
|
+
render json: {
|
39
|
+
message: "Success",
|
40
|
+
status: 200
|
41
|
+
}, status: 200
|
45
42
|
rescue => ex
|
46
43
|
Rails.logger.error("Failed to Initialize application", ex)
|
47
44
|
if performed?
|
@@ -55,28 +52,6 @@ module ZuoraConnect
|
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
|
-
def provision
|
59
|
-
create_new_instance
|
60
|
-
unless performed?
|
61
|
-
render json: {
|
62
|
-
status: 200,
|
63
|
-
message: 'Success',
|
64
|
-
app_instance_id: @appinstance.id
|
65
|
-
}, status: 200
|
66
|
-
end
|
67
|
-
rescue StandardError => e
|
68
|
-
message = 'Failed to provision new instance'
|
69
|
-
if performed?
|
70
|
-
Rails.logger.error("#{message}: #{performed?}", e)
|
71
|
-
else
|
72
|
-
Rails.logger.error(message, e)
|
73
|
-
render json: {
|
74
|
-
status: 500,
|
75
|
-
message: message
|
76
|
-
}, status: 500
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
55
|
private
|
81
56
|
|
82
57
|
def clear_connect_app_session
|
@@ -20,7 +20,7 @@ module ZuoraConnect
|
|
20
20
|
BLANK_OBJECT_ID_LOOKUP = 'BlankValueSupplied'
|
21
21
|
HOLDING_PATTERN_SLEEP = 5.seconds
|
22
22
|
CONNECT_APPLICATION_ID = 0
|
23
|
-
CONNECT_COMMUNICATION_SLEEP
|
23
|
+
CONNECT_COMMUNICATION_SLEEP= 5.seconds
|
24
24
|
IGNORED_LOCALS = ['fr', 'ja', 'es', 'zh', 'de']
|
25
25
|
INTERNAL_HOSTS = []
|
26
26
|
LOGIN_TENANT_DESTINATION = 'target_login'
|
@@ -98,9 +98,7 @@ module ZuoraConnect
|
|
98
98
|
Redis.current.zrem("InstanceRefreshing", self.id)
|
99
99
|
end
|
100
100
|
if defined?(Resque.redis)
|
101
|
-
Resque.redis.
|
102
|
-
Resque.redis.zrem("PauseQueue", key) if key.split("__").first.to_i == self.id
|
103
|
-
end
|
101
|
+
Resque.redis.zrem("PauseQueue", self.id)
|
104
102
|
end
|
105
103
|
return true
|
106
104
|
end
|
@@ -163,7 +161,6 @@ module ZuoraConnect
|
|
163
161
|
end
|
164
162
|
|
165
163
|
self.build_task(task_data: mock_task_data, session: session)
|
166
|
-
self.last_refresh = Time.now.to_i
|
167
164
|
else
|
168
165
|
time_expire = (session["#{self.id}::last_refresh"] || Time.now).to_i - INSTANCE_REFRESH_WINDOW.ago.to_i
|
169
166
|
|
@@ -205,14 +202,14 @@ module ZuoraConnect
|
|
205
202
|
else
|
206
203
|
self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
|
207
204
|
end
|
208
|
-
ZuoraConnect.logger.debug(self.new_session_message
|
205
|
+
ZuoraConnect.logger.debug(self.new_session_message)
|
209
206
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
210
207
|
end
|
211
208
|
end
|
212
209
|
return self
|
213
210
|
rescue ZuoraConnect::Exceptions::HoldingPattern => ex
|
214
211
|
while self.marked_for_refresh?
|
215
|
-
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'"
|
212
|
+
ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
|
216
213
|
sleep(HOLDING_PATTERN_SLEEP)
|
217
214
|
end
|
218
215
|
self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
|
@@ -221,17 +218,17 @@ module ZuoraConnect
|
|
221
218
|
rescue ZuoraConnect::Exceptions::MissMatch => ex
|
222
219
|
self.delete_app_instance
|
223
220
|
session = {}
|
224
|
-
ZuoraConnect.logger.error(ex,
|
221
|
+
ZuoraConnect.logger.error(ex, app_instance_id_new: self.task_data['id'])
|
225
222
|
retry
|
226
223
|
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
227
224
|
raise
|
228
225
|
rescue => ex
|
229
226
|
if recoverable_session
|
230
|
-
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex
|
227
|
+
ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex)
|
231
228
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
232
229
|
return self
|
233
230
|
else
|
234
|
-
ZuoraConnect.logger.error("Failed new session", ex
|
231
|
+
ZuoraConnect.logger.error("Failed new session", ex)
|
235
232
|
raise
|
236
233
|
end
|
237
234
|
ensure
|
@@ -279,8 +276,11 @@ module ZuoraConnect
|
|
279
276
|
#Check how app was deployed
|
280
277
|
if self.id < 25000000 && !skip_connect
|
281
278
|
self.check_oauth_state
|
279
|
+
start = Time.now
|
282
280
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
281
|
+
response_time = Time.now - start
|
283
282
|
|
283
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
|
284
284
|
if response.code == 200
|
285
285
|
begin
|
286
286
|
parsed_json = JSON.parse(response.body)
|
@@ -312,7 +312,7 @@ module ZuoraConnect
|
|
312
312
|
refresh_count += 1
|
313
313
|
if refresh_count < 3
|
314
314
|
sleep(10)
|
315
|
-
ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex
|
315
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex)
|
316
316
|
retry
|
317
317
|
else
|
318
318
|
ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex)
|
@@ -321,17 +321,17 @@ module ZuoraConnect
|
|
321
321
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
322
322
|
refresh_count += 1
|
323
323
|
if refresh_count < 3
|
324
|
-
ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex
|
324
|
+
ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex)
|
325
325
|
self.refresh_oauth if ex.code == 401
|
326
326
|
retry
|
327
327
|
else
|
328
|
-
ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex
|
328
|
+
ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex)
|
329
329
|
raise
|
330
330
|
end
|
331
331
|
end
|
332
332
|
rescue => ex
|
333
333
|
if self['zuora_logins'].present?
|
334
|
-
ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex
|
334
|
+
ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex)
|
335
335
|
skip_connect = true
|
336
336
|
retry
|
337
337
|
end
|
@@ -653,12 +653,16 @@ module ZuoraConnect
|
|
653
653
|
end
|
654
654
|
|
655
655
|
def refresh_oauth
|
656
|
-
refresh_oauth_count ||= 0
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
656
|
+
refresh_oauth_count ||= 0
|
657
|
+
start = Time.now
|
658
|
+
params = {
|
659
|
+
:grant_type => "refresh_token",
|
660
|
+
:redirect_uri => ZuoraConnect.configuration.oauth_client_redirect_uri,
|
661
|
+
:refresh_token => self.refresh_token
|
662
|
+
}
|
663
|
+
response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
|
664
|
+
response_time = Time.now - start
|
665
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}")
|
662
666
|
|
663
667
|
if response.code == 200
|
664
668
|
response_body = JSON.parse(response.body)
|
@@ -672,11 +676,11 @@ module ZuoraConnect
|
|
672
676
|
end
|
673
677
|
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
674
678
|
if (refresh_oauth_count += 1) < 3
|
675
|
-
sleep(
|
676
|
-
ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex
|
679
|
+
sleep(5)
|
680
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex)
|
677
681
|
retry
|
678
682
|
else
|
679
|
-
|
683
|
+
ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex)
|
680
684
|
raise
|
681
685
|
end
|
682
686
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
@@ -687,10 +691,10 @@ module ZuoraConnect
|
|
687
691
|
return if !self.oauth_expired?
|
688
692
|
|
689
693
|
if (refresh_oauth_count += 1) < 3
|
690
|
-
ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex
|
694
|
+
ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex)
|
691
695
|
retry
|
692
696
|
else
|
693
|
-
ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex
|
697
|
+
ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex)
|
694
698
|
raise
|
695
699
|
end
|
696
700
|
end
|
@@ -740,10 +744,10 @@ module ZuoraConnect
|
|
740
744
|
end
|
741
745
|
end
|
742
746
|
if cached_instance.blank?
|
743
|
-
ZuoraConnect.logger.debug("Cached AppInstance Missing"
|
747
|
+
ZuoraConnect.logger.debug("Cached AppInstance Missing")
|
744
748
|
return session
|
745
749
|
else
|
746
|
-
ZuoraConnect.logger.debug("Cached AppInstance Found"
|
750
|
+
ZuoraConnect.logger.debug("Cached AppInstance Found")
|
747
751
|
return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
|
748
752
|
end
|
749
753
|
else
|
@@ -759,7 +763,7 @@ module ZuoraConnect
|
|
759
763
|
if defined?(Redis.current)
|
760
764
|
#Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
|
761
765
|
if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
|
762
|
-
ZuoraConnect.logger.debug("Caching AppInstance"
|
766
|
+
ZuoraConnect.logger.debug("Caching AppInstance")
|
763
767
|
Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
|
764
768
|
end
|
765
769
|
end
|
@@ -823,10 +827,10 @@ module ZuoraConnect
|
|
823
827
|
begin
|
824
828
|
return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
|
825
829
|
rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
|
826
|
-
ZuoraConnect.logger.error("Error Decrypting", ex
|
830
|
+
ZuoraConnect.logger.error("Error Decrypting", ex) if log_fatal
|
827
831
|
return rescue_return
|
828
832
|
rescue JSON::ParserError => ex
|
829
|
-
ZuoraConnect.logger.error("JSON Parse Error", ex
|
833
|
+
ZuoraConnect.logger.error("JSON Parse Error", ex) if log_fatal
|
830
834
|
return encryptor.decrypt_and_verify(CGI::unescape(data))
|
831
835
|
end
|
832
836
|
end
|
@@ -1123,15 +1127,6 @@ module ZuoraConnect
|
|
1123
1127
|
# Data from each schema will be loaded into table(aggregate_name) into the public schema
|
1124
1128
|
def self.refresh_aggregate_table(aggregate_name: 'all_tasks_processing', table_name: 'tasks', where_clause: "where status in ('Processing', 'Queued')", index_table: true, ignore_indexes: [])
|
1125
1129
|
self.update_functions
|
1126
|
-
|
1127
|
-
sql_result = ActiveRecord::Base.connection.execute <<-eos
|
1128
|
-
SELECT pid, relname, mode
|
1129
|
-
FROM pg_locks l
|
1130
|
-
JOIN pg_class t ON l.relation = t.oid AND t.relkind = 'r'
|
1131
|
-
WHERE t.relname = '#{aggregate_name}' AND l.mode ='AccessExclusiveLock';
|
1132
|
-
eos
|
1133
|
-
raise ZuoraConnect::Exceptions::Error.new("An existing lock detected while dropping table '#{aggregate_name}'") if sql_result.count > 0
|
1134
|
-
|
1135
1130
|
if index_table
|
1136
1131
|
ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'Index\', \'{%s}\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause), ignore_indexes.map { |index| "\"#{index}\"" }.join(',')])
|
1137
1132
|
else
|
@@ -1219,16 +1214,6 @@ module ZuoraConnect
|
|
1219
1214
|
end
|
1220
1215
|
end
|
1221
1216
|
|
1222
|
-
def self.without_sticking
|
1223
|
-
if self.connection.respond_to?(:without_sticking)
|
1224
|
-
self.connection.without_sticking do
|
1225
|
-
yield
|
1226
|
-
end
|
1227
|
-
else
|
1228
|
-
yield
|
1229
|
-
end
|
1230
|
-
end
|
1231
|
-
|
1232
1217
|
method_hook :updateOption, :update_logins, :before => :check_oauth_state
|
1233
1218
|
method_hook :new_session, :refresh, :build_task, :after => :apartment_switch
|
1234
1219
|
end
|
@@ -3,7 +3,12 @@
|
|
3
3
|
<title>Select Task ID</title>
|
4
4
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
5
5
|
<style>
|
6
|
-
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
margin: 0;
|
9
|
+
}
|
10
|
+
|
11
|
+
div.connect-dialog {
|
7
12
|
width: 95%;
|
8
13
|
max-width: 33em;
|
9
14
|
margin: 4em auto 0;
|
@@ -11,11 +16,7 @@
|
|
11
16
|
text-align: center;
|
12
17
|
}
|
13
18
|
|
14
|
-
.connect-dialog div {
|
15
|
-
background-color: white;
|
16
|
-
color: #2E2F30;
|
17
|
-
text-align: center;
|
18
|
-
font-family: arial, sans-serif;
|
19
|
+
div.connect-dialog > div {
|
19
20
|
margin: 0 0 1em;
|
20
21
|
border: 1px solid #CCC;
|
21
22
|
border-right-color: #999;
|
@@ -26,17 +27,19 @@
|
|
26
27
|
border-top-right-radius: 9px;
|
27
28
|
border-bottom-left-radius: 9px;
|
28
29
|
border-bottom-right-radius: 9px;
|
30
|
+
background-color: white;
|
29
31
|
padding: 7px 12% 0;
|
30
32
|
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
31
33
|
}
|
32
34
|
|
33
|
-
.connect-dialog h1 {
|
35
|
+
div.connect-dialog > h1 {
|
34
36
|
font-size: 100%;
|
35
37
|
color: #3D4B5A;
|
36
38
|
line-height: 1.5em;
|
37
39
|
}
|
38
40
|
|
39
|
-
|
41
|
+
|
42
|
+
div.connect-dialog > div.launch_button {
|
40
43
|
margin: 1em 0 1em;
|
41
44
|
margin-right: auto;
|
42
45
|
margin-left: auto;
|
data/config/routes.rb
CHANGED
@@ -3,10 +3,6 @@ ZuoraConnect::Engine.routes.draw do
|
|
3
3
|
get '/internal/data' => 'static#metrics'
|
4
4
|
post '/initialize_app' => 'static#initialize_app'
|
5
5
|
|
6
|
-
if ENV['PROVISION_USER'].present? && ENV['PROVISION_SECRET'].present?
|
7
|
-
post '/provision' => 'static#provision'
|
8
|
-
end
|
9
|
-
|
10
6
|
namespace :api do
|
11
7
|
namespace :v1 do
|
12
8
|
resources :app_instance, :only => [:index], defaults: {format: :json} do
|
@@ -24,13 +24,9 @@ module Resque
|
|
24
24
|
@appinstance.new_session(holding_pattern: true)
|
25
25
|
rescue ActiveRecord::RecordNotFound => exception
|
26
26
|
# If we can't find app_instance let make sure we cleanup
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return
|
31
|
-
else
|
32
|
-
raise
|
33
|
-
end
|
27
|
+
Rails.logger.info("No instance found, purge")
|
28
|
+
ZuoraConnect::AppInstance.new(id: args['app_instance_id'].to_i).prune_data
|
29
|
+
return
|
34
30
|
rescue ActiveRecord::StatementInvalid => exception
|
35
31
|
if (connection_count += 1) <= 3 &&
|
36
32
|
(
|
data/lib/zuora_connect.rb
CHANGED
@@ -7,7 +7,7 @@ module ZuoraConnect
|
|
7
7
|
|
8
8
|
attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri
|
9
9
|
|
10
|
-
attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :json_logging
|
10
|
+
attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :json_logging
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@default_locale = :en
|
@@ -19,7 +19,6 @@ module ZuoraConnect
|
|
19
19
|
@additional_apartment_models = []
|
20
20
|
@silencer_resque_finish = true
|
21
21
|
@blpop_queue = false
|
22
|
-
@insert_migrations = true
|
23
22
|
|
24
23
|
# Setting the app name for telegraf write
|
25
24
|
@enable_metrics = false
|
@@ -43,7 +42,7 @@ module ZuoraConnect
|
|
43
42
|
@aws_region = "us-west-2"
|
44
43
|
@s3_bucket_name = "rbm-apps"
|
45
44
|
@s3_folder_name = Rails.application.class.parent_name
|
46
|
-
@json_logging = Rails.env.
|
45
|
+
@json_logging = Rails.env.to_s == 'development' ? false : true
|
47
46
|
end
|
48
47
|
|
49
48
|
def private_key
|
@@ -19,6 +19,7 @@ module ZuoraConnect
|
|
19
19
|
ElasticAPM.set_label(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
|
20
20
|
end
|
21
21
|
end
|
22
|
+
start_time = Time.now
|
22
23
|
if request.headers["API-Token"].present?
|
23
24
|
@appinstance = ZuoraConnect::AppInstance.find_by(:api_token => request.headers["API-Token"])
|
24
25
|
ZuoraConnect.logger.debug("API REQUEST - API token") if @appinstance.present?
|
@@ -47,7 +48,7 @@ module ZuoraConnect
|
|
47
48
|
render json: {"status": 401, "message": "Missing mapping or no deployment for '#{zuora_host}-#{zuora_entity_id}' ."}, status: :unauthorized
|
48
49
|
return
|
49
50
|
elsif appinstances.size > 1
|
50
|
-
render json: {"status": 401, "message": "More than one app instance binded to host and entity ids. Please indicate correct instance via 'zuora-instance-id' header"
|
51
|
+
render json: {"status": 401, "message": "More than one app instance binded to host and entity ids. Please indicate correct instance via 'zuora-instance-id' header"}, status: :unauthorized
|
51
52
|
return
|
52
53
|
else
|
53
54
|
@appinstance = appinstances.first
|
@@ -64,6 +65,10 @@ module ZuoraConnect
|
|
64
65
|
else
|
65
66
|
check_instance
|
66
67
|
end
|
68
|
+
|
69
|
+
if @appinstance.present?
|
70
|
+
ZuoraConnect.logger.debug("Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
|
71
|
+
end
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
@@ -96,6 +101,7 @@ module ZuoraConnect
|
|
96
101
|
ElasticAPM.set_label(:trace_id, request.uuid)
|
97
102
|
end
|
98
103
|
end
|
104
|
+
start_time = Time.now
|
99
105
|
|
100
106
|
if ZuoraConnect.configuration.mode == "Production"
|
101
107
|
setup_instance_via_prod_mode
|
@@ -135,30 +141,32 @@ module ZuoraConnect
|
|
135
141
|
rescue
|
136
142
|
ZuoraConnect.logger.error(ex)
|
137
143
|
end
|
144
|
+
|
145
|
+
ZuoraConnect.logger.debug("Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
|
138
146
|
end
|
139
147
|
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
140
148
|
id = @appinstance.id
|
141
149
|
ZuoraConnect::AppInstance.destroy(id)
|
142
150
|
Apartment::Tenant.drop(id)
|
143
151
|
render "zuora_connect/static/error_handled", :locals => {
|
144
|
-
:title => "Application Setup Error",
|
152
|
+
:title => "Application Setup Error",
|
145
153
|
:message => "Application cannot be run using Zuora Session. Delete old application \
|
146
154
|
deployment and create new with Zuora Basic or OAuth credentials."
|
147
155
|
}, :layout => false
|
148
|
-
return
|
156
|
+
return
|
149
157
|
rescue ZuoraConnect::Exceptions::AccessDenied => ex
|
150
158
|
respond_to do |format|
|
151
|
-
format.html {
|
159
|
+
format.html {
|
152
160
|
render "zuora_connect/static/error_handled", :locals => {
|
153
|
-
:title => "Application State Error",
|
161
|
+
:title => "Application State Error",
|
154
162
|
:message => ex.message
|
155
|
-
}, status: 401, layout: false
|
163
|
+
}, status: 401, layout: false
|
156
164
|
}
|
157
|
-
format.js {
|
165
|
+
format.js {
|
158
166
|
render "zuora_connect/static/error_handled", :locals => {
|
159
|
-
:title => "Application State Error",
|
167
|
+
:title => "Application State Error",
|
160
168
|
:message => ex.message
|
161
|
-
}, status: 401, layout: false
|
169
|
+
}, status: 401, layout: false
|
162
170
|
}
|
163
171
|
format.json { render json: {'errors' => ex.message}, status: 401 }
|
164
172
|
format.all { render json: ex.message, status: 401 }
|
@@ -188,17 +196,17 @@ module ZuoraConnect
|
|
188
196
|
raise ZuoraConnect::Exceptions::AccessDenied.new("User is not an authorized admin for this application") if raise_error
|
189
197
|
|
190
198
|
respond_to do |format|
|
191
|
-
format.html {
|
199
|
+
format.html {
|
192
200
|
render "zuora_connect/static/error_handled", :locals => {
|
193
|
-
:title => "Unauthorized",
|
201
|
+
:title => "Unauthorized",
|
194
202
|
:message => "User is not an authorized admin for this application"
|
195
203
|
}, status: 401, :layout => false
|
196
204
|
}
|
197
|
-
format.js {
|
205
|
+
format.js {
|
198
206
|
render "zuora_connect/static/error_handled", :locals => {
|
199
|
-
:title => "Unauthorized",
|
207
|
+
:title => "Unauthorized",
|
200
208
|
:message => "User is not an authorized admin for this application"
|
201
|
-
}, status: 401, :layout => false
|
209
|
+
}, status: 401, :layout => false
|
202
210
|
}
|
203
211
|
format.json { render json: {'errors' => ex.message}, status: 401 }
|
204
212
|
format.all { render json: ex.message, status: 401 }
|
@@ -219,80 +227,6 @@ module ZuoraConnect
|
|
219
227
|
return (request.headers['ZuoraCurrentEntity'].present? || cookies['ZuoraCurrentEntity'].present?)
|
220
228
|
end
|
221
229
|
|
222
|
-
def create_new_instance
|
223
|
-
ZuoraConnect::AppInstance.read_master_db do
|
224
|
-
Thread.current[:appinstance] = nil
|
225
|
-
ZuoraConnect.logger.with_fields = {} if ZuoraConnect.logger.is_a?(Ougai::Logger)
|
226
|
-
Rails.logger.with_fields = {} if Rails.logger.is_a?(Ougai::Logger)
|
227
|
-
|
228
|
-
if defined?(ElasticAPM) && ElasticAPM.running? && ElasticAPM.respond_to?(:set_label)
|
229
|
-
ElasticAPM.set_label(:trace_id, request.uuid)
|
230
|
-
end
|
231
|
-
|
232
|
-
zuora_host = request.headers['zuora-host']
|
233
|
-
zuora_entity_id = (request.headers['zuora-entity-ids'] || '').gsub(
|
234
|
-
'-',
|
235
|
-
''
|
236
|
-
).split(',').first
|
237
|
-
|
238
|
-
# Validate host present
|
239
|
-
if zuora_host.blank?
|
240
|
-
render json: {
|
241
|
-
status: 401,
|
242
|
-
message: 'zuora-host header was not supplied.'
|
243
|
-
}, status: :unauthorized
|
244
|
-
return
|
245
|
-
end
|
246
|
-
|
247
|
-
# Validate entity-ids present
|
248
|
-
if zuora_entity_id.blank?
|
249
|
-
render json: {
|
250
|
-
status: 401,
|
251
|
-
message: 'zuora-entity-ids header was not supplied.'
|
252
|
-
}, status: :unauthorized
|
253
|
-
return
|
254
|
-
end
|
255
|
-
|
256
|
-
rest_domain = ZuoraAPI::Login.new(url: "https://#{zuora_host}").rest_domain
|
257
|
-
app_instance_id = ZuoraConnect::AppInstance.where(
|
258
|
-
'zuora_entity_ids ?& array[:entities] AND zuora_domain = :host',
|
259
|
-
entities: [zuora_entity_id],
|
260
|
-
host: rest_domain
|
261
|
-
).pluck(:id).first
|
262
|
-
|
263
|
-
if app_instance_id.present?
|
264
|
-
render json: {
|
265
|
-
status: 409,
|
266
|
-
message: 'Instance already exists.',
|
267
|
-
app_instance_id: app_instance_id
|
268
|
-
}, status: 409
|
269
|
-
else
|
270
|
-
Apartment::Tenant.switch!("public")
|
271
|
-
retry_count = 3
|
272
|
-
begin
|
273
|
-
@appinstance = new_instance(
|
274
|
-
next_instance_id,
|
275
|
-
zuora_entity_id,
|
276
|
-
rest_domain,
|
277
|
-
retry_count: retry_count
|
278
|
-
)
|
279
|
-
rescue ActiveRecord::RecordNotUnique
|
280
|
-
retry if (retry_count -= 1).positive?
|
281
|
-
return
|
282
|
-
end
|
283
|
-
|
284
|
-
app_instance_id = @appinstance.id
|
285
|
-
end
|
286
|
-
|
287
|
-
begin
|
288
|
-
Apartment::Tenant.switch!('public')
|
289
|
-
Apartment::Tenant.create(app_instance_id.to_s)
|
290
|
-
rescue Apartment::TenantExists
|
291
|
-
ZuoraConnect.logger.debug('Tenant Already Exists')
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
230
|
private
|
297
231
|
def setup_instance_via_prod_mode
|
298
232
|
zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
|
@@ -300,7 +234,7 @@ module ZuoraConnect
|
|
300
234
|
if zuora_entity_id.present?
|
301
235
|
zuora_tenant_id = cookies['Zuora-Tenant-Id']
|
302
236
|
zuora_user_id = cookies['Zuora-User-Id']
|
303
|
-
zuora_host = request.headers[
|
237
|
+
zuora_host = request.headers["HTTP_X_FORWARDED_HOST"] || "apisandbox.zuora.com"
|
304
238
|
|
305
239
|
zuora_details = {'host' => zuora_host, 'user_id' => zuora_user_id, 'tenant_id' => zuora_tenant_id, 'entity_id' => zuora_entity_id}
|
306
240
|
auth_headers = {}
|
@@ -312,7 +246,7 @@ module ZuoraConnect
|
|
312
246
|
auth_headers.merge!({'Authorization' => "ZSession-a3N2w #{zuora_client.get_session(prefix: false, auth_type: :basic)}"})
|
313
247
|
else
|
314
248
|
render "zuora_connect/static/error_handled", :locals => {
|
315
|
-
:title => "Missing Authorization Token",
|
249
|
+
:title => "Missing Authorization Token",
|
316
250
|
:message => "Zuora 'Zuora-Auth-Token' header and 'ZSession' cookie not present."
|
317
251
|
}, :layout => false
|
318
252
|
return
|
@@ -334,34 +268,27 @@ module ZuoraConnect
|
|
334
268
|
if zuora_tenant_id.to_s == "10548"
|
335
269
|
session.clear
|
336
270
|
render "zuora_connect/static/error_handled", :locals => {
|
337
|
-
:title => "Security Testing",
|
271
|
+
:title => "Security Testing",
|
338
272
|
:message => "Ya we know it you"
|
339
273
|
}, :layout => false
|
340
274
|
return
|
341
275
|
else
|
342
|
-
raise ZuoraConnect::Exceptions::Error.new("Header entity id does not match identity call entity id.")
|
276
|
+
raise ZuoraConnect::Exceptions::Error.new("Header entity id does not match identity call entity id.")
|
343
277
|
end
|
344
278
|
end
|
345
279
|
|
346
|
-
##
|
347
|
-
# If the ZSession was refreshed, but it's still the same user and they aren't launching from the side bar,
|
348
|
-
# we don't need to continue
|
349
|
-
is_different_user = identity.slice("entityId", "tenantId", "userId", "userProfileId") == (session["ZuoraCurrentIdentity"] || {}).slice("entityId", "tenantId", "userId", "userProfileId")
|
350
|
-
zuora_details["identity"]["entityId"] = identity['entityId']
|
351
280
|
session["ZuoraCurrentIdentity"] = identity
|
352
281
|
session["ZuoraCurrentEntity"] = identity['entityId']
|
353
282
|
session["ZSession"] = cookies['ZSession']
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
session["ZuoraCurrentUserInfo"] = client_describe
|
364
|
-
end
|
283
|
+
zuora_instance_id = nil
|
284
|
+
zuora_details["identity"]["entityId"] = identity['entityId']
|
285
|
+
|
286
|
+
client_describe, response = zuora_client.rest_call(
|
287
|
+
url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''),
|
288
|
+
session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic,
|
289
|
+
headers: auth_headers
|
290
|
+
)
|
291
|
+
session["ZuoraCurrentUserInfo"] = client_describe
|
365
292
|
end
|
366
293
|
|
367
294
|
#Find matching app instances.
|
@@ -369,7 +296,7 @@ module ZuoraConnect
|
|
369
296
|
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_client.rest_domain, id: zuora_instance_id.to_i).pluck(:id, :name)
|
370
297
|
else
|
371
298
|
#if app_instance_ids is present then permissions still controlled by connect
|
372
|
-
if params[:app_instance_ids].present?
|
299
|
+
if params[:app_instance_ids].present?
|
373
300
|
navbar, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("navigation"))
|
374
301
|
urls = navbar['menus'].map {|x| x['url']}
|
375
302
|
app_env = ENV["DEIS_APP"] || "xyz123"
|
@@ -377,39 +304,33 @@ module ZuoraConnect
|
|
377
304
|
if url.blank?
|
378
305
|
if navbar['menus'].map {|x| x['label']}.include?('Link Connect Account')
|
379
306
|
render "zuora_connect/static/error_handled", :locals => {
|
380
|
-
:title => "Link Account",
|
307
|
+
:title => "Link Account",
|
381
308
|
:message => "Link Connect account to gain access to application."
|
382
309
|
}, :layout => false
|
383
310
|
return
|
384
311
|
end
|
385
|
-
|
312
|
+
ZuoraConnect::Exceptions::APIError.new(message: "#{app_env} navbar url was blank", response: response)
|
386
313
|
else
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
task_ids = JSON.parse(Base64.urlsafe_decode64(app_instance_ids))
|
392
|
-
|
393
|
-
appinstances = ZuoraConnect::AppInstance.where(:id => task_ids).pluck(:id, :name)
|
394
|
-
rescue => ex
|
395
|
-
raise ZuoraConnect::Exceptions::APIError.new(message: "Failure in parsing the navbar urls.", response: response)
|
396
|
-
end
|
314
|
+
begin
|
315
|
+
task_ids = JSON.parse(Base64.urlsafe_decode64(CGI.parse(URI.parse(url).query)["app_instance_ids"][0]))
|
316
|
+
rescue => ex
|
317
|
+
raise ZuoraConnect::Exceptions::APIError.new(message: "Failure in parsing the navbar urls.", response: response)
|
397
318
|
end
|
398
319
|
end
|
320
|
+
appinstances = ZuoraConnect::AppInstance.where(:id => task_ids).pluck(:id, :name)
|
321
|
+
else
|
322
|
+
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
|
399
323
|
end
|
400
|
-
appinstances ||= ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
|
401
324
|
end
|
402
325
|
|
403
326
|
zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId']
|
404
327
|
|
328
|
+
#One deployed instance
|
405
329
|
if appinstances.size == 1
|
406
330
|
ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
|
407
331
|
@appinstance = ZuoraConnect::AppInstance.find(appinstances.to_h.keys.first)
|
408
|
-
end
|
409
332
|
|
410
|
-
|
411
|
-
if defined?(@appinstance) && @appinstance['zuora_logins'].present?
|
412
|
-
#Add user/update
|
333
|
+
#Add user/update
|
413
334
|
begin
|
414
335
|
@zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
|
415
336
|
rescue ActiveRecord::StatementInvalid => ex
|
@@ -429,7 +350,7 @@ module ZuoraConnect
|
|
429
350
|
else
|
430
351
|
ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
|
431
352
|
@zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
|
432
|
-
end
|
353
|
+
end
|
433
354
|
@zuora_user.session = session
|
434
355
|
session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
|
435
356
|
session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
|
@@ -438,103 +359,97 @@ module ZuoraConnect
|
|
438
359
|
session["appInstance"] = @appinstance.id
|
439
360
|
|
440
361
|
#We have multiple, user must pick
|
441
|
-
elsif appinstances.size > 1
|
362
|
+
elsif appinstances.size > 1
|
442
363
|
ZuoraConnect.logger.debug("User must select instance. #{@names}")
|
443
364
|
render "zuora_connect/static/launch", :locals => {:names => appinstances.to_h}, :layout => false
|
444
365
|
return
|
445
366
|
|
446
367
|
#We have no deployed instance for this tenant
|
447
|
-
else
|
448
|
-
#Ensure user can access oauth creation API
|
368
|
+
else
|
369
|
+
#Ensure user can access oauth creation API
|
449
370
|
if !session["ZuoraCurrentUserInfo"]['permissions'].include?("permission.userManagement")
|
450
371
|
Thread.current[:appinstance] = nil
|
451
372
|
session["appInstance"] = nil
|
452
373
|
render "zuora_connect/static/error_handled", :locals => {
|
453
|
-
:title => "Application can only complete its initial setup via platform administrator",
|
374
|
+
:title => "Application can only complete its initial setup via platform administrator",
|
454
375
|
:message => "Please contact admin who has user managment permissions in tenant and have them click and finish setup."
|
455
376
|
}, :layout => false
|
456
377
|
return
|
457
378
|
end
|
458
379
|
Apartment::Tenant.switch!("public")
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
ActiveRecord::Base.transaction do
|
463
|
-
ActiveRecord::Base.connection.execute('LOCK public.zuora_users IN ACCESS EXCLUSIVE MODE')
|
380
|
+
ActiveRecord::Base.transaction do
|
381
|
+
ActiveRecord::Base.connection.execute('LOCK public.zuora_users IN ACCESS EXCLUSIVE MODE')
|
382
|
+
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
|
464
383
|
|
465
|
-
|
466
|
-
|
384
|
+
if appinstances.size > 0
|
385
|
+
redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{request.fullpath}"
|
386
|
+
return
|
387
|
+
end
|
467
388
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
389
|
+
next_id = (ZuoraConnect::AppInstance.all.where('id > 24999999').order(id: :desc).limit(1).pluck(:id).first || 24999999) + 1
|
390
|
+
user = (ENV['DEIS_APP'] || "Application").split('-').map(&:capitalize).join(' ')
|
391
|
+
body = {
|
392
|
+
'userId' => zuora_user_id,
|
393
|
+
'entityIds' => [zuora_entity_id.unpack("a8a4a4a4a12").join('-')],
|
394
|
+
'customAuthorities' => [],
|
395
|
+
'additionalInformation' => {
|
396
|
+
'description' => "This user is for #{user} application.",
|
397
|
+
'name' => "#{user} API User #{next_id}"
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
oauth_response, response = zuora_client.rest_call(
|
402
|
+
method: :post,
|
403
|
+
body: body.to_json,
|
404
|
+
url: zuora_client.rest_endpoint("genesis/clients").gsub('v1/', ''),
|
405
|
+
session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic,
|
406
|
+
headers: auth_headers
|
407
|
+
)
|
473
408
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
'customAuthorities' => [],
|
481
|
-
'additionalInformation' => {
|
482
|
-
'description' => "This user is for #{user} application.",
|
483
|
-
'name' => "#{user} API User #{next_id}"
|
484
|
-
}
|
485
|
-
}
|
486
|
-
|
487
|
-
oauth_response, response = zuora_client.rest_call(
|
488
|
-
method: :post,
|
489
|
-
body: body.to_json,
|
490
|
-
url: zuora_client.rest_endpoint("genesis/clients").gsub('v1/', ''),
|
491
|
-
session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic,
|
492
|
-
headers: auth_headers
|
493
|
-
)
|
494
|
-
|
495
|
-
new_zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", oauth_client_id: oauth_response["clientId"], oauth_secret: oauth_response["clientSecret"] )
|
496
|
-
if session["ZuoraCurrentUserInfo"].blank?
|
497
|
-
client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''), session_type: :bearer)
|
498
|
-
else
|
499
|
-
client_describe = session["ZuoraCurrentUserInfo"]
|
500
|
-
end
|
501
|
-
|
502
|
-
available_entities = client_describe["accessibleEntities"].select {|entity| entity['id'] == zuora_entity_id}
|
503
|
-
task_data = {
|
504
|
-
"id": next_id,
|
505
|
-
"name": client_describe["tenantName"],
|
506
|
-
"mode": "Collections",
|
507
|
-
"status": "Running",
|
508
|
-
ZuoraConnect::AppInstance::LOGIN_TENANT_DESTINATION => {
|
509
|
-
"tenant_type": "Zuora",
|
510
|
-
"username": session["ZuoraCurrentIdentity"]["username"],
|
511
|
-
"url": new_zuora_client.url,
|
512
|
-
"status": "Active",
|
513
|
-
"oauth_client_id": oauth_response['clientId'],
|
514
|
-
"oauth_secret": oauth_response['clientSecret'],
|
515
|
-
"authentication_type": "OAUTH",
|
516
|
-
"entities": available_entities.map {|e| e.merge({'displayName' => client_describe["tenantName"]})}
|
517
|
-
},
|
518
|
-
"tenant_ids": available_entities.map{|e| e['entityId']}.uniq,
|
519
|
-
}
|
520
|
-
end
|
409
|
+
new_zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", oauth_client_id: oauth_response["clientId"], oauth_secret: oauth_response["clientSecret"] )
|
410
|
+
if session["ZuoraCurrentUserInfo"].blank?
|
411
|
+
client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''), session_type: :bearer)
|
412
|
+
else
|
413
|
+
client_describe = session["ZuoraCurrentUserInfo"]
|
414
|
+
end
|
521
415
|
|
522
|
-
|
523
|
-
|
524
|
-
|
416
|
+
available_entities = client_describe["accessibleEntities"].select {|entity| entity['id'] == zuora_entity_id}
|
417
|
+
task_data = {
|
418
|
+
"id": next_id,
|
419
|
+
"name": client_describe["tenantName"],
|
420
|
+
"mode": "Collections",
|
421
|
+
"status": "Running",
|
422
|
+
ZuoraConnect::AppInstance::LOGIN_TENANT_DESTINATION => {
|
423
|
+
"tenant_type": "Zuora",
|
424
|
+
"username": session["ZuoraCurrentIdentity"]["username"],
|
425
|
+
"url": new_zuora_client.url,
|
426
|
+
"status": "Active",
|
427
|
+
"oauth_client_id": oauth_response['clientId'],
|
428
|
+
"oauth_secret": oauth_response['clientSecret'],
|
429
|
+
"authentication_type": "OAUTH",
|
430
|
+
"entities": available_entities.map {|e| e.merge({'displayName' => client_describe["tenantName"]})}
|
431
|
+
},
|
432
|
+
"tenant_ids": available_entities.map{|e| e['entityId']}.uniq,
|
433
|
+
}
|
434
|
+
mapped_values = {:id => next_id, :api_token => rand(36**64).to_s(36), :token => rand(36**64).to_s(36), :zuora_logins => task_data, :oauth_expires_at => Time.now + 1000.years, :zuora_domain => zuora_client.rest_domain, :zuora_entity_ids => [zuora_entity_id]}
|
435
|
+
@appinstance = ZuoraConnect::AppInstance.new(mapped_values)
|
436
|
+
retry_count = 0
|
437
|
+
begin
|
438
|
+
@appinstance.save(:validate => false)
|
439
|
+
rescue ActiveRecord::RecordNotUnique => ex
|
440
|
+
if (retry_count += 1) < 3
|
441
|
+
@appinstance.assign_attributes({:api_token => rand(36**64).to_s(36), :token => rand(36**64).to_s(36)})
|
442
|
+
retry
|
525
443
|
else
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
444
|
+
Thread.current[:appinstance] = nil
|
445
|
+
session["appInstance"] = nil
|
446
|
+
render "zuora_connect/static/error_handled", :locals => {
|
447
|
+
:title => "Application could not create unique tokens.",
|
448
|
+
:message => "Please contact support or retry launching application."
|
449
|
+
}, :layout => false
|
450
|
+
return
|
533
451
|
end
|
534
452
|
end
|
535
|
-
rescue ActiveRecord::RecordNotUnique
|
536
|
-
retry if (retry_count -= 1).positive?
|
537
|
-
return
|
538
453
|
end
|
539
454
|
|
540
455
|
Apartment::Tenant.switch!("public")
|
@@ -557,27 +472,19 @@ module ZuoraConnect
|
|
557
472
|
ZuoraConnect.logger.warn("UI Authorization Error", ex, zuora: zuora_details.merge({:error => response.body}))
|
558
473
|
elsif final_error != "INVALID_SESSION"
|
559
474
|
ZuoraConnect.logger.warn("UI Authorization Error", ex, zuora: zuora_details.merge({:error => final_error}))
|
560
|
-
else
|
561
|
-
ZuoraConnect.logger.info("UI Authorization Error", ex, zuora: zuora_details.merge({:error => final_error}))
|
562
475
|
end
|
563
476
|
redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{request.fullpath}"
|
564
477
|
return
|
565
|
-
|
566
|
-
|
567
|
-
if ex.
|
568
|
-
|
569
|
-
render "zuora_connect/static/error_handled", locals: locals, status: 400, layout: false
|
570
|
-
else
|
571
|
-
session.clear
|
572
|
-
if defined?(ex.response) && ex.response.present? && defined?(ex.response.body)
|
573
|
-
zuora_details.merge!({:error => ex.response.body})
|
574
|
-
end
|
575
|
-
ZuoraConnect.logger.error("UI Authorization Error", ex, zuora: zuora_details)
|
576
|
-
render "zuora_connect/static/error_unhandled", locals: {exception: ex, skip_exception: true}, layout: false, status: 500
|
478
|
+
rescue => ex
|
479
|
+
session.clear
|
480
|
+
if defined?(ex.response) && ex.response.present? && defined?(ex.response.body)
|
481
|
+
zuora_details.merge!({:error => ex.response.body})
|
577
482
|
end
|
578
|
-
|
483
|
+
ZuoraConnect.logger.error("UI Authorization Error", ex, zuora: zuora_details)
|
484
|
+
render "zuora_connect/static/error_unhandled", locals: {exception: ex, skip_exception: true}, layout: false, status: 500
|
485
|
+
return
|
579
486
|
end
|
580
|
-
elsif request["data"]
|
487
|
+
elsif request["data"] && /^([A-Za-z0-9+\/\-\_]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$/.match(request["data"].to_s)
|
581
488
|
session.clear
|
582
489
|
values = JSON.parse(ZuoraConnect::AppInstance.decrypt_response(Base64.urlsafe_decode64(request["data"])))
|
583
490
|
values.fetch("param_data", {}).each do |k ,v|
|
@@ -592,6 +499,8 @@ module ZuoraConnect
|
|
592
499
|
session["#{values["appInstance"]}::user::email"] = values["current_user"]["email"]
|
593
500
|
end
|
594
501
|
|
502
|
+
ZuoraConnect.logger.debug({msg: 'Setup values', connect: values}) if Rails.env != "production"
|
503
|
+
|
595
504
|
@appinstance = ZuoraConnect::AppInstance.find_by(:id => values["appInstance"].to_i)
|
596
505
|
|
597
506
|
if @appinstance.blank?
|
@@ -612,53 +521,16 @@ module ZuoraConnect
|
|
612
521
|
else
|
613
522
|
raise ZuoraConnect::Exceptions::AccessDenied.new("Authorization mismatch. Possible tampering with session.")
|
614
523
|
end
|
615
|
-
end
|
524
|
+
end
|
616
525
|
else
|
617
526
|
if session["appInstance"].present?
|
618
|
-
@appinstance = ZuoraConnect::AppInstance.find_by(:id => session["appInstance"])
|
527
|
+
@appinstance = ZuoraConnect::AppInstance.find_by(:id => session["appInstance"])
|
619
528
|
else
|
620
529
|
raise ZuoraConnect::Exceptions::AccessDenied.new("No application state or session found.")
|
621
530
|
end
|
622
531
|
end
|
623
532
|
end
|
624
533
|
|
625
|
-
def next_instance_id
|
626
|
-
min_instance_id = 24_999_999
|
627
|
-
(ZuoraConnect::AppInstance.all.where("id > #{min_instance_id}").order(id: :desc).limit(1).pluck(:id).first || min_instance_id) + 1
|
628
|
-
end
|
629
|
-
|
630
|
-
def new_instance(id, zuora_entity_id, rest_domain, task_data: nil, retry_count: 0)
|
631
|
-
app_instance = ZuoraConnect::AppInstance.new(
|
632
|
-
:id => id,
|
633
|
-
:api_token => generate_token,
|
634
|
-
:token => generate_token,
|
635
|
-
:zuora_logins => task_data,
|
636
|
-
:oauth_expires_at => Time.now + 1000.years,
|
637
|
-
:zuora_domain => rest_domain,
|
638
|
-
:zuora_entity_ids => [zuora_entity_id]
|
639
|
-
)
|
640
|
-
|
641
|
-
begin
|
642
|
-
app_instance.save(:validate => false)
|
643
|
-
rescue ActiveRecord::RecordNotUnique
|
644
|
-
raise if retry_count > 1
|
645
|
-
|
646
|
-
Thread.current[:appinstance] = nil
|
647
|
-
session['appInstance'] = nil
|
648
|
-
render 'zuora_connect/static/error_handled', :locals => {
|
649
|
-
:title => 'Application could not create unique tokens.',
|
650
|
-
:message => 'Please contact support or retry launching application.'
|
651
|
-
}, :layout => false
|
652
|
-
return
|
653
|
-
end
|
654
|
-
|
655
|
-
app_instance
|
656
|
-
end
|
657
|
-
|
658
|
-
def generate_token
|
659
|
-
rand(36**64).to_s(36)
|
660
|
-
end
|
661
|
-
|
662
534
|
def setup_instance_via_dev_mode
|
663
535
|
session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
|
664
536
|
user = ZuoraConnect.configuration.dev_mode_user
|
data/lib/zuora_connect/engine.rb
CHANGED
@@ -16,13 +16,10 @@ module ZuoraConnect
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
initializer :append_migrations do |app|
|
21
|
-
|
22
|
-
|
23
|
-
config.paths["db/migrate"]
|
24
|
-
app.config.paths["db/migrate"] << expanded_path
|
25
|
-
end
|
20
|
+
unless app.root.to_s.match root.to_s
|
21
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
22
|
+
app.config.paths["db/migrate"] << expanded_path
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -13,7 +13,6 @@ module ZuoraConnect
|
|
13
13
|
PATH_INFO
|
14
14
|
CONTENT_TYPE
|
15
15
|
ORIGINAL_FULLPATH
|
16
|
-
QUERY_STRING
|
17
16
|
)
|
18
17
|
|
19
18
|
config.before_initialize do
|
@@ -47,7 +46,7 @@ module ZuoraConnect
|
|
47
46
|
require 'lograge'
|
48
47
|
|
49
48
|
Rails.configuration.logger = ZuoraConnect.custom_logger(name: "Rails")
|
50
|
-
if
|
49
|
+
if Rails.env != 'development'
|
51
50
|
Rails.configuration.lograge.enabled = true
|
52
51
|
Rails.configuration.colorize_logging = false
|
53
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.57
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: ougai-formatters-customizable
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: zuora_api
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,20 +120,6 @@ dependencies:
|
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
|
-
- !ruby/object:Gem::Dependency
|
124
|
-
name: aws-sdk-rails
|
125
|
-
requirement: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '0'
|
130
|
-
type: :runtime
|
131
|
-
prerelease: false
|
132
|
-
version_requirements: !ruby/object:Gem::Requirement
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: '0'
|
137
123
|
- !ruby/object:Gem::Dependency
|
138
124
|
name: mono_logger
|
139
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -429,9 +415,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
429
415
|
version: '0'
|
430
416
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
431
417
|
requirements:
|
432
|
-
- - "
|
418
|
+
- - ">="
|
433
419
|
- !ruby/object:Gem::Version
|
434
|
-
version:
|
420
|
+
version: '0'
|
435
421
|
requirements: []
|
436
422
|
rubygems_version: 3.0.3
|
437
423
|
signing_key:
|