zuora_connect 3.0.0.pre.o → 3.0.0.pre.t

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: ecc223977b1f506e5fa4141d181f7e297691f766b87391bbbec461fcdfa7380d
4
- data.tar.gz: 38b4ad6cab3345040e9d413bc5c5989dcfd307841253545aecfc13c3354a324a
3
+ metadata.gz: 81197d2fca3e19e8602342a820948d21963735397119b0c992cb316452e25bba
4
+ data.tar.gz: 43466f6d39c34bb60fa13e63a57c70dc23b9466c0a15a21b9f404a368e4efef1
5
5
  SHA512:
6
- metadata.gz: a72d3d4a1b6508128470aa5684ad8f2d5ee8b036fae4905e64291f15efbd53ba92ced303dfc107bc079d5a57c4412089833f497100161df70ee7b403f2418113
7
- data.tar.gz: de3ff7e9c42e9bfac9aad4f1ee48c012212f21d9932412e39b965d359cc0b3448fc214061000e1fd498af5e33ebf42d89d32becfd272f1a185b53e2d7d2efb9f
6
+ metadata.gz: 6265d548693f0ff43e39ea5cbec79db9245023f4bc0891ab9c6f7772b795927ef071fd06cadc67043effc0fdab05ecbca7c8dec6064004fa28723617521593f8
7
+ data.tar.gz: e1ab4768c5037e459b0111ae1a711c04f0163d061c2460e6e5a6c14e383f5f27ed5eb188d6b891ceb6942784d2e73c03f384896a81799d0e1252ebdfb00a34cd
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 Matthew Ingle
1
+ Copyright 2021 Zuora, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # Connect Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/zuora_connect.svg)](https://badge.fury.io/rb/zuora_connect)
4
+
5
+ ## Requirements
6
+ This gem requires a postgres database
7
+
8
+ ## Install
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'zuora_connect'
14
+ ```
15
+
16
+ Then execute `bundle install` in your terminal
17
+
18
+ ## How to contribute to this repository
19
+ https://confluence.zuora.com/pages/viewpage.action?spaceKey=ZCP&title=Pushing+to+GIT
20
+
21
+ ## Configuration
22
+
23
+ ### Settings
24
+ This gem can be configured by adding `connect.rb` to the `config/initializers` folder. An example file and the available options can be seen below.
25
+ ```ruby
26
+ ZuoraConnect.configure do |config|
27
+ config.url = ""
28
+ config.delayed_job = false
29
+ config.default_time_zone = Time.zone
30
+ config.default_locale = :en
31
+ config.timeout = 5.minutes
32
+ config.private_key = ""
33
+ config.mode = "Production"
34
+ config.dev_mode_logins = { "target_login" => {"tenant_type" => "Zuora", "username" => "user", "password" => "pass", "url" => "url"} }
35
+ config.dev_mode_options = {"name" => {"config_name" => "name", "datatype" => "type", "value" => "value"}}
36
+ config.dev_mode_mode = "Universal"
37
+ end
38
+ ```
39
+
40
+ | Option | Description | Required | Values | Default | Example |
41
+ | -------------------- | ----------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------- | --------------------------- | ------------------------------------------ |
42
+ | url | URL for the gem to connect to | Optional | https://connect.zuora.com <br/> https://connect-staging.zuora.com <br/> localhost:3000 | "https://connect.zuora.com" | config.url = `"https://connect.zuora.com"` |
43
+ | delayed_job | Used to indicate if Delayed Job is used by this Application | Optional | true or false | `true`| `config.delayed_job - true`|
44
+ | default_time_zone | Used to indicate the default timezone for the application | Optional | A valid time zone object | `Time.zone`| `config.default_time_zone = Time.zone` |
45
+ | default_locale | Used to indicate the default locale for the application | Optional | A valid locale| `:en`| `config.default_locale = :en`|
46
+ | private_key| Used to indicate the private key to use when decrypting the data payload|Required for Production| A valid private key| `nil`|`config.private_key = File.open(#{Rails.root/private_key})`|
47
+ | timeout|Used to indicate the amount of time the current session stays active before syncing with ZuoraConnect| Optional |ActiveSupport::Duration |`5.minutes`|`config.timeout = 1.hour`|
48
+ | mode|Used to indicate current environment the gem should run against|Optional |Production or Development|`"Production"`|`config.mode = "Development"`|
49
+ | dev_mode_appinstance|Used to indicate the schema name to use when in development mode|Optional|String|`"1"` |`config.dev_mode_appinstance = "1"`|
50
+ | dev_mode_admin|Used to indicate if admin mode should be turned on in development mode. This will cause all admin calls to be evaluated to true when displaying admin only elements in your application.|Optional|true or false|`false`|`config.dev_mode_admin = true`|
51
+ | dev_mode_pass|Used to mock up the users ZuoraConnect password|Optional |String|`"Test"`|`config.dev_mode_pass = "password1"`|
52
+ | dev_mode_user|Used to mock up the users ZuoraConnect username|Optional|String|`"Test"`|`config.dev_mode_user = "User1"`|
53
+ | dev_mode_logins|Used to mock up the login payload from ZuoraConnect|Optional|Hash|`nil`| `config.dev_mode_logins= { "target_login" => {"tenant_type" => "Zuora","username" => "user","password" => "pass","url" => "url"}}`
54
+ | dev_mode_mode|Used to mock up the mode passed from ZuoraConnect|Optional |String|`"Universal" `|`config.dev_mode_mode = "Mode2"`|
55
+ | dev_mode_options|Used to mock up the options payload from ZuoraConnect|Optional |Hash|`nil`|'config.dev_mode_options ={"name" => {"config_name" => "name","datatype" => "type","value" => "value"}}'|
56
+
57
+
58
+ ### Controller Setup
59
+ The following controllers should have the below lines added to them
60
+
61
+ #### Application Controller ( `controllers/application_controller.rb`)
62
+ ```ruby
63
+ before_action :authenticate_connect_app_request
64
+ after_action :persist_connect_app_session
65
+ ```
66
+
67
+ #### Admin controllers
68
+ ```ruby
69
+ before_action :check_connect_admin!
70
+ ```
71
+
72
+ #### Admin actions inside a controllers
73
+
74
+ ```ruby
75
+ before_action :check_connect_admin!, :only => [:logs]
76
+ ```
77
+ #### API Controller
78
+ ```ruby
79
+ before_action :authenticate_app_api_request
80
+ ```
81
+
82
+ An explanation of the available before_filters and what they do can be found below
83
+
84
+ | Name | Description |
85
+ | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
+ | authenticate_app_api_request | Authenticates the incoming request, handles data segmentation, and creates the @appinstance global variable |
87
+ | persist_connect_app_session | Saves the current user session for use after every request so that every request does not require authentication with Connect. Instead authentication to Connect is done based on the timeout value of the session set in the configuration steps above |
88
+ | check_connect_admin | Checks if the user is labeled as an admin as deemed by the encrypted request payload coming from Connect. This filter is used to lock down certain functionality that only the Developer should have access to. <br/> Returns false if the user is not an admin |
89
+ | check_connect_admin! | The filter works the same as the above but instead raises an exception `ZuoraConnect::Exceptions::AccessDenied` |
90
+ | authenticate_app_api_request | Authenticates the incoming API request based on the token passed in. The token must match a token associate to one of the available app instances. This token is stored on the app instance object as api_token. More information can be found in the API authentication section below. |
91
+
92
+ ## Usage
93
+
94
+ The Connect gem provides an integration with ZuoraConnect by allowing the application to read data from Connect and make the appropriate API calls.
95
+
96
+ ### Data Segmentation
97
+
98
+ The Connect Gem provides an integration with ZuoraConnect by allowing the application to read data from Connect and make the appropriate API calls.
99
+
100
+ ### The App Instance object
101
+
102
+ #### Methods and Attributes
103
+
104
+ | Name | Type | Description | Example |
105
+ | ------------ | ----------- | ------------ | --------------------------- |
106
+ | new_session | `Method` | | @appinstance.new_sesion |
107
+ | updateOption | `Method` | | @appinstance.updateOption() |
108
+ | options | `Attribute` | | @appinstance.options |
109
+ | mode | `Attribute` | | @appinstance.mode |
110
+ | logins | `Attribute` | | @appinstance.logins |
111
+ | task_data | `Attribute` | | @appinstance.task_data |
112
+ | token | `Attribute` | `DEPRECATED` | @appinstance.token |
113
+ | api_token | `Attribute` | | @appinstance.api_token |
114
+
115
+ #### Accessing the Object
116
+
117
+ The `@appinstance` object is accessible in every View and Controller in your application. In order to access `@appinstance` in a Model it must be pulled out of the current thread by doing the following:
118
+ ```ruby
119
+ @appinstance = Thread.current[:appinstance]
120
+ ```
121
+ ### Login Object
122
+
123
+ All Login information available to your app is passed from connect in a hash in the form `{:target_login => data, :source_login => data}`. It is important to note that target_login and source_login can be variable and that any number of logins can be passed to your application as defined by Connect. For example the following use case could exist: `{:zuora_login => data, :system1_login => data,:system2_login => data}`. This information can be retrieved by the @appinstance object through a call similiar to this `@appinstance.system2_login`. This removes the requirement of using `@appinstance.logins `and looping through the returned hash if you are aware of the logins that Connect will be sending your application.
124
+
125
+ Each login is mapped as a login object associated to the `@appinstance` object. Every attribute associated to this object passed from Connect is available on this object as an attribute. At a minimum the below attributes will be available
126
+
127
+
128
+ | Name | Description |
129
+ | ----------- | ------------------------------------------ |
130
+ | tenant_type | Login type such as "Zuora" or "Salesforce" |
131
+ | username | The username |
132
+ | password | The password |
133
+ | url | Endpoint or URL |
134
+
135
+ #### Zuora logins
136
+ The Connect Gem has built-in integration with the Zuora gem and automatically creates a ZuoraLogin object for every Zuora login. This can be accessed by executing something similiar to the following:
137
+ ```ruby
138
+ @appinstance.target_login.client.rest_call
139
+ ```
140
+
141
+ ### Admin authentication
142
+
143
+ #### Controller
144
+
145
+ Authentication is done through a before filter. Reference the above section on controller setup
146
+
147
+ #### View
148
+
149
+ `is_app_admin?` is a view helper that returns true if the user is an admin
150
+
151
+ ### API Authentication
152
+
153
+ In order to allow direct access to the application without Connect for API calls the :authenticate_app_api_request before filter must be used in your controller and both authenticate_connect_app_request and persist_connect_app_session filters should be skipped to avoid collision.
154
+
155
+ When making an API call to your application the token associated to the `@appinstance` object must be passed in as the password in a basic auth header with the username being the users Connect username or in the access_token param
156
+
157
+ ## Rails Console
158
+
159
+ By Default all queries executed from Rails Console will filter against schemas that are named “Public” and your current system $user. You can verify this by executing `ActiveRecord::Base.connection.schema_search_path` in rails console which should return “”$user", public"
160
+
161
+ The Connect Gem will create/use schemas tied to the TaskIds coming out of Connect. In Development mode this TaskId will default to 1. To query data out in development mode you would open up rails console and execute `ActiveRecord::Base.connection.schema_search_path = 1` before proceeding to subsequent queries
162
+
163
+ ## Delayed Job
164
+
165
+ In order to use delayed job the configuration option “delayed_job” must be set to true for jobs to be picked up by your workers
166
+
167
+ ### Installation
168
+ 1. Set `config.delayed_job = true` in `config/initializers/connect.rb`
169
+ 2. Add the following line to the connect.rb init file `Dir["#{Rails.root}/lib/workers/*.rb"].each {|file| require file }`
170
+ 3. Add the following gems to your gem file
171
+ ```ruby
172
+ gem "delayed_job"
173
+ gem "delayed_job_active_record"
174
+ gem "daemons"
175
+ gem "delayed_job_web" #Optional if a web interface is needed for job management
176
+ ```
177
+ 4. Run `rails generate delayed_job:active_record` in the terminal
178
+ 5. Add `config.active_job.queue_adapter = :delayed_job` to `config/application.rb`
179
+
180
+ ### Usage
181
+
182
+ #### Creating a Worker Class
183
+
184
+ Add a worker file based on the following template to lib/workers/worker.rb
185
+ ```ruby
186
+ class Worker
187
+ attr_accessor :schema
188
+ def initialize(instance_id,var2)
189
+ @instance_id = instance_id
190
+ @var2 = var2
191
+ @schema = ActiveRecord::Base.connection.schema_search_path
192
+ end
193
+
194
+ def perform()
195
+ @appinstance = ZuoraConnect::AppInstance.find(@instance_id)
196
+ @appinstance.new_session()
197
+ end
198
+ end
199
+ ```
200
+
201
+ #### Queueing Jobs
202
+
203
+ Jobs can be queued anywhere in the code base by using the following code `Delayed::Job.enqueue(Worker.new(@appinstance.id, var2))`. Note that instead of passing in the @appinstance object we always pass in the id. This must happen for schema segmentation to work correctly. This can be disregarded if your worker is not processing data specific to a users app instance.
204
+
205
+ Reference [here](https://github.com/collectiveidea/delayed_job) for more information on Running Jobs and creating workers
206
+
207
+ #### Starting the delayed job daemon
208
+
209
+ Run `bin/delayed_job -n 2 restart` in your terminal to start 2 processes that will pick up all queued jobs
210
+
211
+ ### License Information
212
+ IN THE EVENT YOU ARE AN EXISTING ZUORA CUSTOMER, USE OF THIS SOFTWARE IS GOVERNED BY THE MIT LICENSE SET FORTH BELOW AND NOT THE MASTER SUBSCRIPTION AGREEMENT OR OTHER COMMERCIAL AGREEMENT ENTERED INTO BETWEEN YOU AND ZUORA (“AGREEMENT”). FOR THE AVOIDANCE OF DOUBT, ZUORA’S OBLIGATIONS WITH RESPECT TO TECHNICAL SUPPORT, UPTIME, INDEMNIFICATION, AND SECURITY SET FORTH IN THE AGREEMENT DO NOT APPLY TO THE USE OF THIS SOFTWARE.
213
+
214
+ Copyright 2021 Zuora, Inc.
215
+
216
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
217
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
218
+
219
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -2,6 +2,37 @@ module ZuoraConnect
2
2
  class ZuoraUser < ActiveRecord::Base
3
3
  self.table_name = "zuora_users"
4
4
  attr_accessor :session
5
+
5
6
  cattr_accessor :current_user_id
7
+
8
+ # zuora_user_id/zuora_entity_id both come from cookie or headers
9
+ # zuora_current_identity comes from session
10
+ # app_instance is only needed to try to migrate :/
11
+ def self.update_id_response(zuora_user_id, zuora_entity_id, zuora_current_identity, app_instance)
12
+ zuora_user = find_or_create_by!(zuora_user_id: zuora_user_id) do |user|
13
+ user.zuora_identity_response = { zuora_entity_id => zuora_current_identity }
14
+ end
15
+
16
+ if zuora_user.stale_identity?
17
+ zuora_user.zuora_identity_response[zuora_entity_id] = zuora_current_identity
18
+ zuora_user.save!
19
+ end
20
+
21
+ zuora_user
22
+ # NOTE(hartley): this rescue is deprecated. We should not be migrating in production
23
+ rescue ActiveRecord::StatementInvalid => e
24
+ raise unless e.message.include?('PG::UndefinedTable') && e.message.include?('zuora_users')
25
+
26
+ ZuoraConnect.logger.fatal('Error querying zuora_users table: attempting migration to recover')
27
+
28
+ app_instance.apartment_switch(nil, true)
29
+ retry
30
+ end
31
+
32
+ # NOTE(hartley): this value was extracted from original usage in helper,
33
+ # need to investigate when exactly the identity_response should be updated
34
+ def stale_identity?
35
+ updated_at < Time.now - 1.day
36
+ end
6
37
  end
7
- end
38
+ end
@@ -5,6 +5,10 @@ if defined?(Resque::Worker)
5
5
  Resque::Job.send(:include, Resque::SelfLookup)
6
6
  end
7
7
 
8
+ if ENV['PROCESS_TYPE'] == 'worker'
9
+ Rails.logger = ZuoraObservability::Logger.custom_logger(name: 'RailsWorker', level: Logger::INFO)
10
+ end
11
+
8
12
  Resque.module_eval do
9
13
  # Returns a hash, mapping queue names to queue sizes
10
14
  def queue_sizes
@@ -0,0 +1,21 @@
1
+ ZuoraObservability.configure do |config|
2
+ config.zecs_service_hook = lambda do |controller|
3
+ custom_payload = {}
4
+ if controller.instance_variable_defined?(:@appinstance)
5
+ appinstance = controller.instance_variable_get(:@appinstance)
6
+ if appinstance.logitems.present? && appinstance.logitems.class == Hash
7
+ ActiveSupport::Deprecation.warn("logitems is deprecated, please use zecs_service_hook. See 'https://gitlab.zeta.tools/extension-products/incubating-projects/zuora_observability/-/blob/master/doc/logging.md' for more details.")
8
+ custom_payload.merge!(appinstance.logitems)
9
+ end
10
+ end
11
+ custom_payload
12
+ end
13
+ config.add_custom_payload_hook do |controller|
14
+ custom_payload = {}
15
+ if controller.instance_variable_defined?(:@appinstance)
16
+ appinstance = controller.instance_variable_get(:@appinstance)
17
+ custom_payload.merge!({ email: appinstance.connect_user })
18
+ end
19
+ custom_payload
20
+ end
21
+ end
@@ -2,24 +2,25 @@ module Resque
2
2
  module Plugins
3
3
  module AppInstanceJob
4
4
  def around_perform(args)
5
- case args.class.to_s
5
+ case args.class.name
6
6
  when "Array"
7
- if args.first.class == Hash
7
+ if args.first.is_a?(Hash)
8
8
  data = args.first.merge({:worker_class => self.to_s})
9
9
  else
10
- data = {:worker_class => self.to_s, :args => args}
10
+ data = {:worker_class => self.to_s, :args => args.to_json}
11
11
  end
12
12
  when "Hash"
13
13
  data = args.merge({:worker_class => self.to_s})
14
14
  end
15
+
15
16
  if Rails.logger.is_a?(Ougai::Logger) && !Rails.env.development?
16
- Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
17
+ Rails.logger.with_fields = { zecs_service: data.transform_keys(&:to_sym), trace_id: SecureRandom.uuid }
17
18
  end
18
19
 
19
20
  begin
20
21
  connection_count ||= 0
21
22
  @appinstance = ZuoraConnect::AppInstance.find(args['app_instance_id'].to_i)
22
- job_start_log(args)
23
+ job_start_log
23
24
 
24
25
  @appinstance.new_session(holding_pattern: true)
25
26
  rescue ActiveRecord::RecordNotFound => exception
@@ -69,8 +70,8 @@ module Resque
69
70
  Rails.logger.flush if Rails.logger.methods.include?(:flush)
70
71
  end
71
72
 
72
- def job_start_log(args)
73
- Rails.logger.info("Starting job")
73
+ def job_start_log
74
+ Rails.logger.info('Starting job')
74
75
  end
75
76
  end
76
77
  end
@@ -7,25 +7,24 @@ module Resque
7
7
  module Plugins
8
8
  module CustomLogger
9
9
  def before_perform(*args)
10
- case args.class.to_s
10
+ case args.class.name
11
11
  when "Array"
12
- if args.first.class == Hash
12
+ if args.first.is_a?(Hash)
13
13
  data = args.first.merge({:worker_class => self.to_s})
14
14
  else
15
- data = {:worker_class => self.to_s, :args => args}
15
+ data = {:worker_class => self.to_s, :args => args.to_json}
16
16
  end
17
17
  when "Hash"
18
18
  data = args.merge({:worker_class => self.to_s})
19
19
  end
20
+
20
21
  if Rails.logger.is_a?(Ougai::Logger) && !Rails.env.development?
21
- Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
22
- end
23
- data = {:msg => 'Starting job', :job => data}
24
- if data.dig(:job, 'app_instance_id').present?
25
- data[:app_instance_id] = data.dig(:job, 'app_instance_id')
22
+ Rails.logger.with_fields = { zecs_service: data.transform_keys(&:to_sym), trace_id: SecureRandom.uuid }
26
23
  end
27
24
 
28
- Rails.logger.info(data) if data.present?
25
+ if data.present?
26
+ Rails.logger.info('Starting job')
27
+ end
29
28
  end
30
29
  end
31
30
  end
data/lib/zuora_connect.rb CHANGED
@@ -11,7 +11,6 @@ require 'resque/plugins/custom_logger'
11
11
  require 'resque/plugins/app_instance_job'
12
12
  require 'metrics/influx/point_value'
13
13
  require 'metrics/net'
14
- require 'mono_logger'
15
14
  require 'zuora_connect/zuora_audit'
16
15
  require 'active_record'
17
16
  require 'zuora_observability'
@@ -88,7 +87,7 @@ module ZuoraConnect
88
87
  verify_server_cert: false,
89
88
  log_level: Logger::INFO,
90
89
  service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name,
91
- logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN)
90
+ logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: Logger::WARN)
92
91
  })
