zuora_connect 3.0.2.pre.d → 3.0.2.pre.h

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: 527f334aa53550fcb76ec478571ff72b4d93a3b1dac00b72e44bd675b377ae2a
4
- data.tar.gz: 555db3194402d86913d295ce38a74dc1983f65cd8ac0521ab88960d8d96c99cf
3
+ metadata.gz: 1daf70331d29259febac6329ca469eb0a452dbd2528b2fca8df344bf4eba70ae
4
+ data.tar.gz: d9a36bda5170c74140511e7e2538ad2e71c02af12c311cd57dbd9e825c970bbf
5
5
  SHA512:
6
- metadata.gz: b6880e4c9ae5aba34292326f6f78e2d60011ccb85bb3d0e1523b617ca61e975f3cf8b2616cdf3813e78f4a3254867e8fd5f1a0e8d46989d2674b387c499f56ba
7
- data.tar.gz: 548da9f9da6499333c850257e928fe639444040d18127af630d224f9322622d3493ab7aa6b70640034fb35f5586348b1de219425a799bc177cb26b3157c36336
6
+ metadata.gz: a4db46ecf8fa9ef1f8aea8e1622450e95ba85e9a1f34764e5461ecaa1a4da8987704a5fd15e73946030f9592253bf099db4f4e83515ea81064216bf058dddf05
7
+ data.tar.gz: 8a71664252ae4b807e0bfe851cb5246de049591787da15a909bb2e67e3c4addd960c0d0fbbdce47758716722bf4c245a0b1aa2b6adbbdb70155c4a23b0770754
@@ -266,7 +266,7 @@ module ZuoraConnect
266
266
 
267
267
  params = {
268
268
  name: self.task_data.dig('name'),
269
- zuora_entity_ids: (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']}.uniq,
269
+ zuora_entity_ids: (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).select {|entity| !entity['skip'].to_bool}.map{|e| e['id']}.uniq,
270
270
  zuora_tenant_ids: tenants.map(&:to_s).uniq,
271
271
  organizations: organizations
272
272
  }
@@ -397,7 +397,8 @@ module ZuoraConnect
397
397
  end
398
398
  end
399
399
  rescue => ex
400
- if self['zuora_logins'].present?
400
+ refresh_count += 1
401
+ if self['zuora_logins'].present? && refresh_count < 3
401
402
  ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex, self.default_ougai_items)
402
403
  skip_connect = true
403
404
  retry
@@ -812,7 +813,7 @@ module ZuoraConnect
812
813
  def strip_cache_data(object: {}, keys: ['applications', 'tokens','tenant_ids', 'organizations','user_settings'] )
813
814
  keys.each {|key| object.delete(key) }
814
815
  object.select {|k,v| k.include?('login') && v['tenant_type'] == 'Zuora'}.each do |login_key, login_data|
815
- object[login_key]['entities'] = login_data.fetch('entities',[]).map {|entity| entity.slice('id', 'tenantId', 'entityId', 'displayName')}
816
+ object[login_key]['entities'] = login_data.fetch('entities',[]).map {|entity| entity.slice('id', 'tenantId', 'entityId', 'displayName', 'identifier')}
816
817
  end
817
818
  return object
818
819
  end
@@ -1,27 +1,29 @@
1
1
  module ZuoraConnect
2
2
  class Login
3
-
3
+ attr_accessor :clients, :identifier_to_ids, :default_entity
4
4
  def initialize (fields)
5
- @clients = {}
5
+ self.clients = {}
6
+ self.identifier_to_ids = {}
6
7
  if fields["tenant_type"] == "Zuora"
7
8
  login_fields = fields.map{|k,v| [k.to_sym, v]}.to_h
8
9
  login_type = fields.dig("authentication_type").blank? ? 'Basic' : fields.dig("authentication_type").capitalize
9
10
 
10
11
  raise ZuoraConnect::Exceptions::InvalidCredentialSet.new("Cannot setup application with ZSession Login.") if login_type == "Session"
11
- @clients["Default"] = "::ZuoraAPI::#{login_type}".constantize.new(**login_fields)
12
- @default_entity = fields["entities"][0]["id"] if (fields.dig("entities") || []).size == 1
12
+ self.clients["Default"] = "::ZuoraAPI::#{login_type}".constantize.new(**login_fields)
13
+ self.default_entity = fields["entities"][0]["id"] if (fields.dig("entities") || []).size == 1
13
14
  if fields["entities"] && fields["entities"].size > 0
14
15
  fields["entities"].each do |entity|
15
- params = {:entity_id => entity["id"]}.merge(login_fields)
16
- @clients[entity["id"]] = "::ZuoraAPI::#{login_type}".constantize.new(**params)
16
+ params = {:entity_id => entity["id"], :entity_identifier => entity["identifier"]}.merge(login_fields)
17
+ self.clients[entity["id"]] = "::ZuoraAPI::#{login_type}".constantize.new(**params)
18
+ self.identifier_to_ids[entity["identifier"]] = entity["id"]
17
19
  end
18
20
  end
19
- self.attr_builder("available_entities", @clients.keys)
21
+ self.attr_builder("available_entities", self.clients.keys)
20
22
  end
21
23
  fields.each do |k,v|
22
24
  self.attr_builder(k,v)
23
25
  end
24
- @default_entity ||= "Default"
26
+ self.default_entity ||= "Default"
25
27
  end
26
28
 
27
29
  def attr_builder(field,val)
@@ -29,9 +31,19 @@ module ZuoraConnect
29
31
  send("#{field}=", val)
30
32
  end
31
33
 
32
- def client(id = @default_entity)
33
- return id.blank? ? @clients[@default_entity] : @clients[id]
34
- end
34
+ def client(id = self.default_entity)
35
+ use_entity_name = self.identifier_to_ids.keys.include?(id)
36
+
37
+ # Translate entity name to entity id
38
+ id = self.identifier_to_ids[id] if use_entity_name
39
+
40
+ client = id.blank? ? self.clients[self.default_entity] : self.clients[id]
35
41
 
42
+ if client
43
+ client.entity_header_type = use_entity_name ? :entity_name : :entity_id
44
+ end
45
+
46
+ client
47
+ end
36
48
  end
37
49
  end
@@ -1 +1 @@
1
- $('body').html('<%= escape_javascript render(:file=> "zuora_connect/static/error_handled", :formats => [:html], :locals => local_assigns, :layout => false) %>');
1
+ $('body').html('<%= escape_javascript render(:template=> "zuora_connect/static/error_handled", :formats => [:html], :locals => local_assigns, :layout => false) %>');
@@ -1 +1 @@
1
- $('body').html('<%= escape_javascript render(:file=> "zuora_connect/static/error_unhandled", :formats => [:html], :locals => local_assigns, :layout => false) %>');
1
+ $('body').html('<%= escape_javascript render(:template=> "zuora_connect/static/error_unhandled", :formats => [:html], :locals => local_assigns, :layout => false) %>');
@@ -46,19 +46,10 @@ module ZuoraConnect
46
46
  if !ActionDispatch::Request::HTTP_METHODS.include?(env["REQUEST_METHOD"].upcase)
47
47
  [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]]
48
48
  else
49
- if (env['HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID'].present?)
50
- Thread.current[:isHallway] = "/#{env['HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID']}"
51
- env['PATH_INFO'] = env['PATH_INFO'].gsub(Thread.current[:isHallway], '')
52
- env['REQUEST_URI'] = env['REQUEST_URI'].gsub(Thread.current[:isHallway], '')
53
- env['REQUEST_PATH'] = env['REQUEST_PATH'].gsub(Thread.current[:isHallway], '')
54
-
55
- #We need the forwarded host header to identify location of tenant
49
+ if Thread.current[:isHallway]
50
+ # We need the forwarded host header to identify location of tenant
56
51
  whitelist = Regexp.new(".*[\.]zuora[\.]com$|^zuora[\.]com$")
57
- if whitelist.match(env['HTTP_X_FORWARDED_HOST']).present?
58
- @bad_headers.delete('HTTP_X_FORWARDED_HOST')
59
- end
60
- else
61
- Thread.current[:isHallway] = nil
52
+ @bad_headers.delete('HTTP_X_FORWARDED_HOST') if whitelist.match(env['HTTP_X_FORWARDED_HOST']).present?
62
53
  end
63
54
 
64
55
  #Remove bad headers
@@ -88,28 +79,18 @@ module ZuoraConnect
88
79
  begin
89
80
  @status, @headers, @response = @app.call(env)
