zuora_connect 2.0.53 → 2.0.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/zuora_connect/app_instance_base.rb +10 -0
- data/lib/zuora_connect/controllers/helpers.rb +104 -101
- data/lib/zuora_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c87e671fc1c2afd2dc94cff3f210b5a4cf2b0c9b7b16108fb990d5c35b4e3e3
|
4
|
+
data.tar.gz: 522a063ceb5dd7cfcb453e69b823d8f6f3d0b2610269a0de51bf8d7888f83a0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd9ecbbecfa364c8a4e38fbe3e4c613ab60b7bed6101929e83d6506d1fc2bfa1ad2e023619faf85c30541cfed4005233abe43e52df8fbdacbd32937739430f1b
|
7
|
+
data.tar.gz: 501b573a04de6d580ddc7fb6fad5d3c06e8a32c3899f2054606682c2669b0f981373f0232f50f0d71b37289659e8e09aa3b2b4780380b6495310fbf1e9ddeef5
|
@@ -1204,6 +1204,16 @@ module ZuoraConnect
|
|
1204
1204
|
super
|
1205
1205
|
end
|
1206
1206
|
|
1207
|
+
def self.read_master_db
|
1208
|
+
if self.connection.respond_to?(:stick_to_master!)
|
1209
|
+
self.connection.stick_to_master!(false)
|
1210
|
+
yield
|
1211
|
+
Makara::Context.release_all
|
1212
|
+
else
|
1213
|
+
yield
|
1214
|
+
end
|
1215
|
+
end
|
1216
|
+
|
1207
1217
|
method_hook :updateOption, :update_logins, :before => :check_oauth_state
|
1208
1218
|
method_hook :new_session, :refresh, :build_task, :after => :apartment_switch
|
1209
1219
|
end
|
@@ -5,68 +5,70 @@ module ZuoraConnect
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
def authenticate_app_api_request
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if ElasticAPM.
|
16
|
-
ElasticAPM.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
start_time = Time.now
|
22
|
-
if request.headers["API-Token"].present?
|
23
|
-
@appinstance = ZuoraConnect::AppInstance.find_by(:api_token => request.headers["API-Token"])
|
24
|
-
ZuoraConnect.logger.debug("API REQUEST - API token") if @appinstance.present?
|
25
|
-
check_instance
|
26
|
-
elsif ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil))
|
27
|
-
zuora_host, zuora_entity_id, zuora_instance_id = [request.headers['zuora-host'], (request.headers['zuora-entity-ids'] || "").gsub('-',''), request.headers['zuora-instance-id']]
|
28
|
-
|
29
|
-
#Validate host present
|
30
|
-
if zuora_host.blank?
|
31
|
-
render json: {"status": 401, "message": "zuora-host header was not supplied."}, status: :unauthorized
|
32
|
-
return
|
33
|
-
end
|
34
|
-
#Validate entity-ids present
|
35
|
-
if zuora_entity_id.blank?
|
36
|
-
render json: {"status": 401, "message": "zuora-entity-ids header was not supplied."}, status: :unauthorized
|
37
|
-
return
|
38
|
-
end
|
39
|
-
#Select with instance id if present. Used where mulitple deployments are done.
|
40
|
-
if zuora_instance_id.present?
|
41
|
-
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_host, id: zuora_instance_id.to_i)
|
42
|
-
else
|
43
|
-
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_host)
|
8
|
+
ZuoraConnect::AppInstance.read_master_db do
|
9
|
+
#Skip session for api requests
|
10
|
+
request.session_options[:skip] = true
|
11
|
+
|
12
|
+
Thread.current[:appinstance] = nil
|
13
|
+
if ZuoraConnect.logger.is_a?(Ougai::Logger); ZuoraConnect.logger.with_fields = {}; end
|
14
|
+
if Rails.logger.is_a?(Ougai::Logger); Rails.logger.with_fields = {}; end
|
15
|
+
if defined?(ElasticAPM) && ElasticAPM.running?
|
16
|
+
if ElasticAPM.respond_to?(:set_label)
|
17
|
+
ElasticAPM.set_label(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
|
18
|
+
else
|
19
|
+
ElasticAPM.set_label(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
|
20
|
+
end
|
44
21
|
end
|
22
|
+
start_time = Time.now
|
23
|
+
if request.headers["API-Token"].present?
|
24
|
+
@appinstance = ZuoraConnect::AppInstance.find_by(:api_token => request.headers["API-Token"])
|
25
|
+
ZuoraConnect.logger.debug("API REQUEST - API token") if @appinstance.present?
|
26
|
+
check_instance
|
27
|
+
elsif ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil))
|
28
|
+
zuora_host, zuora_entity_id, zuora_instance_id = [request.headers['zuora-host'], (request.headers['zuora-entity-ids'] || "").gsub('-',''), request.headers['zuora-instance-id']]
|
45
29
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
30
|
+
#Validate host present
|
31
|
+
if zuora_host.blank?
|
32
|
+
render json: {"status": 401, "message": "zuora-host header was not supplied."}, status: :unauthorized
|
33
|
+
return
|
34
|
+
end
|
35
|
+
#Validate entity-ids present
|
36
|
+
if zuora_entity_id.blank?
|
37
|
+
render json: {"status": 401, "message": "zuora-entity-ids header was not supplied."}, status: :unauthorized
|
38
|
+
return
|
39
|
+
end
|
40
|
+
#Select with instance id if present. Used where mulitple deployments are done.
|
41
|
+
if zuora_instance_id.present?
|
42
|
+
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_host, id: zuora_instance_id.to_i)
|
43
|
+
else
|
44
|
+
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_host)
|
45
|
+
end
|
46
|
+
|
47
|
+
if appinstances.size == 0
|
48
|
+
render json: {"status": 401, "message": "Missing mapping or no deployment for '#{zuora_host}-#{zuora_entity_id}' ."}, status: :unauthorized
|
49
|
+
return
|
50
|
+
elsif appinstances.size > 1
|
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
|
52
|
+
return
|
53
|
+
else
|
54
|
+
@appinstance = appinstances.first
|
55
|
+
check_instance
|
56
|
+
end
|
57
|
+
|
58
|
+
elsif request.headers.fetch("Authorization", "").include?("Basic ")
|
59
|
+
authenticate_or_request_with_http_basic do |username, password|
|
60
|
+
@appinstance = ZuoraConnect::AppInstance.find_by(:token => password)
|
61
|
+
@appinstance ||= ZuoraConnect::AppInstance.find_by(:api_token => password)
|
62
|
+
ZuoraConnect.logger.debug("API REQUEST - Basic Auth") if @appinstance.present?
|
63
|
+
check_instance
|
64
|
+
end
|
52
65
|
else
|
53
|
-
@appinstance = appinstances.first
|
54
66
|
check_instance
|
55
67
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@appinstance = ZuoraConnect::AppInstance.find_by(:token => password)
|
60
|
-
@appinstance ||= ZuoraConnect::AppInstance.find_by(:api_token => password)
|
61
|
-
ZuoraConnect.logger.debug("API REQUEST - Basic Auth") if @appinstance.present?
|
62
|
-
check_instance
|
68
|
+
|
69
|
+
if @appinstance.present?
|
70
|
+
ZuoraConnect.logger.debug("Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
|
63
71
|
end
|
64
|
-
else
|
65
|
-
check_instance
|
66
|
-
end
|
67
|
-
|
68
|
-
if @appinstance.present?
|
69
|
-
ZuoraConnect.logger.debug("Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
@@ -88,59 +90,60 @@ module ZuoraConnect
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def authenticate_connect_app_request
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if ElasticAPM.
|
96
|
-
ElasticAPM.
|
93
|
+
ZuoraConnect::AppInstance.read_master_db do
|
94
|
+
Thread.current[:appinstance] = nil
|
95
|
+
if ZuoraConnect.logger.is_a?(Ougai::Logger); ZuoraConnect.logger.with_fields = {}; end
|
96
|
+
if Rails.logger.is_a?(Ougai::Logger); Rails.logger.with_fields = {}; end
|
97
|
+
if defined?(ElasticAPM) && ElasticAPM.running?
|
98
|
+
if ElasticAPM.respond_to?(:set_label)
|
99
|
+
ElasticAPM.set_label(:trace_id, request.uuid)
|
100
|
+
else
|
101
|
+
ElasticAPM.set_label(:trace_id, request.uuid)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
start_time = Time.now
|
105
|
+
|
106
|
+
if ZuoraConnect.configuration.mode == "Production"
|
107
|
+
setup_instance_via_prod_mode
|
97
108
|
else
|
98
|
-
|
109
|
+
setup_instance_via_dev_mode
|
99
110
|
end
|
100
|
-
end
|
101
|
-
start_time = Time.now
|
102
111
|
|
103
|
-
|
104
|
-
setup_instance_via_prod_mode
|
105
|
-
else
|
106
|
-
setup_instance_via_dev_mode
|
107
|
-
end
|
112
|
+
return if performed?
|
108
113
|
|
109
|
-
|
114
|
+
if !defined?(@appinstance) || @appinstance.blank?
|
115
|
+
render "zuora_connect/static/error_handled", :locals => {
|
116
|
+
:title => "Application state could not be found.",
|
117
|
+
:message => "Please relaunch application."
|
118
|
+
}, :layout => false
|
119
|
+
return
|
120
|
+
end
|
121
|
+
#Call .data_lookup with the current session to retrieve session. In some cases session may be stored/cache in redis
|
122
|
+
#so data lookup provides a model method that can be overriden per app.
|
123
|
+
if params[:controller] != 'zuora_connect/api/v1/app_instance' && params[:action] != 'drop'
|
124
|
+
if @appinstance.new_session_for_ui_requests(:params => params)
|
125
|
+
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
126
|
+
end
|
127
|
+
end
|
110
128
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
@appinstance.
|
129
|
+
if session["#{@appinstance.id}::user::email"].present?
|
130
|
+
ElasticAPM.set_user(session["#{@appinstance.id}::user::email"]) if defined?(ElasticAPM) && ElasticAPM.running?
|
131
|
+
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail)
|
132
|
+
end
|
133
|
+
begin
|
134
|
+
locale = session["#{@appinstance.id}::user::locale"]
|
135
|
+
I18n.locale = locale.present? ? locale : @appinstance.locale
|
136
|
+
rescue I18n::InvalidLocale => ex
|
137
|
+
ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
138
|
+
end
|
139
|
+
begin
|
140
|
+
Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
|
141
|
+
rescue
|
142
|
+
ZuoraConnect.logger.error(ex)
|
123
143
|
end
|
124
|
-
end
|
125
144
|
|
126
|
-
|
127
|
-
ElasticAPM.set_user(session["#{@appinstance.id}::user::email"]) if defined?(ElasticAPM) && ElasticAPM.running?
|
128
|
-
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail)
|
129
|
-
end
|
130
|
-
begin
|
131
|
-
locale = session["#{@appinstance.id}::user::locale"]
|
132
|
-
I18n.locale = locale.present? ? locale : @appinstance.locale
|
133
|
-
rescue I18n::InvalidLocale => ex
|
134
|
-
ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
145
|
+
ZuoraConnect.logger.debug("Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
|
135
146
|
end
|
136
|
-
begin
|
137
|
-
Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
|
138
|
-
rescue
|
139
|
-
ZuoraConnect.logger.error(ex)
|
140
|
-
end
|
141
|
-
|
142
|
-
ZuoraConnect.logger.debug("Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
|
143
|
-
|
144
147
|
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
145
148
|
id = @appinstance.id
|
146
149
|
ZuoraConnect::AppInstance.destroy(id)
|
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.54
|
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-04-
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|