93
92
  defaults.merge!({disable_send: true}) if defined?(Rails::Console)
94
93
 
@@ -7,7 +7,7 @@ module ZuoraConnect
7
7
 
8
8
  attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri
9
9
 
10
- attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :json_logging, :insert_migrations, :skip_connect
10
+ attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :insert_migrations, :skip_connect
11
11
 
12
12
  def initialize
13
13
  @default_locale = :en
@@ -44,7 +44,6 @@ module ZuoraConnect
44
44
  @aws_region = "us-west-2"
45
45
  @s3_bucket_name = "rbm-apps"
46
46
  @s3_folder_name = Rails.application.class.parent_name
47
- @json_logging = Rails.env.development? || Rails.env.test? ? false : true
48
47
  end
49
48
 
50
49
  def private_key
@@ -19,6 +19,9 @@ module ZuoraConnect
19
19
  ElasticAPM.set_label(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
20
20
  end
21
21
  end
22
+
23
+ ZuoraConnect::ZuoraUser.current_user_id = request.headers["Zuora-User-Id"]
24
+
22
25
  if request.headers["API-Token"].present?
23
26
  @appinstance = ZuoraConnect::AppInstance.find_by(:api_token => request.headers["API-Token"])
24
27
  ZuoraConnect.logger.debug("API REQUEST - API token") if @appinstance.present?
@@ -125,7 +128,7 @@ module ZuoraConnect
125
128
  PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail)
126
129
  end
127
130
 
128
- locale = (session["#{@appinstance.id}::user::locale"] || "").gsub("_", "-")
131
+ locale = (session["#{@appinstance.id}::user::locale"] || "").gsub("_", "-")
129
132
  begin
130
133
  I18n.locale = locale.present? ? locale : @appinstance.locale
131
134
  rescue I18n::InvalidLocale => ex
@@ -303,8 +306,8 @@ module ZuoraConnect
303
306
  private
304
307
  def setup_instance_via_prod_mode
305
308
  zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
306
- ZuoraConnect::ZuoraUser.current_user_id = nil
307
-
309
+ ZuoraConnect::ZuoraUser.current_user_id = nil
310
+
308
311
  if zuora_entity_id.present?
309
312
  zuora_tenant_id = cookies['Zuora-Tenant-Id']
310
313
  zuora_user_id = cookies['Zuora-User-Id']
@@ -408,7 +411,7 @@ module ZuoraConnect
408
411
  appinstances ||= ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
409
412
  end
410
413
 
411
- zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId']
414
+ zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId'] || request.headers["Zuora-User-Id"]
412
415
 
413
416
  if appinstances.size == 1
414
417
  ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
@@ -417,28 +420,10 @@ module ZuoraConnect
417
420
 
418
421
  # One deployed instance with credentials
419
422
  if defined?(@appinstance) && !@appinstance['zuora_logins'].nil?
420
- #Add user/update
421
- begin
422
- ZuoraConnect::ZuoraUser.reset_table_name
423
- @zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
424
- rescue ActiveRecord::StatementInvalid => ex
425
- if ex.message.include?("PG::UndefinedTable") && ex.message.include?("zuora_users")
426
- @appinstance.apartment_switch(nil,true)
427
- retry
428
- else
429
- raise
430
- end
431
- end
432
- if @zuora_user.present?
433
- ZuoraConnect.logger.debug("Current zuora user #{zuora_user_id}")
434
- if @zuora_user.updated_at < Time.now - 1.day
435
- @zuora_user.zuora_identity_response[zuora_entity_id] = session["ZuoraCurrentIdentity"]
436
- @zuora_user.save!
437
- end
438
- else
439
- ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
440
- @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
441
- end
423
+ @zuora_user = ZuoraConnect::ZuoraUser.update_id_response(
424
+ zuora_user_id, zuora_entity_id, session["ZuoraCurrentIdentity"],
425
+ @appinstance
426
+ )
442
427
  @zuora_user.session = session
443
428
  ZuoraConnect::ZuoraUser.current_user_id = zuora_user_id
444
429
  session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
@@ -682,15 +667,15 @@ module ZuoraConnect
682
667
  def setup_instance_via_dev_mode
683
668
  session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
684
669
  session["#{ZuoraConnect.configuration.dev_mode_appinstance}::admin"] = ZuoraConnect.configuration.dev_mode_admin
685
-
670
+
686
671
  values = {
687
672
  id: ZuoraConnect.configuration.dev_mode_appinstance,
688
- access_token: ZuoraConnect.configuration.dev_mode_user,
689
- refresh_token: ZuoraConnect.configuration.dev_mode_pass,
690
- token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
673
+ access_token: ZuoraConnect.configuration.dev_mode_user,
674
+ refresh_token: ZuoraConnect.configuration.dev_mode_pass,
675
+ token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
691
676
  api_token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass
692
677
  }
693
-
678
+
694
679
  @appinstance = ZuoraConnect::AppInstance.find_by(:id => ZuoraConnect.configuration.dev_mode_appinstance.to_i)
695
680
  ZuoraConnect::ZuoraUser.current_user_id = 0
696
681
  if @appinstance.blank?
@@ -708,4 +693,4 @@ module ZuoraConnect
708
693
  end
709
694
  end
710
695
  end
711
- end
696
+ end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "3.0.0-o"
2
+ VERSION = "3.0.0-t"
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.o
4
+ version: 3.0.0.pre.t
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-01-13 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -38,40 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: ougai-formatters-customizable
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 1.0.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 1.0.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: zuora_api
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 1.7.00
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.7.00
47
+ version: '1.7'
65
48
  type: :runtime
66
49
  prerelease: false
67
50
  version_requirements: !ruby/object:Gem::Requirement
68
51
  requirements:
69
52
  - - "~>"
70
53
  - !ruby/object:Gem::Version
71
- version: 1.7.00
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 1.7.00
54
+ version: '1.7'
75
55
  - !ruby/object:Gem::Dependency
76
56
  name: httparty
77
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,20 +72,6 @@ dependencies:
92
72
  - - ">="
93
73
  - !ruby/object:Gem::Version
94
74
  version: 0.16.4
95
- - !ruby/object:Gem::Dependency
96
- name: lograge
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
75
  - !ruby/object:Gem::Dependency
110
76
  name: aws-sdk-s3
111
77
  requirement: !ruby/object:Gem::Requirement
@@ -134,20 +100,6 @@ dependencies:
134
100
  - - ">="
135
101
  - !ruby/object:Gem::Version
136
102
  version: '0'
137
- - !ruby/object:Gem::Dependency
138
- name: mono_logger
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - "~>"
142
- - !ruby/object:Gem::Version
143
- version: '1.0'
144
- type: :runtime
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - "~>"
149
- - !ruby/object:Gem::Version
150
- version: '1.0'
151
103
  - !ruby/object:Gem::Dependency
152
104
  name: railties
153
105
  requirement: !ruby/object:Gem::Requirement
@@ -186,16 +138,16 @@ dependencies:
186
138
  name: zuora_observability
187
139
  requirement: !ruby/object:Gem::Requirement
188
140
  requirements:
189
- - - '='
141
+ - - "~>"
190
142
  - !ruby/object:Gem::Version
191
- version: 0.1.0.pre.b
143
+ version: '0.1'
192
144
  type: :runtime
193
145
  prerelease: false
194
146
  version_requirements: !ruby/object:Gem::Requirement
195
147
  requirements:
196
- - - '='
148
+ - - "~>"
197
149
  - !ruby/object:Gem::Version
198
- version: 0.1.0.pre.b
150
+ version: '0.1'
199
151
  - !ruby/object:Gem::Dependency
200
152
  name: rspec
201
153
  requirement: !ruby/object:Gem::Requirement
@@ -336,6 +288,48 @@ dependencies:
336
288
  - - ">="
337
289
  - !ruby/object:Gem::Version
338
290
  version: '0'
291
+ - !ruby/object:Gem::Dependency
292
+ name: rubocop
293
+ requirement: !ruby/object:Gem::Requirement
294
+ requirements:
295
+ - - ">="
296
+ - !ruby/object:Gem::Version
297
+ version: '0'
298
+ type: :development
299
+ prerelease: false
300
+ version_requirements: !ruby/object:Gem::Requirement
301
+ requirements:
302
+ - - ">="
303
+ - !ruby/object:Gem::Version
304
+ version: '0'
305
+ - !ruby/object:Gem::Dependency
306
+ name: rubocop-rails
307
+ requirement: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: '0'
312
+ type: :development
313
+ prerelease: false
314
+ version_requirements: !ruby/object:Gem::Requirement
315
+ requirements:
316
+ - - ">="
317
+ - !ruby/object:Gem::Version
318
+ version: '0'
319
+ - !ruby/object:Gem::Dependency
320
+ name: rubocop-rspec
321
+ requirement: !ruby/object:Gem::Requirement
322
+ requirements:
323
+ - - ">="
324
+ - !ruby/object:Gem::Version
325
+ version: '0'
326
+ type: :development
327
+ prerelease: false
328
+ version_requirements: !ruby/object:Gem::Requirement
329
+ requirements:
330
+ - - ">="
331
+ - !ruby/object:Gem::Version
332
+ version: '0'
339
333
  description: Description of Connect.
340
334
  email:
341
335
  - connect@zuora.com
@@ -344,6 +338,7 @@ extensions: []
344
338
  extra_rdoc_files: []
345
339
  files:
346
340
  - MIT-LICENSE
341
+ - README.md
347
342
  - Rakefile
348
343
  - app/assets/javascripts/hallway_wrapper/after.js
349
344
  - app/assets/javascripts/hallway_wrapper/before.js
@@ -379,6 +374,7 @@ files:
379
374
  - config/initializers/resque.rb
380
375
  - config/initializers/to_bool.rb
381
376
  - config/initializers/unicorn.rb
377
+ - config/initializers/zuora_observability.rb
382
378
  - config/routes.rb
383
379
  - db/migrate/20100718151733_create_connect_app_instances.rb
384
380
  - db/migrate/20101024162319_add_tokens_to_app_instance.rb
@@ -434,7 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
434
430
  - !ruby/object:Gem::Version
435
431
  version: 1.3.1
436
432
  requirements: []
437
- rubygems_version: 3.2.3
433
+ rubygems_version: 3.2.15
438
434
  signing_key:
439
435
  specification_version: 4
440
436
  summary: Summary of Connect.