90
81
  ensure
82
+ # Writing to telegraf: Handle 404
83
+ if [404, 500].include?(@status)
84
+ content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
85
+ content_type = content_type.gsub('text/javascript', 'application/javascript')
86
+ tags = { status: @status, content_type: content_type }
91
87
 
92
- # Uncomment following block of code for handling engine requests/requests without controller
93
- # else
94
- # # Handling requests which do not have controllers (engines)
95
- if env["SCRIPT_NAME"].present?
96
- controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
97
- controller_path = controller_path.sub("/", "::")
98
- request_path = "#{controller_path}#UnknownAction"
99
- else
100
- # Writing to telegraf: Handle 404
101
- if [404, 500].include?(@status)
102
- content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
103
- content_type = content_type.gsub('text/javascript', 'application/javascript')
104
- tags = {status: @status, content_type: content_type}
105
-
106
- tags = tags.merge({controller: 'ActionController'})
107
- tags = tags.merge({action: 'RoutingError' }) if @status == 404
108
-
109
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
110
-
111
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
112
- end
88
+ tags = tags.merge({ controller: 'ActionController' })
89
+ tags = tags.merge({ action: 'RoutingError' }) if @status == 404
90
+
91
+ values = { response_time: ((Time.now - start_time) * 1000).round(2) }
92
+
93
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
113
94
  end
114
95
  Thread.current[:inbound_metric] = nil
115
96
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZuoraConnect
4
+ module Middleware
5
+ # Enables requests to be served from dynamic paths, determined by headers
6
+ class Hallway
7
+ UI_PATH = 'HTTP_ZUORA_UI_PATH'
8
+ LAYOUT_ID = 'HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID'
9
+
10
+ def initialize(app)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ dynamic_path = env[UI_PATH].presence || layout_id(env)
16
+
17
+ Thread.current[:isHallway] = dynamic_path
18
+
19
+ if dynamic_path.present?
20
+ env['SCRIPT_NAME'] = dynamic_path
21
+ env['PATH_INFO'] = env['PATH_INFO'].sub(dynamic_path, '')
22
+ end
23
+
24
+ @app.call(env)
25
+ end
26
+
27
+ private
28
+
29
+ def layout_id(env)
30
+ "/#{env[LAYOUT_ID]}" if env[LAYOUT_ID].present?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'middleware/metrics_middleware'
2
4
  require 'middleware/request_id_middleware'
3
5
  require 'middleware/json_parse_errors'
@@ -17,7 +19,8 @@ module ZuoraConnect
17
19
  end
18
20
 
19
21
  initializer "zuora_connect.configure_rails_initialization" do |app|
20
- app.middleware.insert_after Rack::Sendfile, ZuoraConnect::MetricsMiddleware
22
+ app.middleware.insert_after Rack::Sendfile, ZuoraConnect::Middleware::Hallway
23
+ app.middleware.insert_after ZuoraConnect::Middleware::Hallway, ZuoraConnect::MetricsMiddleware
21
24
  app.middleware.insert_after ActionDispatch::RequestId, ZuoraConnect::RequestIdMiddleware
22
25
  app.config.middleware.use ZuoraConnect::JsonParseErrors
23
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ZuoraConnect
2
- VERSION = "3.0.2-d"
4
+ VERSION = "3.0.2-h"
3
5
  end
data/lib/zuora_connect.rb CHANGED
@@ -2,6 +2,7 @@ require 'zuora_connect/configuration'
2
2
  require "zuora_connect/engine"
3
3
  require 'zuora_connect/exceptions'
4
4
  require 'zuora_connect/controllers/helpers'
5
+ require 'zuora_connect/middleware/hallway'
5
6
  require 'zuora_connect/railtie'
6
7
  require 'resque/additions'
7
8
  require 'resque/dynamic_queues'
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.2.pre.d
4
+ version: 3.0.2.pre.h
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-16 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -424,6 +424,7 @@ files:
424
424
  - lib/zuora_connect/controllers/helpers.rb
425
425
  - lib/zuora_connect/engine.rb
426
426
  - lib/zuora_connect/exceptions.rb
427
+ - lib/zuora_connect/middleware/hallway.rb
427
428
  - lib/zuora_connect/railtie.rb
428
429
  - lib/zuora_connect/version.rb
429
430
  homepage: