zuora_connect 2.0.60e → 2.0.60j
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/models/zuora_connect/app_instance_base.rb +36 -6
- data/config/initializers/postgresql_adapter.rb +71 -1
- data/lib/resque/dynamic_queues.rb +1 -1
- data/lib/zuora_connect/controllers/helpers.rb +13 -5
- data/lib/zuora_connect/railtie.rb +15 -0
- 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: 27a3847105e8376738ca1183becbbbaae8f6f1b8d5a6fad0dca2207bc8526da2
|
4
|
+
data.tar.gz: 99d274d4cd3e5ab15f148fbda907aa51555c52f01c7acd3b88610b6d829d5351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15e5d1d61dbf20dc6f51419482da3f5804a70e04b40febbee74588b8f7036ca2530aec84fdc58cbaa90add318f48d6c5318188b195e3f98d1fb181092104a732
|
7
|
+
data.tar.gz: 1863947d49d8d854456466e17dc35183ba0bc36af30fa272027932bfdf8b0bc09bb98be525fc344ee9649670e1bae0285756838c80cc7d55e524d6dc81e22418
|
@@ -11,7 +11,7 @@ module ZuoraConnect
|
|
11
11
|
before_destroy :prune_data
|
12
12
|
|
13
13
|
self.table_name = "zuora_connect_app_instances"
|
14
|
-
attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems
|
14
|
+
attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems, :user_timezone
|
15
15
|
@@telegraf_host = nil
|
16
16
|
REFRESH_TIMEOUT = 2.minute #Used to determine how long to wait on current refresh call before executing another
|
17
17
|
INSTANCE_REFRESH_WINDOW = 1.hours #Used to set how how long till app starts attempting to refresh cached task connect data
|
@@ -240,7 +240,29 @@ module ZuoraConnect
|
|
240
240
|
rescue I18n::InvalidLocale => ex
|
241
241
|
ZuoraConnect.logger.error(ex) if !IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
|
+
user = ZuoraConnect::ZuoraUser.order(updated_at: :desc).first
|
245
|
+
self.user_timezone = user ? user.zuora_identity_response.values.first&.dig('timeZone') : nil
|
246
|
+
|
247
|
+
if self.user_timezone.present?
|
248
|
+
# connect instance which has a custom timezone
|
249
|
+
if !self.auto_deployed? && self.task_data.dig('user_settings', 'timezone') != self.user_timezone
|
250
|
+
if self.environment == 'Production'
|
251
|
+
ZuoraConnect.logger.error('Instance and user timezones are different', app_instance_id: self.id)
|
252
|
+
end
|
253
|
+
self.user_timezone = nil
|
254
|
+
Time.zone = self.timezone
|
255
|
+
else
|
256
|
+
begin
|
257
|
+
Time.zone = self.user_timezone
|
258
|
+
rescue ArgumentError
|
259
|
+
Time.zone = self.timezone
|
260
|
+
end
|
261
|
+
end
|
262
|
+
else
|
263
|
+
Time.zone = self.timezone
|
264
|
+
end
|
265
|
+
|
244
266
|
if self.task_data.present?
|
245
267
|
tenants = self.task_data.fetch('tenant_ids', [])
|
246
268
|
organizations = self.task_data.fetch('organizations', [])
|
@@ -272,6 +294,10 @@ module ZuoraConnect
|
|
272
294
|
end
|
273
295
|
end
|
274
296
|
|
297
|
+
def auto_deployed?
|
298
|
+
self.id >= 25000000
|
299
|
+
end
|
300
|
+
|
275
301
|
def refresh(session: {})
|
276
302
|
refresh_count ||= 0
|
277
303
|
skip_connect ||= false
|
@@ -338,6 +364,10 @@ module ZuoraConnect
|
|
338
364
|
raise
|
339
365
|
end
|
340
366
|
|
367
|
+
def aws_secrets
|
368
|
+
(Rails.application.secrets.aws || {}).transform_keys { |key| key.to_s }
|
369
|
+
end
|
370
|
+
|
341
371
|
#### START KMS ENCRYPTION Methods ####
|
342
372
|
def zuora_logins=(val)
|
343
373
|
write_attribute(:zuora_logins, kms_encrypt(val.to_json))
|
@@ -350,7 +380,7 @@ module ZuoraConnect
|
|
350
380
|
|
351
381
|
def kms_decrypt(value)
|
352
382
|
kms_tries ||= 0
|
353
|
-
kms_client = Aws::KMS::Client.new({region:
|
383
|
+
kms_client = Aws::KMS::Client.new({region: aws_secrets['AWS_REGION'], credentials: self.aws_auth_client}.delete_if { |k, v| v.blank? })
|
354
384
|
resp = kms_client.decrypt({ciphertext_blob: [value].pack("H*") })
|
355
385
|
return resp.plaintext
|
356
386
|
rescue *AWS_AUTH_ERRORS => ex
|
@@ -365,7 +395,7 @@ module ZuoraConnect
|
|
365
395
|
|
366
396
|
def kms_encrypt(value)
|
367
397
|
kms_tries ||= 0
|
368
|
-
kms_client = Aws::KMS::Client.new({region:
|
398
|
+
kms_client = Aws::KMS::Client.new({region: aws_secrets['AWS_REGION'], credentials: self.aws_auth_client}.delete_if {|k,v| v.blank? })
|
369
399
|
|
370
400
|
resp = kms_client.encrypt({key_id: kms_key, plaintext: value})
|
371
401
|
return resp.ciphertext_blob.unpack('H*').first
|
@@ -380,12 +410,12 @@ module ZuoraConnect
|
|
380
410
|
end
|
381
411
|
|
382
412
|
def kms_key
|
383
|
-
return ENV['AWS_KMS_ARN'] ||
|
413
|
+
return ENV['AWS_KMS_ARN'] || aws_secrets['AWS_KMS_ARN']
|
384
414
|
end
|
385
415
|
|
386
416
|
def aws_auth_client
|
387
417
|
if Rails.env.to_s == 'development'
|
388
|
-
return Aws::Credentials.new(
|
418
|
+
return Aws::Credentials.new(aws_secrets['AWS_ACCESS_KEY_ID'], aws_secrets['AWS_SECRET_ACCESS_KEY'])
|
389
419
|
else
|
390
420
|
return nil
|
391
421
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
3
|
class PostgreSQLAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
SCHEMA_ADDITIONAL_TYPES = 'SchemaAdditionalTypes'.freeze
|
6
|
+
|
4
7
|
private
|
5
|
-
def
|
8
|
+
def load_additional_types_latest(oids = nil)
|
6
9
|
initializer = OID::TypeMapInitializer.new(type_map)
|
10
|
+
|
11
|
+
return if loaded_from_cache?(initializer)
|
12
|
+
|
7
13
|
if supports_ranges?
|
8
14
|
query = <<-SQL
|
9
15
|
SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
@@ -24,9 +30,73 @@ module ActiveRecord
|
|
24
30
|
end
|
25
31
|
|
26
32
|
execute_and_clear(query, "SCHEMA", []) do |records|
|
33
|
+
cache_additional_types(records)
|
27
34
|
initializer.run(records)
|
28
35
|
end
|
29
36
|
end
|
37
|
+
|
38
|
+
def load_additional_types_deprecated(type_map, oids = nil)
|
39
|
+
initializer = OID::TypeMapInitializer.new(type_map)
|
40
|
+
|
41
|
+
return if loaded_from_cache?(initializer)
|
42
|
+
|
43
|
+
if supports_ranges?
|
44
|
+
query = <<-SQL
|
45
|
+
SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
46
|
+
FROM pg_type as t
|
47
|
+
LEFT JOIN pg_range as r ON oid = rngtypid
|
48
|
+
SQL
|
49
|
+
else
|
50
|
+
query = <<-SQL
|
51
|
+
SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, t.typtype, t.typbasetype
|
52
|
+
FROM pg_type as t
|
53
|
+
SQL
|
54
|
+
end
|
55
|
+
|
56
|
+
if oids
|
57
|
+
query += "WHERE t.oid::integer IN (%s)" % oids.join(", ")
|
58
|
+
else
|
59
|
+
query += initializer.query_conditions_for_initial_load(type_map)
|
60
|
+
end
|
61
|
+
|
62
|
+
execute_and_clear(query, "SCHEMA", []) do |records|
|
63
|
+
cache_additional_types(records)
|
64
|
+
initializer.run(records)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def loaded_from_cache?(initializer)
|
69
|
+
if defined?(Redis.current)
|
70
|
+
begin
|
71
|
+
if Redis.current.exists(SCHEMA_ADDITIONAL_TYPES)
|
72
|
+
initializer.run(JSON.parse(Redis.current.get(SCHEMA_ADDITIONAL_TYPES)))
|
73
|
+
return true
|
74
|
+
end
|
75
|
+
rescue => ex
|
76
|
+
Rails.logger.warn('Exception occurred while loading additional types', ex)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
false
|
81
|
+
end
|
82
|
+
|
83
|
+
def cache_additional_types(records)
|
84
|
+
if defined?(Redis.current)
|
85
|
+
begin
|
86
|
+
Redis.current.setex(SCHEMA_ADDITIONAL_TYPES, 1.hour.to_i, records.to_json)
|
87
|
+
rescue => ex
|
88
|
+
Rails.logger.warn('Exception occurred while caching additional types', ex)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
rails_version = Rails.version.split('.').map { |x| x.to_i }
|
95
|
+
if (rails_version <=> [5, 2, 0]) >= 1
|
96
|
+
alias :load_additional_types :load_additional_types_latest
|
97
|
+
else
|
98
|
+
alias :load_additional_types :load_additional_types_deprecated
|
99
|
+
end
|
30
100
|
end
|
31
101
|
end
|
32
102
|
end
|
@@ -124,14 +124,21 @@ module ZuoraConnect
|
|
124
124
|
ElasticAPM.set_user(session["#{@appinstance.id}::user::email"]) if defined?(ElasticAPM) && ElasticAPM.running?
|
125
125
|
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail)
|
126
126
|
end
|
127
|
+
|
128
|
+
locale = (session["#{@appinstance.id}::user::locale"] || "").gsub("_", "-")
|
127
129
|
begin
|
128
|
-
locale = session["#{@appinstance.id}::user::locale"]
|
129
130
|
I18n.locale = locale.present? ? locale : @appinstance.locale
|
130
131
|
rescue I18n::InvalidLocale => ex
|
132
|
+
if locale.include?("-")
|
133
|
+
locale = locale.split("-").first
|
134
|
+
retry
|
135
|
+
end
|
131
136
|
ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
132
137
|
end
|
133
138
|
begin
|
134
|
-
|
139
|
+
if @appinstance.user_timezone.blank?
|
140
|
+
Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
|
141
|
+
end
|
135
142
|
rescue
|
136
143
|
ZuoraConnect.logger.error(ex)
|
137
144
|
end
|
@@ -435,7 +442,8 @@ module ZuoraConnect
|
|
435
442
|
session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
|
436
443
|
session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
|
437
444
|
session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
|
438
|
-
session["#{@appinstance.id}::user::
|
445
|
+
session["#{@appinstance.id}::user::language"] = session['ZuoraCurrentIdentity']["language"]
|
446
|
+
session["#{@appinstance.id}::user::locale"] = session['ZuoraCurrentIdentity']["locale"]
|
439
447
|
session["appInstance"] = @appinstance.id
|
440
448
|
|
441
449
|
#We have multiple, user must pick
|
@@ -566,8 +574,8 @@ module ZuoraConnect
|
|
566
574
|
|
567
575
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, Exception => ex
|
568
576
|
if ex.message.include?("Referenced User resource(s) not found") && ex.class == ZuoraAPI::Exceptions::ZuoraAPIError
|
569
|
-
locals = {title: "Provisioning Error", message: "New
|
570
|
-
render "zuora_connect/static/error_handled", locals: locals, status:
|
577
|
+
locals = {title: "Provisioning Error", message: "New tenants need to be provisioned by API Gateway('#{ex.message}'). Please contact support."}
|
578
|
+
render "zuora_connect/static/error_handled", locals: locals, status: 200, layout: false
|
571
579
|
else
|
572
580
|
session.clear
|
573
581
|
if defined?(ex.response) && ex.response.present? && defined?(ex.response.body)
|
@@ -81,6 +81,21 @@ module ZuoraConnect
|
|
81
81
|
request_headers =
|
82
82
|
event.payload[:headers].env.
|
83
83
|
reject { |key| key.to_s.include?('.') || REQUEST_HEADERS_TO_IGNORE.include?(key.to_s) }
|
84
|
+
begin
|
85
|
+
if request_headers["HTTP_AUTHORIZATION"].present?
|
86
|
+
if request_headers["HTTP_AUTHORIZATION"].include?("Basic")
|
87
|
+
user_password = request_headers["HTTP_AUTHORIZATION"].split("Basic").last.strip
|
88
|
+
user, password = Base64.decode64(user_password).split(":")
|
89
|
+
request_headers["HTTP_AUTHORIZATION"] = "Basic #{user}:ValueFiltered"
|
90
|
+
elsif
|
91
|
+
request_headers["HTTP_AUTHORIZATION"] = "ValueFiltered"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
request_headers["HTTP_API_TOKEN"] = "ValueFiltered" if request_headers["HTTP_API_TOKEN"].present?
|
95
|
+
rescue
|
96
|
+
request_headers.delete("HTTP_API_TOKEN")
|
97
|
+
request_headers.delete("HTTP_AUTHORIZATION")
|
98
|
+
end
|
84
99
|
items.merge!({ headers: request_headers.to_s })
|
85
100
|
end
|
86
101
|
|
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.60j
|
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-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|