zuora_connect 2.0.58a → 2.0.60b

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: 4a03cd7450b81983c6d782fe911babc655153094bf6ff41fec0b3ed3a3a06888
4
- data.tar.gz: 99eff46c23e53cd0d09b4c0fdafe199c239f800ca55dcaed255674d69729a2db
3
+ metadata.gz: 1f6d2a40d21ec315aaaac1859582bc689d24d6ef0ee3e42fabc640d171cb6944
4
+ data.tar.gz: 8793132888e45c9fa532ebb92c11205da312ac88df1e43dbd89f38faab9d8e49
5
5
  SHA512:
6
- metadata.gz: 7cd29354de9ecb38d51ce8361029fc6a15a008f76d659723245fe12686068757fa34b768198a571ed4390bed750e49086b49fb1099702c2475b66b4506e49c57
7
- data.tar.gz: beb5f965e6f8a88bbec73ecb507d595f82f468e419a958aec6dc33a8d4d17f17ccbf45fb90669dbf252d8e92799b9a7778323a833a618dd87a966dbf25fac51d
6
+ metadata.gz: cbd7542971dfedb9b2470094cde902c8b147c9f406cd864bb60e7beafa306b5f29b2c70aab457ea12b22b5dffd726a21a870c5bb238acaeeda64641b5cfd6ad9
7
+ data.tar.gz: a5adffbf1799fef7bf31db82eeba2fb648ea9c1ba3c34149c6c7f4b06ca7a02a6dd6c05a5e934e9aebbc974905737848ed40c8296e172226941d0fa1e7dc172c
@@ -1,11 +1,11 @@
1
1
  module ZuoraConnect
2
2
  class StaticController < ApplicationController
3
- before_action :authenticate_connect_app_request, :except => [:metrics, :health, :initialize_app, :provision]
4
- before_action :clear_connect_app_session, :only => [:metrics, :health, :initialize_app, :provision]
5
- after_action :persist_connect_app_session, :except => [:metrics, :health, :initialize_app, :provision]
3
+ before_action :authenticate_connect_app_request, :except => [:metrics, :health, :initialize_app, :provision, :instance_user]
4
+ before_action :clear_connect_app_session, :only => [:metrics, :health, :initialize_app, :provision, :instance_user]
5
+ after_action :persist_connect_app_session, :except => [:metrics, :health, :initialize_app, :provision, :instance_user]
6
6
 
7
7
  skip_before_action :verify_authenticity_token, :only => [:initialize_app, :provision]
8
- http_basic_authenticate_with name: ENV['PROVISION_USER'], password: ENV['PROVISION_SECRET'], :only => [:provision]
8
+ http_basic_authenticate_with name: ENV['PROVISION_USER'], password: ENV['PROVISION_SECRET'], :only => [:provision, :instance_user]
9
9
 
10
10
  def metrics
11
11
  type = params[:type].present? ? params[:type] : "versions"
@@ -14,11 +14,11 @@ module ZuoraConnect
14
14
 
15
15
  def health
16
16
  if params[:error].present?
17
- begin
17
+ begin
18
18
  raise ZuoraConnect::Exceptions::Error.new('This is an error')
19
19
  rescue => ex
20
20
  case params[:error]
21
- when 'Log'
21
+ when 'Log'
22
22
  Rails.logger.error("Error in Health", ex)
23
23
  when 'Exception'
24
24
  raise
@@ -77,6 +77,52 @@ module ZuoraConnect
77
77
  end
78
78
  end
79
79
 
