zuora_connect 2.0.5 → 2.0.8

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.
@@ -1,6 +1,7 @@
1
1
  module ZuoraConnect
2
2
  class ZuoraUser < ActiveRecord::Base
3
3
  self.table_name = "zuora_users"
4
+ attr_accessor :session
4
5
 
5
6
  end
6
7
  end
@@ -0,0 +1,77 @@
1
+ <html>
2
+ <head>
3
+ <title>Handled Error</title>
4
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
+ <style>
6
+ body {
7
+ background-color: white;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ margin: 0;
12
+ }
13
+
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+
20
+ div.dialog > div {
21
+ border: 1px solid #CCC;
22
+ border-right-color: #999;
23
+ border-left-color: #999;
24
+ border-bottom-color: #BBB;
25
+ border-top: #3D4B5A solid 4px;
26
+ border-top-left-radius: 9px;
27
+ border-top-right-radius: 9px;
28
+ background-color: white;
29
+ padding: 7px 12% 0;
30
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
31
+ }
32
+
33
+ h1 {
34
+ font-size: 100%;
35
+ color: #3D4B5A;
36
+ line-height: 1.5em;
37
+ }
38
+ div.dialog > p {
39
+ margin: 0 0 1em;
40
+ padding: 1em;
41
+ background-color: #F7F7F7;
42
+ border: 1px solid #CCC;
43
+ border-right-color: #999;
44
+ border-left-color: #999;
45
+ border-bottom-color: #999;
46
+ border-bottom-left-radius: 4px;
47
+ border-bottom-right-radius: 4px;
48
+ border-top-color: #DADADA;
49
+ color: #666;
50
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
51
+ }
52
+ </style>
53
+ </head>
54
+
55
+ <body>
56
+ <% if defined?(exception) %>
57
+ <div class="dialog" style='max-width: 74em;'>
58
+ <div><h1><%= exception.class %> - '<%= exception.message %>'</h1></div>
59
+ <p style='text-align: left;'>
60
+ <% exception.backtrace.each do |line| %>
61
+ <%= line %><br>
62
+ <% end %>
63
+ </p>
64
+ </div>
65
+ <% elsif defined?(message) && defined?(title) %>
66
+ <div class="dialog">
67
+ <div><h1><%= title %></h1></div>
68
+ <p><%= message.html_safe %></p>
69
+ </div>
70
+ <% else %>
71
+ <div class="dialog">
72
+ <div><h1>The launch url was invalid</h1></div>
73
+ <p>Please try relaunching this application</p>
74
+ </div>
75
+ <% end %>
76
+ </body>
77
+ </html>
@@ -0,0 +1,82 @@
1
+ <html>
2
+ <head>
3
+ <title>We're sorry, but something went wrong</title>
4
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ margin: 0;
12
+ }
13
+
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+
20
+ div.dialog > div {
21
+ border: 1px solid #CCC;
22
+ border-right-color: #999;
23
+ border-left-color: #999;
24
+ border-bottom-color: #BBB;
25
+ border-top: #B00100 solid 4px;
26
+ border-top-left-radius: 9px;
27
+ border-top-right-radius: 9px;
28
+ background-color: white;
29
+ padding: 7px 12% 0;
30
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
31
+ }
32
+
33
+ h1 {
34
+ font-size: 100%;
35
+ color: #730E15;
36
+ line-height: 1.5em;
37
+ }
38
+
39
+ div.dialog > p {
40
+ margin: 0 0 1em;
41
+ padding: 1em;
42
+ background-color: #F7F7F7;
43
+ border: 1px solid #CCC;
44
+ border-right-color: #999;
45
+ border-left-color: #999;
46
+ border-bottom-color: #999;
47
+ border-bottom-left-radius: 4px;
48
+ border-bottom-right-radius: 4px;
49
+ border-top-color: #DADADA;
50
+ color: #666;
51
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
52
+ }
53
+ </style>
54
+ </head>
55
+
56
+ <body>
57
+ <!-- This file lives in public/500.html -->
58
+ <% if defined?(exception) %>
59
+ <div class="dialog" style='max-width: 74em;'>
60
+ <div><h1><%= exception.class %> - '<%= exception.message %>'</h1></div>
61
+ <p style='text-align: left;'>
62
+ <% last_line = false %>
63
+ <% exception.backtrace.each do |line| %>
64
+ <% ending = last_line && !line.include?(Rails.root.to_s) ? false : true %>
65
+ <% break if !ending%>
66
+ <% if ending %>
67
+ <%= line %><br>
68
+ <% end %>
69
+ <% last_line = line.include?(Rails.root.to_s) %>
70
+ <% end %>
71
+ </p>
72
+ </div>
73
+ <% else %>
74
+ <div class="dialog">
75
+ <div>
76
+ <h1>The launch url was invalid</h1>
77
+ </div>
78
+ <p>Please try relaunching this application</p>
79
+ </div>
80
+ <% end %>
81
+ </body>
82
+ </html>
@@ -1,80 +1,79 @@
1
- <html><head>
2
- <title>Select Task ID</title>
3
- <meta name="viewport" content="width=device-width,initial-scale=1">
4
- <style>
5
- body {
6
- background-color: #EFEFEF;
7
- color: #2E2F30;
8
- text-align: center;
9
- font-family: arial, sans-serif;
10
- margin: 0;
11
- }
1
+ <html>
2
+ <head>
3
+ <title>Select Task ID</title>
4
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ margin: 0;
12
+ }
12
13
 
13
- div.dialog {
14
- width: 95%;
15
- max-width: 33em;
16
- margin: 4em auto 0;
17
- }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
18
19
 
19
- div.dialog > div {
20
- margin: 0 0 1em;
21
- border: 1px solid #CCC;
22
- border-right-color: #999;
23
- border-left-color: #999;
24
- border-bottom-color: #BBB;
25
- border-top: #3D4B5A solid 4px;
26
- border-top-left-radius: 9px;
27
- border-top-right-radius: 9px;
28
- border-bottom-left-radius: 9px;
29
- border-bottom-right-radius: 9px;
30
- background-color: white;
31
- padding: 7px 12% 0;
32
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
33
- }
20
+ div.dialog > div {
21
+ margin: 0 0 1em;
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #3D4B5A solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ border-bottom-left-radius: 9px;
30
+ border-bottom-right-radius: 9px;
31
+ background-color: white;
32
+ padding: 7px 12% 0;
33
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
34
+ }
34
35
 
35
- h1 {
36
- font-size: 100%;
37
- color: #3D4B5A;
38
- line-height: 1.5em;
39
- }
36
+ h1 {
37
+ font-size: 100%;
38
+ color: #3D4B5A;
39
+ line-height: 1.5em;
40
+ }
40
41
 
41
-
42
- div.launch_button {
43
- margin: 1em 0 1em;
44
- margin-right: auto;
45
- margin-left: auto;
46
- padding: 1em;
47
- width: 300px;
48
- font-size: 12pt;
49
- font-weight: bold;
50
- background-color: #F7F7F7;
51
- border: 1px solid #CCC;
52
- border-right-color: #999;
53
- border-left-color: #999;
54
- border-bottom-color: #999;
55
- border-top-left-radius: 4px;
56
- border-top-right-radius: 4px;
57
- border-bottom-left-radius: 4px;
58
- border-bottom-right-radius: 4px;
59
- border-top-color: #999;
60
- color: #666;
61
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
62
- }
63
- </style>
64
- </head>
65
-
66
- <body style='background: white;'>
67
- <div class="dialog">
68
- <div>
69
- <h1>Please select the instance you would like to launch.</h1>
70
- <% names.each do |id, name| %>
71
- <div class="launch_button" >
72
- <% label = name.present? ? "#{id} - #{name}" : id %>
73
- <%= link_to label, root_path(app_instance_id: id) %>
74
- </div>
75
- <% end %>
42
+
43
+ div.launch_button {
44
+ margin: 1em 0 1em;
45
+ margin-right: auto;
46
+ margin-left: auto;
47
+ padding: 1em;
48
+ width: 300px;
49
+ font-size: 12pt;
50
+ font-weight: bold;
51
+ background-color: #F7F7F7;
52
+ border: 1px solid #CCC;
53
+ border-right-color: #999;
54
+ border-left-color: #999;
55
+ border-bottom-color: #999;
56
+ border-top-left-radius: 4px;
57
+ border-top-right-radius: 4px;
58
+ border-bottom-left-radius: 4px;
59
+ border-bottom-right-radius: 4px;
60
+ border-top-color: #999;
61
+ color: #666;
62
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
63
+ }
64
+ </style>
65
+ </head>
66
+ <body style='background: white;'>
67
+ <div class="dialog">
68
+ <div>
69
+ <h1>Please select the instance you would like to launch.</h1>
70
+ <% names.each do |id, name| %>
71
+ <div class="launch_button" >
72
+ <% label = name.present? ? "#{id} - #{name}" : id %>
73
+ <%= link_to label, root_path(app_instance_id: id) %>
74
+ </div>
75
+ <% end %>
76
+ </div>
76
77
  </div>
