health_check_toolbox 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +3 -0
- data/lib/health_check_toolbox.rb +19 -0
- data/lib/health_check_toolbox/config.rb +39 -0
- data/lib/health_check_toolbox/engine.rb +6 -0
- data/lib/health_check_toolbox/health_check_routes.rb +15 -0
- data/lib/health_check_toolbox/health_controller.rb +18 -0
- data/lib/health_check_toolbox/services/base_health_check.rb +21 -0
- data/lib/health_check_toolbox/services/database.rb +22 -0
- data/lib/health_check_toolbox/services/redis_service.rb +21 -0
- data/lib/health_check_toolbox/services/rest_services.rb +74 -0
- data/lib/health_check_toolbox/services/wso2.rb +21 -0
- data/lib/health_check_toolbox/status_manager.rb +49 -0
- data/lib/health_check_toolbox/version.rb +5 -0
- data/spec/dummy/Rakefile +9 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +37 -0
- data/spec/dummy/bin/update +32 -0
- data/spec/dummy/bin/yarn +13 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +16 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +32 -0
- data/spec/dummy/config/environments/production.rb +26 -0
- data/spec/dummy/config/environments/test.rb +25 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/assets.rb +5 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -0
- data/spec/dummy/config/puma.rb +10 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +8 -0
- data/spec/dummy/package.json +5 -0
- data/spec/health_check_toolbox/config_spec.rb +87 -0
- data/spec/health_check_toolbox/health_controller_spec.rb +47 -0
- data/spec/health_check_toolbox/services/database_spec.rb +19 -0
- data/spec/health_check_toolbox/services/redis_service_spec.rb +27 -0
- data/spec/health_check_toolbox/services/rest_services_spec.rb +45 -0
- data/spec/health_check_toolbox/services/wso2_spec.rb +26 -0
- data/spec/health_check_toolbox/status_manager_spec.rb +78 -0
- data/spec/health_check_toolbox_spec.rb +22 -0
- data/spec/spec_helper.rb +20 -0
- metadata +263 -0
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
4
|
+
# for example lib/tasks/capistrano.rake, and they will automatically
|
5
|
+
# be available to Rake.
|
6
|
+
|
7
|
+
require_relative 'config/application'
|
8
|
+
|
9
|
+
Rails.application.load_tasks
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a starting point to setup your application.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# Install JavaScript dependencies if using Yarn
|
22
|
+
# system('bin/yarn')
|
23
|
+
|
24
|
+
# puts "\n== Copying sample files =="
|
25
|
+
# unless File.exist?('config/database.yml')
|
26
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
27
|
+
# end
|
28
|
+
|
29
|
+
puts "\n== Preparing database =="
|
30
|
+
system! 'bin/rails db:setup'
|
31
|
+
|
32
|
+
puts "\n== Removing old logs and tempfiles =="
|
33
|
+
system! 'bin/rails log:clear tmp:clear'
|
34
|
+
|
35
|
+
puts "\n== Restarting application server =="
|
36
|
+
system! 'bin/rails restart'
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a way to update your development environment automatically.
|
15
|
+
# Add necessary update steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# Install JavaScript dependencies if using Yarn
|
22
|
+
# system('bin/yarn')
|
23
|
+
|
24
|
+
puts "\n== Updating database =="
|
25
|
+
system! 'bin/rails db:migrate'
|
26
|
+
|
27
|
+
puts "\n== Removing old logs and tempfiles =="
|
28
|
+
system! 'bin/rails log:clear tmp:clear'
|
29
|
+
|
30
|
+
puts "\n== Restarting application server =="
|
31
|
+
system! 'bin/rails restart'
|
32
|
+
end
|
data/spec/dummy/bin/yarn
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
5
|
+
Dir.chdir(APP_ROOT) do
|
6
|
+
begin
|
7
|
+
exec 'yarnpkg', *ARGV
|
8
|
+
rescue Errno::ENOENT
|
9
|
+
warn 'Yarn executable was not detected in the system.'
|
10
|
+
warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
5
|
+
|
6
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
7
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: sqlite3
|
3
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
4
|
+
timeout: 5000
|
5
|
+
|
6
|
+
development:
|
7
|
+
<<: *default
|
8
|
+
database: db/development.sqlite3
|
9
|
+
|
10
|
+
test:
|
11
|
+
<<: *default
|
12
|
+
database: db/test.sqlite3
|
13
|
+
|
14
|
+
production:
|
15
|
+
<<: *default
|
16
|
+
database: db/production.sqlite3
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
config.cache_classes = false
|
5
|
+
config.eager_load = false
|
6
|
+
config.consider_all_requests_local = true
|
7
|
+
|
8
|
+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
config.cache_store = :memory_store
|
12
|
+
config.public_file_server.headers = {
|
13
|
+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
14
|
+
}
|
15
|
+
else
|
16
|
+
config.action_controller.perform_caching = false
|
17
|
+
|
18
|
+
config.cache_store = :null_store
|
19
|
+
end
|
20
|
+
|
21
|
+
config.active_storage.service = :local
|
22
|
+
|
23
|
+
config.action_mailer.raise_delivery_errors = false
|
24
|
+
|
25
|
+
config.action_mailer.perform_caching = false
|
26
|
+
|
27
|
+
config.active_record.migration_error = :page_load
|
28
|
+
|
29
|
+
config.assets.debug = true
|
30
|
+
|
31
|
+
config.assets.quiet = true
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
config.cache_classes = true
|
5
|
+
|
6
|
+
config.eager_load = true
|
7
|
+
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
12
|
+
|
13
|
+
config.assets.js_compressor = :uglifier
|
14
|
+
|
15
|
+
config.assets.compile = false
|
16
|
+
|
17
|
+
config.active_storage.service = :local
|
18
|
+
|
19
|
+
config.action_mailer.perform_caching = false
|
20
|
+
|
21
|
+
config.i18n.fallbacks = true
|
22
|
+
|
23
|
+
config.active_support.deprecation = :notify
|
24
|
+
|
25
|
+
config.active_record.dump_schema_after_migration = false
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
config.cache_classes = true
|
5
|
+
config.eager_load = false
|
6
|
+
config.public_file_server.enabled = true
|
7
|
+
config.public_file_server.headers = {
|
8
|
+
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
|
9
|
+
}
|
10
|
+
|
11
|
+
config.consider_all_requests_local = true
|
12
|
+
config.action_controller.perform_caching = false
|
13
|
+
|
14
|
+
config.action_dispatch.show_exceptions = false
|
15
|
+
|
16
|
+
config.action_controller.allow_forgery_protection = false
|
17
|
+
|
18
|
+
config.active_storage.service = :test
|
19
|
+
|
20
|
+
config.action_mailer.perform_caching = false
|
21
|
+
|
22
|
+
config.action_mailer.delivery_method = :test
|
23
|
+
|
24
|
+
config.active_support.deprecation = :stderr
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe HealthCheckToolbox::Config do
|
6
|
+
let(:config) { described_class.new(&block) }
|
7
|
+
|
8
|
+
context 'when config block is valid' do
|
9
|
+
let(:block) do
|
10
|
+
proc do
|
11
|
+
redis_service true
|
12
|
+
database true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before { config.instance_eval(&block) }
|
17
|
+
|
18
|
+
after { described_class.services = [] }
|
19
|
+
|
20
|
+
describe '.services' do
|
21
|
+
subject(:services) { described_class.services }
|
22
|
+
|
23
|
+
it do
|
24
|
+
expect(services.first).
|
25
|
+
to be_instance_of(HealthCheckToolbox::Services::RedisService)
|
26
|
+
end
|
27
|
+
it do
|
28
|
+
expect(services.first.args).to eq([true])
|
29
|
+
end
|
30
|
+
it { expect(services.first.block).to be_nil }
|
31
|
+
|
32
|
+
it do
|
33
|
+
expect(services.last).
|
34
|
+
to be_instance_of(HealthCheckToolbox::Services::Database)
|
35
|
+
end
|
36
|
+
it { expect(services.last.args).to eq([true]) }
|
37
|
+
it { expect(services.last.block).to be_nil }
|
38
|
+
|
39
|
+
context 'with rest_services block' do
|
40
|
+
let(:block) do
|
41
|
+
proc do
|
42
|
+
redis_service true
|
43
|
+
database true
|
44
|
+
wso2 true
|
45
|
+
rest_services do
|
46
|
+
file_storage_service 'http://file_storage/2.0.0'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it do
|
52
|
+
expect(services.last).
|
53
|
+
to be_instance_of(HealthCheckToolbox::Services::RestServices)
|
54
|
+
end
|
55
|
+
it { expect(services.last.args).to be_empty }
|
56
|
+
it { expect(services.last.block).to be_instance_of(Proc) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.services_status' do
|
61
|
+
let(:status_response) do
|
62
|
+
{
|
63
|
+
'status_1' => 'redis_service:ok',
|
64
|
+
'status_2' => 'database:ok'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
before do
|
69
|
+
allow(HealthCheckToolbox::StatusManager).
|
70
|
+
to receive(:generate).and_return(status_response)
|
71
|
+
end
|
72
|
+
|
73
|
+
subject(:status) { described_class.services_status }
|
74
|
+
|
75
|
+
it { expect(status['status_1']).to eq('redis_service:ok') }
|
76
|
+
it { expect(status['status_2']).to eq('database:ok') }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when config block is invalid' do
|
81
|
+
let(:block) { proc { asdf true } }
|
82
|
+
|
83
|
+
it do
|
84
|
+
expect { config.instance_eval(&block) }.to raise_error(NoMethodError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|