zuora_connect 3.0.0.pre.a → 3.0.0.pre.f

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e63c10c8405375ad7cb2c28073c6181ed055266fb8d61e3ac5725e8f5b8ca8d5
4
- data.tar.gz: c5124fe3590fd14c0acdad0cfe6e567997195eaa728245f620bfff5bbda285fe
3
+ metadata.gz: b446d43b611937f6dd159be0509d2baade4dce7db52381560ec571ef3b4e638a
4
+ data.tar.gz: 0bde587c9f97c73708e3f47a07138b81a4948c99f41250f4043625757d84fe07
5
5
  SHA512:
6
- metadata.gz: 1beb3e3c0531b3035051711670de269814122c20269086ffd31257b02dc4e6ff8c515ac812abc436360ebc9f1506e3ae8e15e859d6098913e08f2dfed67e1284
7
- data.tar.gz: bff9fca90e302be4fe97b3cac4ac54bb8dc6c841ad6762939f9b0b2c6c7e66417bb108105d6d8372965ae9090d813c97cff8a4a4a6b513665beed63c9229f0e4
6
+ metadata.gz: 817077fec00084059fe4eeff8809e6b340e55a57a35b4d267c89bdd9ceda2fabeb1f925113ae8a95e8380b504587d53539bbc7ab97416924413d9e061d4ce916
7
+ data.tar.gz: 85ac6b9700e02395ed1bcb73eec74163780f284de4cefe7c76db6e6c4dd636d1868115e1c0bf06be9ae5034c06b7b460274265635d59e447c4dd3157d65f81cd
@@ -152,7 +152,8 @@ module ZuoraConnect
152
152
  if ZuoraConnect.configuration.mode != "Production"
153
153
  mock_task_data = {
154
154
  "id" => ZuoraConnect.configuration.dev_mode_appinstance,
155
- "mode" => ZuoraConnect.configuration.dev_mode_mode
155
+ "mode" => ZuoraConnect.configuration.dev_mode_mode,
156
+ "name" => "Developer Instance"
156
157
  }
157
158
 
158
159
  case ZuoraConnect.configuration.dev_mode_options.class
@@ -168,6 +169,7 @@ module ZuoraConnect
168
169
  end
169
170
 
170
171
  self.build_task(task_data: mock_task_data, session: session)
172
+ self.set_backup_creds if !self['zuora_logins'].present?
171
173
  self.last_refresh = Time.now.to_i
172
174
  else
173
175
  time_expire = (session["#{self.id}::last_refresh"] || Time.now).to_i - INSTANCE_REFRESH_WINDOW.ago.to_i
@@ -289,10 +291,7 @@ module ZuoraConnect
289
291
  elsif type == :user
290
292
  begin
291
293
  sql = <<-eos
292
- SELECT zuora_users.zuora_identity_response
293
- FROM "#{self.id}".zuora_users
294
- ORDER BY zuora_users.updated_at DESC
295
- LIMIT 1;
294
+ SELECT zuora_users.zuora_identity_response FROM "#{self.id}".zuora_users ORDER BY zuora_users.updated_at DESC LIMIT 1;
296
295
  eos
297
296
  user = ActiveRecord::Base.connection.execute(sql).to_a.first
298
297
 
@@ -352,7 +351,7 @@ module ZuoraConnect
352
351
  skip_connect ||= false
353
352
  begin
354
353
  #Check how app was deployed
355
- if self.id < 25000000 && !skip_connect
354
+ if !self.auto_deployed? && !skip_connect
356
355
  self.check_oauth_state
357
356
  response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
358
357
 
@@ -363,17 +362,9 @@ module ZuoraConnect
363
362
  raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
364
363
  end
365
364
 
366
- self.build_task(task_data: parsed_json, session: session)
367
- if self.kms_key.present? && self.kms_key.match(/^arn:aws:.*/)
368
- begin
369
- self.zuora_logins = self.strip_cache_data(object: parsed_json.dup, keys: ['applications', 'tokens', 'user_settings'])
370
- self.save(:validate => false)
371
- rescue Aws::KMS::Errors::ValidationException, *AWS_AUTH_ERRORS => ex
372
- Rails.logger.warn(AWS_AUTH_ERRORS_MSG, ex)
373
- rescue => ex
374
- Rails.logger.error(AWS_AUTH_ERRORS_MSG, ex)
375
- end
376
- end
365
+ self.build_task(task_data: parsed_json, session: session)
366
+ self.set_backup_creds
367
+ self.save(validate: false) if self.changed?
377
368
  else
378
369
  raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
379
370
  end
@@ -418,8 +409,16 @@ module ZuoraConnect
418
409
  end
419
410
 
420
411
  #### START KMS ENCRYPTION Methods ####
412
+ def set_backup_creds
413
+ if self.kms_key.present? && self.kms_key.match(/^arn:aws:.*/) && self.task_data.present?
414
+ self.zuora_logins = self.strip_cache_data(object: self.task_data.dup, keys: ['applications', 'tokens', 'user_settings'])
415
+ end
416
+ end
417
+
421
418
  def zuora_logins=(val)
422
419
  write_attribute(:zuora_logins, kms_encrypt(val.to_json))
420
+ rescue Aws::KMS::Errors::ValidationException, Aws::KMS::Errors::NotFoundException, *AWS_AUTH_ERRORS => ex
421
+ Rails.logger.warn(AWS_AUTH_ERRORS_MSG, ex)
423
422
  end
424
423
 
425
424
  def zuora_logins
@@ -582,7 +581,7 @@ module ZuoraConnect
582
581
  parsed_json = JSON.parse(response.body)
583
582
 
584
583
  #Set Org
585
- if self.id >= 25000000 && parsed_json['organization'].present?
584
+ if self.auto_deployed? && parsed_json['organization'].present?
586
585
  login_cache = self.zuora_logins
587
586
  login_cache.delete('organization')
588
587
  self.zuora_logins = login_cache.merge({'organizations' => [parsed_json['organization']]})
@@ -34,15 +34,3 @@ Resque.module_eval do
34
34
  Hash[queue_names.zip(sizes)]
35
35
  end
36
36
  end
37
-
38
- if defined?(Resque.logger)
39
- Resque.logger = ZuoraObservability::Logger.custom_logger(name: "Resque", type: 'Monologger', level: MonoLogger::INFO)
40
- Resque::Scheduler.logger = ZuoraObservability::Logger.custom_logger(name: "ResqueScheduler") if defined?(Resque::Scheduler)
41
- end
42
- if defined?(Delayed::Worker.logger)
43
- Delayed::Worker.logger = ZuoraObservability::Logger.custom_logger(name: "DelayedJob", type: 'Monologger', level: MonoLogger::INFO)
44
- end
45
-
46
- Makara::Logging::Logger.logger = ZuoraObservability::Logger.custom_logger(name: "Makara") if defined?(Makara)
47
- ElasticAPM.agent.config.logger = ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN) if defined?(ElasticAPM) && ElasticAPM.running?
48
- ActionMailer::Base.logger = ZuoraObservability::Logger.custom_logger(name: "ActionMailer", type: 'Monologger') if defined?(ActionMailer)
@@ -1,37 +1,6 @@
1
1
  module ZuoraConnect
2
2
  require 'uri'
3
3
 
4
- # Object of this class is passed to the ActiveSupport::Notification hook
5
- class PageRequest
6
-
7
- # This method is triggered when a non error page is loaded (not 404)
8
- def call(name, started, finished, unique_id, payload)
9
- # If the url contains any css or JavaScript files then do not collect metrics for them
10
- return nil if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| payload[:path].include?(word) }
11
-
12
- # Getting the endpoint and the content_type
13
- content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json", :csv => "text/csv"}
14
- content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
15
- content_type = content_type.to_s.gsub('text/javascript', 'application/javascript')
16
-
17
- # payloads with 500 requests do not have status as it is not set by the controller
18
- # https://github.com/rails/rails/issues/33335
19
- #status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
20
- if payload[:exception].present?
21
- status_code, exception = [500, payload[:exception].first]
22
- else
23
- status_code, exception = [payload[:status], nil]
24
- end
25
-
26
- tags = {method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action]}.compact
27
-
28
- values = {view_time: payload[:view_runtime], db_time: payload[:db_runtime], response_time: ((finished-started)*1000)}.compact
29
- values = values.map{ |k,v| [k,v.round(2)]}.to_h
30
-
31
- ZuoraObservability::Metrics.write_to_telegraf(direction: :inbound, tags: tags, values: values)
32
- end
33
- end
34
-
35
4
  class MetricsMiddleware
36
5
 
37
6
  require "zuora_connect/version"
@@ -86,13 +55,6 @@ module ZuoraConnect
86
55
  @status, @headers, @response = @app.call(env)
87
56
  ensure
88
57
 
89
- # If the url contains any CSS or JavaScript files then do not collect metrics for them
90
- if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
91
- tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
92
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
93
- ZuoraObservability::Metrics.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
94
- end
95
-
96
58
  # Uncomment following block of code for handling engine requests/requests without controller
97
59
  # else
98
60
  # # Handling requests which do not have controllers (engines)
@@ -677,27 +677,30 @@ module ZuoraConnect
677
677
 
678
678
  def setup_instance_via_dev_mode
679
679
  session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
680
- user = ZuoraConnect.configuration.dev_mode_user
681
- key = ZuoraConnect.configuration.dev_mode_pass
682
- values = {:user => user , :key => key, :appinstance => session["appInstance"]}
683
- @appinstance = ZuoraConnect::AppInstance.find_by(:id => values[:appinstance].to_i)
680
+ session["#{ZuoraConnect.configuration.dev_mode_appinstance}::admin"] = ZuoraConnect.configuration.dev_mode_admin
681
+
682
+ values = {
683
+ id: ZuoraConnect.configuration.dev_mode_appinstance,
684
+ access_token: ZuoraConnect.configuration.dev_mode_user,
685
+ refresh_token: ZuoraConnect.configuration.dev_mode_pass,
686
+ token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
687
+ api_token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass
688
+ }
689
+
690
+ @appinstance = ZuoraConnect::AppInstance.find_by(:id => ZuoraConnect.configuration.dev_mode_appinstance.to_i)
684
691
  ZuoraConnect::ZuoraUser.current_user_id = 0
685
692
  if @appinstance.blank?
686
693
  Apartment::Tenant.switch!("public")
687
694
  begin
688
- Apartment::Tenant.create(values[:appinstance].to_s)
695
+ Apartment::Tenant.create(ZuoraConnect.configuration.dev_mode_appinstance.to_s)
689
696
  rescue Apartment::TenantExists => ex
690
- Apartment::Tenant.drop(values[:appinstance].to_s)
697
+ Apartment::Tenant.drop(ZuoraConnect.configuration.dev_mode_appinstance.to_s)
691
698
  retry
692
699
  end
693
-
694
- @appinstance = ZuoraConnect::AppInstance.new(:id => values[:appinstance].to_i, :access_token => values[:user], :refresh_token => values[:key], :token => "#{values[:key]}#{values[:key]}", :api_token => "#{values[:key]}#{values[:key]}")
695
- @appinstance.save(:validate => false)
696
- end
697
- if @appinstance.access_token.blank? || @appinstance.refresh_token.blank? || @appinstance.token.blank? || @appinstance.api_token.blank?
698
- @appinstance.update_attributes!(:access_token => values["user"], :refresh_token => values["key"], :token => "#{values[:key]}#{values[:key]}", :api_token => "#{values[:key]}#{values[:key]}")
700
+ @appinstance = ZuoraConnect::AppInstance.new()
699
701
  end
700
- session["#{@appinstance.id}::admin"] = ZuoraConnect.configuration.dev_mode_admin
702
+ @appinstance.assign_attributes(values)
703
+ @appinstance.save(:validate => false)
701
704
  end
702
705
  end
703
706
  end
@@ -5,17 +5,6 @@ require 'middleware/bad_multipart_form_data_sanitizer'
5
5
 
6
6
  module ZuoraConnect
7
7
  class Railtie < Rails::Railtie
8
- REQUEST_HEADERS_TO_IGNORE = %W(
9
- RAW_POST_DATA
10
- REQUEST_METHOD
11
- REQUEST_URI
12
- REQUEST_PATH
13
- PATH_INFO
14
- CONTENT_TYPE
15
- ORIGINAL_FULLPATH
16
- QUERY_STRING
17
- )
18
-
19
8
  config.before_initialize do
20
9
  version = Rails.version
21
10
  if version >= "5.0.0"
@@ -43,8 +32,5 @@ module ZuoraConnect
43
32
  app.config.middleware.use Rack::Deflater, if: ->(env, *) { env['PATH_INFO'] == '/connect/internal/metrics' }
44
33
  end
45
34
  end
46
-
47
- # hook to process_action
48
- ActiveSupport::Notifications.subscribe('process_action.action_controller', ZuoraConnect::PageRequest.new)
49
35
  end
50
36
  end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "3.0.0-a"
2
+ VERSION = "3.0.0-f"
3
3
  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.0.0.pre.a
4
+ version: 3.0.0.pre.f
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-30 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -186,16 +186,16 @@ dependencies:
186
186
  name: zuora_observability
187
187
  requirement: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - ">="
189
+ - - '='
190
190
  - !ruby/object:Gem::Version
191
- version: '0'
191
+ version: 0.1.0.pre.b
192
192
  type: :runtime
193
193
  prerelease: false
194
194
  version_requirements: !ruby/object:Gem::Requirement
195
195
  requirements:
196
- - - ">="
196
+ - - '='
197
197
  - !ruby/object:Gem::Version
198
- version: '0'
198
+ version: 0.1.0.pre.b
199
199
  - !ruby/object:Gem::Dependency
200
200
  name: rspec
201
201
  requirement: !ruby/object:Gem::Requirement