80
+ def instance_user
81
+ ZuoraConnect::AppInstance.read_master_db do
82
+ ZuoraConnect.logger.with_fields = {} if ZuoraConnect.logger.is_a?(Ougai::Logger)
83
+ Rails.logger.with_fields = {} if Rails.logger.is_a?(Ougai::Logger)
84
+
85
+ if defined?(ElasticAPM) && ElasticAPM.running? && ElasticAPM.respond_to?(:set_label)
86
+ ElasticAPM.set_label(:trace_id, request.uuid)
87
+ end
88
+
89
+ unless params[:id].present?
90
+ render json: {
91
+ status: 400,
92
+ message: 'No app instance id provided'
93
+ }, status: :bad_request
94
+ return
95
+ end
96
+
97
+ @appinstance = ZuoraConnect::AppInstance.find(params[:id]).new_session
98
+ end
99
+
100
+ zuora_client = @appinstance.send(ZuoraConnect::AppInstance::LOGIN_TENANT_DESTINATION).client
101
+ client_describe, = zuora_client.rest_call(
102
+ url: zuora_client.rest_endpoint('genesis/user/info').gsub('v1/', ''),
103
+ session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic
104
+ )
105
+
106
+ render json: {
107
+ status: 200,
108
+ message: 'Success',
109
+ user_id: client_describe['coreUserId'],
110
+ username: client_describe['username'],
111
+ email: client_describe['workEmail']
112
+ }, status: 200
113
+ rescue ActiveRecord::RecordNotFound
114
+ render json: {
115
+ status: 400,
116
+ message: 'No app instance found'
117
+ }, status: :bad_request
118
+ rescue StandardError => e
119
+ Rails.logger.error('Error occurred getting user details', e)
120
+ render json: {
121
+ status: 500,
122
+ message: 'Failed to get user details'
123
+ }, status: 500
124
+ end
125
+
80
126
  private
81
127
 
82
128
  def clear_connect_app_session
@@ -5,6 +5,7 @@ ZuoraConnect::Engine.routes.draw do
5
5
 
6
6
  if ENV['PROVISION_USER'].present? && ENV['PROVISION_SECRET'].present?
7
7
  post '/provision' => 'static#provision'
8
+ get '/instance/:id/user' => 'static#instance_user'
8
9
  end
9
10
 
10
11
  namespace :api do
@@ -47,7 +47,7 @@ module Resque
47
47
  raise
48
48
  end
49
49
  rescue PG::ConnectionBad => exception
50
- Rails.logger.info("Bad Connection Restart")
50
+ Rails.logger.warn("Bad Connection Restart", exception)
51
51
  Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
52
52
  return
53
53
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => exception
@@ -346,7 +346,7 @@ module ZuoraConnect
346
346
  ##
347
347
  # If the ZSession was refreshed, but it's still the same user and they aren't launching from the side bar,
348
348
  # we don't need to continue
349
- is_different_user = identity.slice("entityId", "tenantId", "userId", "userProfileId") == (session["ZuoraCurrentIdentity"] || {}).slice("entityId", "tenantId", "userId", "userProfileId")
349
+ is_different_user = identity.slice("entityId", "tenantId", "userId", "userProfileId") != (session["ZuoraCurrentIdentity"] || {}).slice("entityId", "tenantId", "userId", "userProfileId")
350
350
  zuora_details["identity"]["entityId"] = identity['entityId']
351
351
  session["ZuoraCurrentIdentity"] = identity
352
352
  session["ZuoraCurrentEntity"] = identity['entityId']
@@ -408,7 +408,7 @@ module ZuoraConnect
408
408
  end
409
409
 
410
410
  # One deployed instance with credentials
411
- if defined?(@appinstance) && @appinstance['zuora_logins'].present?
411
+ if defined?(@appinstance) && !@appinstance['zuora_logins'].nil?
412
412
  #Add user/update
413
413
  begin
414
414
  @zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
@@ -632,12 +632,19 @@ module ZuoraConnect
632
632
  :id => id,
633
633
  :api_token => generate_token,
634
634
  :token => generate_token,
635
- :zuora_logins => task_data,
636
635
  :oauth_expires_at => Time.now + 1000.years,
637
636
  :zuora_domain => rest_domain,
638
637
  :zuora_entity_ids => [zuora_entity_id]
639
638
  )
640
639
 
640
+ if task_data.nil?
641
+ # no encryption
642
+ app_instance['zuora_logins'] = task_data
643
+ else
644
+ # kms encrypt
645
+ app_instance.zuora_logins = task_data
646
+ end
647
+
641
648
  begin
642
649
  app_instance.save(:validate => false)
643
650
  rescue ActiveRecord::RecordNotUnique
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.58a"
2
+ VERSION = "2.0.60b"
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: 2.0.58a
4
+ version: 2.0.60b
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-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment