zuora_connect 3.0.0.pre.q → 3.0.0.pre.r

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: 9348d7aa606a5c6a3100f94afd22efdb2ad2c8405342708420e0e15753cb4816
4
- data.tar.gz: ea4ece99e78a056adb90fd21c4308e374365f0c64036e118fc78e83bdea441b2
3
+ metadata.gz: 8b3516f74913531168adf62cf95a28fe805018ab49ec723c9083d8f80064c158
4
+ data.tar.gz: 78e7f843dcfdd421d3dd80eb868afba810c68f6b85783a5efb645f93bf3c6097
5
5
  SHA512:
6
- metadata.gz: ec5539d89ee66fa7d02dc64add2073c5281cd138342e28600f54085d2664bc7db7df2f9995617f5fd79607a80eb3c28e09dd0893b68d22a6355f8965a8333ff3
7
- data.tar.gz: a3c30217361264f6c934484e550e26d9183cb7aeec362abd2da73be352dba20564f0b2dc6252af15355d307ff64440b7d9c619eab380e8ce2d0b95116a35cc3f
6
+ metadata.gz: e6760f6ae414ea0362a93f4ed28d6345d3cf2247e9bac4bcb4e927159da124507fb342ba3a8237176885aa9a8d1fd389a8c629c1cedf97914d6d48757e9d95b0
7
+ data.tar.gz: 7b92aebfc8426957e86dec98a6f8251e124094deee5b55776e65c6e5bd2d3d6615bc08740d9658766d7164d10d4193f8591d096702a2c605c4426d2c07cf4f53
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
@@ -417,27 +417,10 @@ module ZuoraConnect
417
417
 
418
418
  # One deployed instance with credentials
419
419
  if defined?(@appinstance) && !@appinstance['zuora_logins'].nil?
420
- #Add user/update
421
- begin
422
- @zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
423
- rescue ActiveRecord::StatementInvalid => ex
424
- if ex.message.include?("PG::UndefinedTable") && ex.message.include?("zuora_users")
425
- @appinstance.apartment_switch(nil,true)
426
- retry
427
- else
428
- raise
429
- end
430
- end
431
- if @zuora_user.present?
432
- ZuoraConnect.logger.debug("Current zuora user #{zuora_user_id}")
433
- if @zuora_user.updated_at < Time.now - 1.day
434
- @zuora_user.zuora_identity_response[zuora_entity_id] = session["ZuoraCurrentIdentity"]
435
- @zuora_user.save!
436
- end
437
- else
438
- ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
439
- @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
440
- end
420
+ @zuora_user = ZuoraConnect::ZuoraUser.update_id_response(
421
+ zuora_user_id, zuora_entity_id, session["ZuoraCurrentIdentity"],
422
+ @appinstance
423
+ )
441
424
  @zuora_user.session = session
442
425
  ZuoraConnect::ZuoraUser.current_user_id = zuora_user_id
443
426
  session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "3.0.0-q"
2
+ VERSION = "3.0.0-r"
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.q
4
+ version: 3.0.0.pre.r
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-02-18 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -338,6 +338,7 @@ extensions: []
338
338
  extra_rdoc_files: []
339
339
  files:
340
340
  - MIT-LICENSE
341
+ - README.md
341
342
  - Rakefile
342
343
  - app/assets/javascripts/hallway_wrapper/after.js
343
344
  - app/assets/javascripts/hallway_wrapper/before.js