zuora_connect 0 → 3.2.11
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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +219 -0
- data/Rakefile +1 -1
- data/app/assets/javascripts/hallway_wrapper/after.js +22 -3
- data/app/controllers/concerns/zuora_connect/authenticate.rb +39 -0
- data/app/controllers/zuora_connect/api/v1/app_instance_controller.rb +5 -0
- data/app/controllers/zuora_connect/application_controller.rb +37 -2
- data/app/controllers/zuora_connect/static_controller.rb +142 -27
- data/app/helpers/zuora_connect/LDAP/adapter.rb +16 -0
- data/app/helpers/zuora_connect/LDAP/connection.rb +123 -0
- data/app/helpers/zuora_connect/application_helper.rb +10 -0
- data/app/models/concerns/zuora_connect/auditable.rb +29 -0
- data/app/models/zuora_connect/app_instance_base.rb +652 -180
- data/app/models/zuora_connect/login.rb +24 -11
- data/app/models/zuora_connect/telegraf.rb +18 -38
- data/app/models/zuora_connect/zuora_user.rb +35 -0
- data/app/views/sql/refresh_aggregate_table.txt +12 -10
- data/app/views/zuora_connect/application/ldap_login.html.erb +195 -0
- data/app/views/zuora_connect/static/error_handled.html.erb +76 -0
- data/app/views/zuora_connect/static/error_handled.js.erb +1 -0
- data/app/views/zuora_connect/static/error_unhandled.erb +85 -0
- data/app/views/zuora_connect/static/error_unhandled.js.erb +1 -0
- data/app/views/zuora_connect/static/launch.html.erb +71 -76
- data/config/initializers/object_method_hooks.rb +2 -2
- data/config/initializers/patches.rb +9 -0
- data/config/initializers/postgresql_adapter.rb +119 -1
- data/config/initializers/prometheus.rb +57 -23
- data/config/initializers/redis.rb +52 -5
- data/config/initializers/resque.rb +5 -1
- data/config/initializers/unicorn.rb +30 -2
- data/config/initializers/zuora_observability.rb +24 -0
- data/config/routes.rb +8 -3
- data/db/migrate/20100718151733_create_connect_app_instances.rb +1 -1
- data/db/migrate/20101024162319_add_tokens_to_app_instance.rb +1 -1
- data/db/migrate/20101024220705_add_token_to_app_instance.rb +1 -1
- data/db/migrate/20110131211919_add_sessions_table.rb +1 -1
- data/db/migrate/20110411200303_add_expiration_to_app_instance.rb +1 -1
- data/db/migrate/20110413191512_add_new_api_token.rb +1 -1
- data/db/migrate/20110503003602_add_catalog_data_to_app_instance.rb +1 -1
- data/db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb +1 -1
- data/db/migrate/20110503003604_catalog_default.rb +1 -1
- data/db/migrate/20180301052853_add_catalog_attempted_at.rb +1 -1
- data/db/migrate/20181206162339_add_fields_to_instance.rb +1 -1
- data/db/migrate/20190520232221_add_zuora_user_table_and_alter_app_instance_id_table.rb +18 -0
- data/db/migrate/20190520232222_add_unique_index.rb +6 -0
- data/db/migrate/20190520232223_add_provisioning_fields.rb +6 -0
- data/db/migrate/20190520232224_add_environment_fields.rb +16 -0
- data/lib/metrics/net.rb +3 -3
- data/lib/middleware/json_parse_errors.rb +33 -0
- data/lib/middleware/metrics_middleware.rb +62 -68
- data/lib/middleware/request_id_middleware.rb +17 -0
- data/lib/resque/dynamic_queues.rb +35 -13
- data/lib/resque/plugins/app_instance_job.rb +63 -0
- data/lib/resque/plugins/custom_logger.rb +12 -27
- data/lib/tasks/zuora_connect_tasks.rake +0 -5
- data/lib/zuora_connect/configuration.rb +8 -4
- data/lib/zuora_connect/controllers/helpers.rb +640 -189
- data/lib/zuora_connect/engine.rb +12 -9
- data/lib/zuora_connect/exceptions.rb +18 -2
- data/lib/zuora_connect/middleware/hallway.rb +34 -0
- data/lib/zuora_connect/railtie.rb +16 -39
- data/lib/zuora_connect/version.rb +3 -1
- data/lib/zuora_connect.rb +69 -5
- metadata +146 -126
- data/app/views/zuora_connect/static/invalid_app_instance_error.html.erb +0 -65
- data/app/views/zuora_connect/static/invalid_launch_request.html +0 -65
- data/app/views/zuora_connect/static/session_error.html.erb +0 -63
- data/config/initializers/elastic_apm.rb +0 -25
- data/lib/zuora_connect/views/helpers.rb +0 -9
- data/test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb +0 -13
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -29
- data/test/dummy/config/application.rb +0 -26
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -41
- data/test/dummy/config/environments/production.rb +0 -79
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/assets.rb +0 -11
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -4
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/config.ru +0 -4
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/zuora_connect/app_instances.yml +0 -11
- data/test/integration/navigation_test.rb +0 -8
- data/test/lib/generators/zuora_connect/datatable_generator_test.rb +0 -16
- data/test/models/zuora_connect/app_instance_test.rb +0 -9
- data/test/test_helper.rb +0 -21
- data/test/zuora_connect_test.rb +0 -7
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Copied from devise lib and deleted not useful functionality
|
|
2
|
+
|
|
3
|
+
module ZuoraConnect
|
|
4
|
+
module LDAP
|
|
5
|
+
class Connection
|
|
6
|
+
attr_reader :ldap, :login
|
|
7
|
+
|
|
8
|
+
def initialize(params = {})
|
|
9
|
+
ldap_config = YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env]
|
|
10
|
+
ldap_options = params
|
|
11
|
+
|
|
12
|
+
# Allow `ssl: true` shorthand in YAML, but enable more control with `encryption`
|
|
13
|
+
ldap_config['ssl'] = :simple_tls if ldap_config['ssl'] === true
|
|
14
|
+
ldap_options[:encryption] = ldap_config['ssl'].to_sym if ldap_config['ssl']
|
|
15
|
+
ldap_options[:encryption] = ldap_config['encryption'] if ldap_config['encryption']
|
|
16
|
+
|
|
17
|
+
@ldap = Net::LDAP.new(ldap_options)
|
|
18
|
+
@ldap.host = ldap_config['host']
|
|
19
|
+
@ldap.port = ldap_config['port']
|
|
20
|
+
@ldap.base = ldap_config['base']
|
|
21
|
+
@attribute = ldap_config['attribute']
|
|
22
|
+
@allow_unauthenticated_bind = ldap_config['allow_unauthenticated_bind']
|
|
23
|
+
|
|
24
|
+
@ldap_auth_username_builder = params[:ldap_auth_username_builder]
|
|
25
|
+
|
|
26
|
+
@group_base = ldap_config['group_base']
|
|
27
|
+
@check_group_membership = ldap_config.key?('check_group_membership') ? ldap_config['check_group_membership'] : false
|
|
28
|
+
@check_group_membership_without_admin = ldap_config.key?('check_group_membership_without_admin') ? ldap_config['check_group_membership_without_admin'] : false
|
|
29
|
+
@required_groups = ldap_config['required_groups']
|
|
30
|
+
@group_membership_attribute = ldap_config.key?('group_membership_attribute') ? ldap_config['group_membership_attribute'] : 'uniqueMember'
|
|
31
|
+
@required_attributes = ldap_config['require_attribute']
|
|
32
|
+
@required_attributes_presence = ldap_config['require_attribute_presence']
|
|
33
|
+
|
|
34
|
+
@ldap.auth ldap_config['admin_user'], ldap_config['admin_password'] if params[:admin]
|
|
35
|
+
|
|
36
|
+
@login = params[:login]
|
|
37
|
+
@password = params[:password]
|
|
38
|
+
@new_password = params[:new_password]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def dn
|
|
42
|
+
@dn ||= begin
|
|
43
|
+
ZuoraConnect::logger.debug("LDAP dn lookup: #{@attribute}=#{@login}")
|
|
44
|
+
ldap_entry = search_for_login
|
|
45
|
+
if ldap_entry.nil?
|
|
46
|
+
@ldap_auth_username_builder.call(@attribute,@login,@ldap)
|
|
47
|
+
else
|
|
48
|
+
ldap_entry.dn
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def search_for_login
|
|
54
|
+
@login_ldap_entry ||= begin
|
|
55
|
+
ZuoraConnect::logger.debug("LDAP search for login: #{@attribute}=#{@login}")
|
|
56
|
+
filter = Net::LDAP::Filter.eq(@attribute.to_s, @login.to_s)
|
|
57
|
+
ldap_entry = nil
|
|
58
|
+
match_count = 0
|
|
59
|
+
@ldap.search(:filter => filter) {|entry| ldap_entry = entry; match_count+=1}
|
|
60
|
+
op_result= @ldap.get_operation_result
|
|
61
|
+
if op_result.code!=0
|
|
62
|
+
ZuoraConnect::logger.debug("LDAP Error #{op_result.code}: #{op_result.message}")
|
|
63
|
+
end
|
|
64
|
+
ZuoraConnect::logger.debug("LDAP search yielded #{match_count} matches")
|
|
65
|
+
ldap_entry
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def authenticate!
|
|
70
|
+
return false unless @password.present? || @allow_unauthenticated_bind
|
|
71
|
+
@ldap.auth(dn, @password)
|
|
72
|
+
@ldap.bind
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def authenticated?
|
|
76
|
+
authenticate!
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def last_message_bad_credentials?
|
|
80
|
+
@ldap.get_operation_result.error_message.to_s.include? 'AcceptSecurityContext error, data 52e'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def last_message_expired_credentials?
|
|
84
|
+
@ldap.get_operation_result.error_message.to_s.include? 'AcceptSecurityContext error, data 773'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def authorized?
|
|
88
|
+
ZuoraConnect::logger.debug("Authorizing user #{dn}")
|
|
89
|
+
if !authenticated?
|
|
90
|
+
if last_message_bad_credentials?
|
|
91
|
+
ZuoraConnect::logger.debug('Not authorized because of invalid credentials.')
|
|
92
|
+
elsif last_message_expired_credentials?
|
|
93
|
+
ZuoraConnect::logger.debug('Not authorized because of expired credentials.')
|
|
94
|
+
else
|
|
95
|
+
ZuoraConnect::logger.debug('Not authorized because not authenticated.')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
false
|
|
99
|
+
elsif !in_required_groups?
|
|
100
|
+
ZuoraConnect::logger.debug('Not authorized because not in required groups.')
|
|
101
|
+
false
|
|
102
|
+
else
|
|
103
|
+
true
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def in_required_groups?
|
|
108
|
+
return true unless @check_group_membership || @check_group_membership_without_admin
|
|
109
|
+
|
|
110
|
+
return false if @required_groups.nil?
|
|
111
|
+
|
|
112
|
+
@required_groups.each do |group|
|
|
113
|
+
if group.is_a?(Array)
|
|
114
|
+
return false unless in_group?(group[1], group[0])
|
|
115
|
+
else
|
|
116
|
+
return false unless in_group?(group)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
true
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
module ZuoraConnect
|
|
2
2
|
module ApplicationHelper
|
|
3
|
+
def is_app_admin?
|
|
4
|
+
return @appinstance.blank? ? false : session["#{@appinstance.id}::admin"] || @appinstance.zuora_tenant_ids.include?("9")
|
|
5
|
+
end
|
|
3
6
|
|
|
7
|
+
def zuora_user
|
|
8
|
+
return @zuora_user
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def connect_meta_tags
|
|
12
|
+
"<meta name=\"z-hallway-prefix\" content=\"#{ Thread.current[:isHallway] }\">".html_safe
|
|
13
|
+
end
|
|
4
14
|
end
|
|
5
15
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ZuoraConnect
|
|
4
|
+
# Added by @Vina
|
|
5
|
+
# Description: This automatically stamp user created/updated the record for DataQuery Audit
|
|
6
|
+
# Usage: add 'include ZuoraConnect::Auditable' to your model.rb that you would like to track
|
|
7
|
+
module Auditable
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
before_create :set_created_by_id
|
|
12
|
+
before_update :set_updated_by_id
|
|
13
|
+
before_destroy :set_updated_by_id
|
|
14
|
+
|
|
15
|
+
belongs_to :updated_by, class_name: 'ZuoraConnect::ZuoraUser', foreign_key: 'updated_by_id', primary_key: "zuora_user_id", optional: true
|
|
16
|
+
belongs_to :created_by, class_name: 'ZuoraConnect::ZuoraUser', foreign_key: 'created_by_id', primary_key: "zuora_user_id", optional: true
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def set_created_by_id
|
|
21
|
+
self.created_by_id = ZuoraUser.current_user_id if defined?(created_by_id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def set_updated_by_id
|
|
25
|
+
self.updated_by_id = ZuoraUser.current_user_id if defined?(updated_by_id)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|