health_check_toolbox 1.0.1

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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +84 -0
  3. data/Rakefile +6 -0
  4. data/config/locales/en.yml +6 -0
  5. data/config/routes.rb +3 -0
  6. data/lib/health_check_toolbox.rb +19 -0
  7. data/lib/health_check_toolbox/config.rb +39 -0
  8. data/lib/health_check_toolbox/engine.rb +6 -0
  9. data/lib/health_check_toolbox/health_check_routes.rb +15 -0
  10. data/lib/health_check_toolbox/health_controller.rb +18 -0
  11. data/lib/health_check_toolbox/services/base_health_check.rb +21 -0
  12. data/lib/health_check_toolbox/services/database.rb +22 -0
  13. data/lib/health_check_toolbox/services/redis_service.rb +21 -0
  14. data/lib/health_check_toolbox/services/rest_services.rb +74 -0
  15. data/lib/health_check_toolbox/services/wso2.rb +21 -0
  16. data/lib/health_check_toolbox/status_manager.rb +49 -0
  17. data/lib/health_check_toolbox/version.rb +5 -0
  18. data/spec/dummy/Rakefile +9 -0
  19. data/spec/dummy/bin/bundle +5 -0
  20. data/spec/dummy/bin/rails +6 -0
  21. data/spec/dummy/bin/rake +6 -0
  22. data/spec/dummy/bin/setup +37 -0
  23. data/spec/dummy/bin/update +32 -0
  24. data/spec/dummy/bin/yarn +13 -0
  25. data/spec/dummy/config.ru +7 -0
  26. data/spec/dummy/config/application.rb +14 -0
  27. data/spec/dummy/config/boot.rb +7 -0
  28. data/spec/dummy/config/cable.yml +10 -0
  29. data/spec/dummy/config/database.yml +16 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +32 -0
  32. data/spec/dummy/config/environments/production.rb +26 -0
  33. data/spec/dummy/config/environments/test.rb +25 -0
  34. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  35. data/spec/dummy/config/initializers/assets.rb +5 -0
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  37. data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
  38. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
  40. data/spec/dummy/config/initializers/inflections.rb +1 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +5 -0
  43. data/spec/dummy/config/puma.rb +10 -0
  44. data/spec/dummy/config/routes.rb +4 -0
  45. data/spec/dummy/config/spring.rb +8 -0
  46. data/spec/dummy/config/storage.yml +8 -0
  47. data/spec/dummy/package.json +5 -0
  48. data/spec/health_check_toolbox/config_spec.rb +87 -0
  49. data/spec/health_check_toolbox/health_controller_spec.rb +47 -0
  50. data/spec/health_check_toolbox/services/database_spec.rb +19 -0
  51. data/spec/health_check_toolbox/services/redis_service_spec.rb +27 -0
  52. data/spec/health_check_toolbox/services/rest_services_spec.rb +45 -0
  53. data/spec/health_check_toolbox/services/wso2_spec.rb +26 -0
  54. data/spec/health_check_toolbox/status_manager_spec.rb +78 -0
  55. data/spec/health_check_toolbox_spec.rb +22 -0
  56. data/spec/spec_helper.rb +20 -0
  57. metadata +263 -0
@@ -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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+ require_relative '../config/boot'
6
+ require 'rails/commands'
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../config/boot'
5
+ require 'rake'
6
+ Rake.application.run
@@ -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
@@ -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
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require_relative 'config/environment'
6
+
7
+ run Rails.application
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ require 'rails/all'
6
+
7
+ Bundler.require(*Rails.groups)
8
+ require 'health_check_toolbox'
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ config.load_defaults 5.2
13
+ end
14
+ 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,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: dummy_production
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'application'
4
+
5
+ Rails.application.initialize!
@@ -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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # ActiveSupport::Reloader.to_prepare do
6
+ # ApplicationController.renderer.defaults.merge!(
7
+ # http_host: 'example.org',
8
+ # https: false
9
+ # )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.config.assets.version = '1.0'
4
+
5
+ Rails.application.config.assets.paths << Rails.root.join('node_modules')
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveSupport.on_load(:action_controller) do
4
+ wrap_parameters format: [:json]
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
4
+ threads threads_count, threads_count
5
+
6
+ port ENV.fetch('PORT') { 3000 }
7
+
8
+ environment ENV.fetch('RAILS_ENV') { 'development' }
9
+
10
+ plugin :tmp_restart
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ .ruby-version
5
+ .rbenv-vars
6
+ tmp/restart.txt
7
+ tmp/caching-dev.txt
8
+ ].each { |path| Spring.watch(path) }
@@ -0,0 +1,8 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "dummy",
3
+ "private": true,
4
+ "dependencies": {}
5
+ }
@@ -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