77
- </div>
78
-
79
-
80
- </body></html>
78
+ </body>
79
+ </html>
@@ -0,0 +1,9 @@
1
+ #Used to ensure encode of UploadedFile for lograge does not dump entire file.
2
+ class ActionDispatch::Http::UploadedFile
3
+ def as_json(options = nil)
4
+ %w(headers).inject({}) do |hash, attr|
5
+ hash[attr] = send(attr).force_encoding('utf-8')
6
+ hash
7
+ end
8
+ end
9
+ end
data/config/routes.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  ZuoraConnect::Engine.routes.draw do
2
2
  get '/health' => 'static#health'
3
3
  get '/internal/data' => 'static#metrics'
4
- get '/invalid_session' => 'static#session_error', :as => :invalid_session
5
- get '/invalid_instance' => "static#invalid_app_instance_error", :as => :invalid_instance
6
4
  post '/initialize_app' => 'static#initialize_app'
7
5
 
8
6
  namespace :api do
@@ -0,0 +1,6 @@
1
+ class AddUniqueIndex < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_index :zuora_connect_app_instances, :api_token, unique: true unless ActiveRecord::Base.connection.index_exists?(:zuora_connect_app_instances, :api_token, unique: true)
4
+ add_index :zuora_connect_app_instances, :token, unique: true unless ActiveRecord::Base.connection.index_exists?(:zuora_connect_app_instances, :token, unique: true)
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module ZuoraConnect
2
+ class JsonParseErrors
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ begin
9
+ @app.call(env)
10
+ rescue ActionDispatch::ParamsParser::ParseError => error
11
+ if env['HTTP_ACCEPT'] =~ /application\/json/ || env['CONTENT_TYPE'] =~ /application\/json/
12
+ return [
13
+ 400, { "Content-Type" => "application/json" },
14
+ [{"success": false, "reasons": [{"code": 50000090, "message": "Malformed json was submitted." }]}.to_json ]
15
+ ]
16
+ else
17
+ raise error
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -2,7 +2,7 @@ module ZuoraConnect
2
2
  class RequestIdMiddleware
3
3
  mattr_accessor :request_id
4
4
  mattr_accessor :zuora_request_id
5
-
5
+ mattr_accessor :zuora_rest_domain
6
6
  def initialize(app)
7
7
  @app = app
8
8
  end
@@ -105,7 +105,7 @@ module Resque
105
105
  end
106
106
 
107
107
  grouped_queues = grouped_queues.values.rotate(@n).map{|queue_list| get_categorized_queues(queue_list).to_h.values.flatten}.flatten.delete_if{|queue| !should_work_on_queue?(queue)}.map{|queue| "queue:#{queue}"}
108
- queue, payload = Resque.redis.blpop(grouped_queues, :timeout => (ENV["BLPOP_TIMEOUT"].to_i || 30))
108
+ queue, payload = get_job_from_queues(grouped_queues)
109
109
  return nil if queue.blank?
110
110
 
111
111
  queue = queue.split("queue:")[1]
@@ -113,6 +113,10 @@ module Resque
113
113
  return create_job(queue, Resque.decode(payload))
114
114
  end
115
115
 
116
+ def get_job_from_queues(grouped_queues)
117
+ Resque.redis.blpop(grouped_queues, :timeout => (ENV["BLPOP_TIMEOUT"].to_i || 30))
118
+ end
119
+
116
120
  def get_restricted_job
117
121
  Resque::Plugins::ConcurrentRestrictionJob.next_runnable_job_random
118
122
  end
@@ -7,7 +7,7 @@ module Resque
7
7
  module Plugins
8
8
  module CustomLogger
9
9
  def before_perform(*args)
10
- Rails.logger.with_fields = { trace_id: SecureRandom.uuid, name: "RailsWorker"} if Rails.logger.class.to_s == 'Ougai::Logger'
10
+ Rails.logger.with_fields = { trace_id: SecureRandom.uuid, name: "RailsWorker"} if Rails.logger.class.to_s == 'Ougai::Logger' && ZuoraConnect.configuration.json_logging
11
11
  case args.class.to_s
12
12
  when "Array"
13
13
  if args.first.class == Hash
data/lib/zuora_connect.rb CHANGED
@@ -2,7 +2,6 @@ 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/views/helpers'
6
5
  require 'zuora_connect/railtie'
7
6
  require 'resque/additions'
8
7
  require 'resque/dynamic_queues'
@@ -25,30 +24,49 @@ module ZuoraConnect
25
24
  else
26
25
  @logger ||= custom_logger(name: "Connect", level: Rails.logger.level)
27
26
  end
28
- end
27
+ end
29
28
 
30
29
  def custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai)
31
30
  #puts name + ' - ' + {Logger::WARN => 'Logger::WARN', Logger::ERROR => 'Logger::ERROR', Logger::DEBUG => 'Logger::DEBUG', Logger::INFO => 'Logger::INFO' }[level] + ' - '
32
31
  if type == :ougai
33
32
  require 'ougai'
33
+ require "ougai/formatters/customizable"
34
34
  #logger = Ougai::Logger.new(MonoLogger.new(STDOUT))
35
- logger = Ougai::Logger.new(STDOUT)
36
- logger.formatter = Ougai::Formatters::ConnectFormatter.new(name)
35
+ logger = Ougai::Logger.new(STDOUT)
37
36
  logger.level = level
38
- logger.before_log = lambda do |data|
39
- data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
40
- data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
41
- #data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]}
42
- if !['ElasticAPM', 'ResqueScheduler', 'ResquePool', 'Resque', 'Makara'].include?(name)
43
- if Thread.current[:appinstance].present?
44
- data[:app_instance_id] = Thread.current[:appinstance].id
45
- logitems = Thread.current[:appinstance].logitems
46
- if logitems.present? && logitems.class == Hash
47
- data[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
48
- data[:organization] = logitems[:organization] if logitems[:organization].present?
37
+ if ZuoraConnect.configuration.json_logging
38
+ logger.formatter = Ougai::Formatters::ConnectFormatter.new(name)
39
+ logger.before_log = lambda do |data|
40
+ data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
41
+ data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
42
+ #data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]}
43
+ if !['ElasticAPM', 'ResqueScheduler', 'ResquePool', 'Resque', 'Makara'].include?(name)
44
+ if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present?
45
+ data[:app_instance_id] = Thread.current[:appinstance].id
46
+ logitems = Thread.current[:appinstance].logitems
47
+ if logitems.present? && logitems.class == Hash
48
+ data[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
49
+ data[:organization] = logitems[:organization] if logitems[:organization].present?
50
+ end
49
51
  end
50
52
  end
51
53
  end
54
+ else
55
+ logger.formatter = Ougai::Formatters::Customizable.new(
56
+ format_err: proc do |data|
57
+ next nil unless data.key?(:err)
58
+ err = data.delete(:err)
59
+ " #{err[:name]} (#{err[:message]})\n #{err[:stack]}"
60
+ end,
61
+ format_data: proc do |data|
62
+ format('%s %s: %s', 'DATA'.ljust(6), Time.now.strftime('%FT%T.%6NZ'), "#{data.to_json}") if data.present?
63
+ end,
64
+ format_msg: proc do |severity, datetime, _progname, data|
65
+ msg = data.delete(:msg)
66
+ format('%s %s: %s', severity.ljust(6), datetime, msg)
67
+ end
68
+ )
69
+ logger.formatter.datetime_format = '%FT%T.%6NZ'
52
70
  end
53
71
  else
54
72
  logger = MonoLogger.new(STDOUT)
@@ -58,40 +76,39 @@ module ZuoraConnect
58
76
  msg = JSON.parse(msg)
59
77
  rescue JSON::ParserError => ex
60
78
  end
61
-
62
- require 'json'
63
- store = {
64
- name: name,
65
- level: serverity,
66
- timestamp: datetime.strftime('%FT%T.%6NZ'),
67
- pid: Process.pid,
68
- message: name == "ActionMailer" ? msg.strip : msg
69
- }
70
- if !['ElasticAPM', 'ResqueScheduler', 'ResquePool','Resque', 'Makara'].include?(name)
71
- if Thread.current[:appinstance].present?
72
- store[:app_instance_id] = Thread.current[:appinstance].id
73
- logitems = Thread.current[:appinstance].logitems
74
- if logitems.present? && logitems.class == Hash
75
- store[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
76
- store[:organization] = logitems[:organization] if logitems[:organization].present?
79
+ if ZuoraConnect.configuration.json_logging
80
+ require 'json'
81
+ store = {
82
+ name: name,
83
+ level: serverity,
84
+ timestamp: datetime.strftime('%FT%T.%6NZ'),
85
+ pid: Process.pid,
86
+ message: name == "ActionMailer" ? msg.strip : msg
87
+ }
88
+ if !['ElasticAPM', 'ResqueScheduler', 'ResquePool','Resque', 'Makara'].include?(name)
89
+ if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present?
90
+ store[:app_instance_id] = Thread.current[:appinstance].id
91
+ logitems = Thread.current[:appinstance].logitems
92
+ if logitems.present? && logitems.class == Hash
93
+ store[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
94
+ store[:organization] = logitems[:organization] if logitems[:organization].present?
95
+ end
77
96
  end
78
97
  end
98
+ JSON.dump(store) + "\n"
99
+ else
100
+ format('%s %s: %s', serverity.ljust(6), datetime, msg) + "\n"
79
101
  end
80
- JSON.dump(store) + "\n"
81
102
  end
82
103
  end
83
104
  return logger
84
- end
105
+ end
85
106
  end
86
107
 
87
108
  module Controllers
88
109
  autoload :Helpers, 'zuora_connect/controllers/helpers'
89
110
  end
90
111
 
91
- module Views
92
- ActionView::Base.send(:include, Helpers)
93
- end
94
-
95
112
  def self.configuration
96
113
  @configuration ||= Configuration.new
97
114
  end
@@ -129,23 +146,23 @@ module ZuoraConnect
129
146
  }
130
147
  when 'test'
131
148
  defaults = {
132
- active: false,
149
+ active: false,
133
150
  disable_send: true
134
151
  }
135
152
  end
136
153
 
137
154
  defaults.merge!({
138
155
  disable_start_message: true,
139
- pool_size: 1,
140
- transaction_max_spans: 500,
141
- ignore_url_patterns: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'],
156
+ pool_size: 1,
157
+ transaction_max_spans: 500,
158
+ ignore_url_patterns: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'],
142
159
  verify_server_cert: false,
143
160
  log_level: Logger::INFO,
144
161
  service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name,
145
162
  logger: ZuoraConnect.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN)
146
163
  })
147
164
  defaults.merge!({disable_send: true}) if defined?(Rails::Console)
148
-
165
+
149
166
  return defaults
150
167
  end
151
168
  end