zuora_connect 3.1.1 → 3.1.3

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: 5eedfed1cc9d304e303303bbda985be007df987f6c50c8cebf4bef6ee2f630a2
4
- data.tar.gz: 77bbf5a323c63814cb50521ffd244c601b40e3f5c07bc8208f9996b83fe5090e
3
+ metadata.gz: 669d11bc2e10ece9fb5f4d014b412739545cf7d17c6858b0588f8d6c566be41e
4
+ data.tar.gz: a077b09e7c4e5e3bdb10742c99100a11842d6d5bb31ca520a97d44c8e9ac51c0
5
5
  SHA512:
6
- metadata.gz: 519cf6f3002ff33a5849e297e74ccd7a541a9677fdbf28e7481848d3ef74f2521555c129fa215db87dc5565fa7c0afa4ea3ce19c6555ad0bec8878fe41d48d78
7
- data.tar.gz: 6db95ad4869e55739c648492a830054c8f59b574a6ddabf80b8de24ff1e67356e7df492fcf742a6afea5bb65f34f215252dd2466d5c264578c5c0cd224866fe4
6
+ metadata.gz: b043fa5b788040e781843eb2c2f20aba5a7b2d1f8d014e89ac31aa3574a451473dd1d89a08d479f71215f6f386d288e5fdb315316fcf31de8121d39224778d7c
7
+ data.tar.gz: f151cb64ecddc869299c25f9a1012601ededb097e469fd86a060ca0c8b82e074559df24724600880a8afea9f3995550c9c504af311d1e24248fbdcfaa6013197
@@ -1,11 +1,11 @@
1
1
  module ZuoraConnect
2
2
  class StaticController < ApplicationController
3
- before_action :authenticate_connect_app_request, :except => [:health, :initialize_app, :provision, :instance_user]
4
- before_action :clear_connect_app_session, :only => [:health, :initialize_app, :provision, :instance_user]
5
- after_action :persist_connect_app_session, :except => [:health, :initialize_app, :provision, :instance_user]
3
+ before_action :authenticate_connect_app_request, :except => [:health, :initialize_app, :provision, :instance_user, :instance_drop]
4
+ before_action :clear_connect_app_session, :only => [:health, :initialize_app, :provision, :instance_user, :instance_drop]
5
+ after_action :persist_connect_app_session, :except => [:health, :initialize_app, :provision, :instance_user, :instance_drop]
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, :instance_user]
8
+ http_basic_authenticate_with name: ENV['PROVISION_USER'], password: ENV['PROVISION_SECRET'], :only => [:provision, :instance_user, :instance_drop]
9
9
 
10
10
 
11
11
  def health
@@ -119,6 +119,40 @@ module ZuoraConnect
119
119
  }, status: 500
120
120
  end
121
121
 
122
+ def instance_drop
123
+ ZuoraConnect::AppInstance.read_master_db do
124
+ instance_id = params[:id]
125
+ @appinstance = ZuoraConnect::AppInstance.find(instance_id)
126
+ if @appinstance.drop_instance
127
+ ZuoraConnect::AppInstance.destroy(instance_id)
128
+ msg = Apartment::Tenant.drop(instance_id)
129
+
130
+ if msg.error_message.present?
131
+ render json: { "message" => msg.error_message }, status: :bad_request
132
+ else
133
+ render json: {
134
+ status: 200,
135
+ message: 'Success',
136
+ app_instance_id: instance_id
137
+ }, status: 200
138
+ end
139
+ else
140
+ render json: { "message" => @appinstance.drop_message }, status: :bad_request
141
+ end
142
+ end
143
+ rescue StandardError => e
144
+ message = 'Failed to drop instance'
145
+ if performed?
146
+ Rails.logger.error("#{message}: #{performed?}", e)
147
+ else
148
+ Rails.logger.error(message, e)
149
+ render json: {
150
+ status: 500,
151
+ message: message
152
+ }, status: 500
153
+ end
154
+ end
155
+
122
156
  private
123
157
 
124
158
  def clear_connect_app_session
@@ -353,8 +353,10 @@ module ZuoraConnect
353
353
  end
354
354
 
355
355
  def fetch_connect_data(session: {})
356
+ refresh_count ||= 0
356
357
  self.check_oauth_state
357
- response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
358
+ request_url = ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json"
359
+ response = HTTParty.get(request_url,:body => {:access_token => self.access_token})
358
360
 
359
361
  if response.code == 200
360
362
  begin
@@ -367,45 +369,43 @@ module ZuoraConnect
367
369
  self.set_backup_creds
368
370
  self.save(validate: false) if self.changed?
369
371
  else
370
- raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
372
+ raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error communicating with Connect for '#{request_url}' with #{response.code}", response.body, response.code)
373
+ end
374
+ rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
375
+ refresh_count += 1
376
+ if refresh_count < 3
377
+ sleep(10)
378
+ ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
379
+ retry
380
+ else
381
+ ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex)
382
+ raise
383
+ end
384
+ rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
385
+ refresh_count += 1
386
+ if refresh_count < 3
387
+ ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
388
+ self.refresh_oauth if ex.code == 401
389
+ retry
390
+ else
391
+ ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex, self.default_ougai_items)
392
+ raise
371
393
  end
372
394
  end
373
395
 
374
-
375
396
  def refresh(session: {})
376
397
  refresh_count ||= 0
377
398
  skip_connect ||= ZuoraConnect.configuration.skip_connect
378
- begin
379
- #Check how app was deployed
380
- if !self.auto_deployed? && (!skip_connect || self['zuora_logins'].blank?)
381
- self.fetch_connect_data(session: session)
382
- else
383
- self.build_task(task_data: self.zuora_logins, session: session)
384
- end
385
- self.last_refresh = Time.now.to_i
386
- self.cache_app_instance
387
- self.reset_mark_for_refresh
388
- rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
389
- refresh_count += 1
390
- if refresh_count < 3
391
- sleep(10)
392
- ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
393
- retry
394
- else
395
- ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex)
396
- raise
397
- end
398
- rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
399
- refresh_count += 1
400
- if refresh_count < 3
401
- ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
402
- self.refresh_oauth if ex.code == 401
403
- retry
404
- else
405
- ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex, self.default_ougai_items)
406
- raise
407
- end
399
+ #Check how app was deployed
400
+ if !self.auto_deployed? && (!skip_connect || self['zuora_logins'].blank?)
401
+ self.fetch_connect_data(session: session)
402
+ else
403
+ self.build_task(task_data: self.zuora_logins, session: session)
408
404
  end
405
+ self.last_refresh = Time.now.to_i
406
+ self.cache_app_instance
407
+ self.reset_mark_for_refresh
408
+
409
409
  rescue => ex
410
410
  refresh_count += 1
411
411
  if self['zuora_logins'].present? && refresh_count < 3
data/config/routes.rb CHANGED
@@ -4,6 +4,7 @@ ZuoraConnect::Engine.routes.draw do
4
4
 
5
5
  if ENV['PROVISION_USER'].present? && ENV['PROVISION_SECRET'].present?
6
6
  post '/provision' => 'static#provision'
7
+ post '/instance/:id/drop' => 'static#instance_drop'
7
8
  get '/instance/:id/user' => 'static#instance_user'
8
9
  end
9
10
 
@@ -42,7 +42,7 @@ module ZuoraConnect
42
42
  end
43
43
 
44
44
  def call(env)
45
- @bad_headers = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_SCHEME", "HTTP_X_FORWARDED_SSL"]
45
+ @bad_headers = ["HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_SCHEME", "HTTP_X_FORWARDED_SSL"]
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
@@ -2,15 +2,18 @@ namespace :db do
2
2
  desc 'Also create shared_extensions Schema'
3
3
  task :extensions => :environment do
4
4
  # Create Schema
5
- at_exit {
6
- ActiveRecord::Base.connection.execute 'CREATE SCHEMA IF NOT EXISTS shared_extensions;'
7
- # Enable Hstore
8
- ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS HSTORE SCHEMA shared_extensions;'
9
- # Enable UUID-OSSP
10
- ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;'
11
- }
5
+ ActiveRecord::Base.connection.execute 'CREATE SCHEMA IF NOT EXISTS shared_extensions;'
6
+ # Enable Hstore
7
+ ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS HSTORE SCHEMA shared_extensions;'
8
+ # Enable UUID-OSSP
9
+ ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;'
12
10
  end
13
11
  end
14
12
 
15
- Rake::Task["db:create"].enhance [:extensions]
16
- Rake::Task["db:test:purge"].enhance [:extensions]
13
+ Rake::Task["db:create"].enhance do
14
+ Rake::Task["db:extensions"].invoke
15
+ end
16
+
17
+ Rake::Task["db:test:purge"].enhance do
18
+ Rake::Task["db:extensions"].invoke
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZuoraConnect
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.3"
5
5
  end
data/lib/zuora_connect.rb CHANGED
@@ -65,13 +65,15 @@ module ZuoraConnect
65
65
  case Rails.env.to_s
66
66
  when 'production'
67
67
  defaults = {
68
- server_url: "http://apm-server.logging:8200",
68
+ server_url: "https://apm-server.logging.svc.cluster.local:8200",
69
+ secret_token:'afhfkulsahgcanriu2c7n8638w59cb67572YCAFAF38839095253',
69
70
  transaction_sample_rate: 0.20,
70
71
  capture_body: 'errors'
71
72
  }
72
73
  when 'staging'
73
74
  defaults = {
74
- server_url: "http://apm-server.logging:8200",
75
+ server_url: "https://apm-server.logging.svc.cluster.local:8200",
76
+ secret_token:'afhfkulsahgcanriu2c7n8638w59cb67572YCAFAF38839095253',
75
77
  transaction_sample_rate: 1.0
76
78
  }
77
79
  when 'development'
@@ -90,9 +92,10 @@ module ZuoraConnect
90
92
  disable_start_message: true,
91
93
  pool_size: 1,
92
94
  transaction_max_spans: 500,
93
- transaction_ignore_urls: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'],
95
+ ignore_url_patterns: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'],
94
96
  verify_server_cert: false,
95
- log_level: Logger::INFO,
97
+ log_level: Logger::WARN,
98
+ service_version: ENV['Z_APPLICATION_VERSION'].present? ? ENV['Z_APPLICATION_VERSION'] : '0.0.0',
96
99
  service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : ZuoraConnect.app_name,
97
100
  logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: Logger::WARN)
98
101
  })
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.1.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-06 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment