zuora_connect 3.1.0.pre.b → 3.1.0.pre.e

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ab5ac57e2b7a00d075bbc96d9ab724f4bdc6c5ca457469f857eab9db1a7f876
4
- data.tar.gz: c4ff526e3ec38ae3bff4a6d3ed1faaf94f45523ec0b59cb46bcfaada4b9aaaca
3
+ metadata.gz: 5214f01edfd6d5be196318459c718b0b654ddf9d94b658860fd5595f834ff59a
4
+ data.tar.gz: 0a718fed463c71a7723897f673dd40c2facc742a205b2851f6ede90e20e796da
5
5
  SHA512:
6
- metadata.gz: 150b9b6d81620dbf8005f878ceac204b199009723462e449a8ef7f5498a78244178ddd34cd4ec6a6f6d64b3806e177451f2816576ebfe849ea411b344d1c7c0e
7
- data.tar.gz: f7aaa7a5b6cd2e86aa109615c46964268ed3b7e598512ea7f3cbf4f24ddbee6a714b47f7c631aae02d83e16d8219e2b6c3672370ffe49323dfed5169cb3f4456
6
+ metadata.gz: 3a51ece01655985f0e699eaf0550b0f87f6af2f43dc3ae015982aa6674113e77216d68fc21f98811d6b13ec930e9db01d4e8ab28814be04f2210e11df91c3183
7
+ data.tar.gz: 91500dc84ef5cd15efd160cbb885eb022b3861677e66e28f276a37e0a025d27fdbbb4615bff4f1bf8378e2413935fe7ba418b72a9f806b7167f7876e3b6ec470
@@ -43,7 +43,12 @@ module ZuoraConnect
43
43
 
44
44
  def cache_bust
45
45
  if defined?(Redis.current)
46
+ @appinstance.fetch_connect_data #Fetch data and set in database if kms key is used
47
+ @appinstance.cache_app_instance(force_cache: true) #Update cache in redis
46
48
  Redis.current.del("AppInstance:#{@appinstance.id}")
49
+ @appinstance.cache_app_instance(force_cache: true) #Update cache in redis
50
+ #TODO: Could be a chance another thread cache back to old value, but will eventually cache will get consitent, move to nolonger needing redis cache
51
+
47
52
  respond_to do |format|
48
53
  format.json {render json: {}, status: :ok}
49
54
  end
@@ -351,28 +351,33 @@ module ZuoraConnect
351
351
  self.id >= 25000000
352
352
  end
353
353
 
354
+ def fetch_connect_data(session: {})
355
+ self.check_oauth_state
356
+ response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
357
+
358
+ if response.code == 200
359
+ begin
360
+ parsed_json = JSON.parse(response.body)
361
+ rescue JSON::ParserError => ex
362
+ raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
363
+ end
364
+
365
+ self.build_task(task_data: parsed_json, session: session)
366
+ self.set_backup_creds
367
+ self.save(validate: false) if self.changed?
368
+ else
369
+ raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
370
+ end
371
+ end
372
+
373
+
354
374
  def refresh(session: {})
355
375
  refresh_count ||= 0
356
376
  skip_connect ||= ZuoraConnect.configuration.skip_connect
357
377
  begin
358
378
  #Check how app was deployed
359
- if !self.auto_deployed? && !skip_connect
360
- self.check_oauth_state
361
- response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
362
-
363
- if response.code == 200
364
- begin
365
- parsed_json = JSON.parse(response.body)
366
- rescue JSON::ParserError => ex
367
- raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
368
- end
369
-
370
- self.build_task(task_data: parsed_json, session: session)
371
- self.set_backup_creds
372
- self.save(validate: false) if self.changed?
373
- else
374
- raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
375
- end
379
+ if !self.auto_deployed? && (!skip_connect || self['zuora_logins'].blank?)
380
+ self.fetch_connect_data(session: session)
376
381
  else
377
382
  self.build_task(task_data: self.zuora_logins, session: session)
378
383
  end
@@ -775,10 +780,10 @@ module ZuoraConnect
775
780
  Redis.current.del("AppInstance:#{self.id}")
776
781
  end
777
782
 
778
- def cache_app_instance
783
+ def cache_app_instance(force_cache: false)
779
784
  if defined?(Redis.current)
780
785
  #Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
781
- if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
786
+ if self.task_data.present? && ((self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i ) || force_cache)
782
787
  ZuoraConnect.logger.debug("Caching AppInstance", self.default_ougai_items)
783
788
  Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
784
789
  end
@@ -98,7 +98,19 @@ module ActiveRecord
98
98
  begin
99
99
  if Redis.current.exists(SCHEMA_ADDITIONAL_TYPES)
100
100
  additional_types = JSON.parse(Redis.current.get(SCHEMA_ADDITIONAL_TYPES))
101
- if additional_types.is_a?(Array)
101
+
102
+ rails_version = Rails.version.split('.').map { |x| x.to_i }
103
+ if (rails_version <=> [7, 0, 0]) >= 1
104
+ if additional_types.is_a?(Array) && !additional_types.first.is_a?(Array)
105
+ raise 'incompatible cache version'
106
+ end
107
+ elsif (rails_version <=> [5, 2, 0]) >= 1
108
+ if additional_types.is_a?(Array) && additional_types.first.is_a?(Array)
109
+ raise 'incompatible cache version'
110
+ end
111
+ end
112
+
113
+ if additional_types.is_a?(Array) && additional_types.first.is_a?(Array)
102
114
  additional_types.each { |additional_type| initializer.run(additional_type) }
103
115
  else
104
116
  initializer.run(additional_types)
@@ -106,6 +118,7 @@ module ActiveRecord
106
118
  return true
107
119
  end
108
120
  rescue => ex
121
+ Redis.current.del(SCHEMA_ADDITIONAL_TYPES)
109
122
  Rails.logger.warn('Exception occurred while loading additional types', ex)
110
123
  end
111
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZuoraConnect
4
- VERSION = "3.1.0-b"
4
+ VERSION = "3.1.0-e"
5
5
  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: 3.1.0.pre.b
4
+ version: 3.1.0.pre.e
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment