healthier 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6edf83e9f94bfec7c31425fb9da3271736b0e088abffcf6075b51e9b3384776
4
+ data.tar.gz: 6a61b806971ab5aaea9684f8b5e29bfadd16ad60c7a4106ff1406863e6ef9278
5
+ SHA512:
6
+ metadata.gz: dbdca601bebf47f6a3e8002d9cb0194bf19269a9f17f6a5833f72922fc371775a34ff018d7c30530ac8318c0bdcb3a914ef8a66c6c2d4eff4f56285faef8bd59
7
+ data.tar.gz: b205cd863d5c0cadadcdab264d893e5c489aa65e37e6c5399041894cc645832e077d279231ff6a5d7b2fc1daeb58da270571008257e67ab92003893da3f0de33
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2023 Nima Yonten
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Healthier
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "healthier"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install healthier
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
+
8
+ load 'rails/tasks/statistics.rake'
9
+
10
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthier
4
+ # ApplicationController
5
+ class ApplicationController < ActionController::Base
6
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
7
+
8
+ before_action :authenticate_request
9
+
10
+ def authenticate_request
11
+ BasicAuthService.authorize(self)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthier
4
+ # Controller for performing health checks
5
+ class ChecksController < ApplicationController
6
+ def ping
7
+ render json: Healthier::Engine.ping!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module authenticates the API with Basic Auth
4
+ class BasicAuthService
5
+ def self.authorize(controller)
6
+ controller.authenticate_or_request_with_http_basic do |username, password|
7
+ username == 'healthier' && password == 'Selise23'
8
+ end
9
+ end
10
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Healthier::Engine.routes.draw do
4
+ get 'ping', to: 'checks#ping'
5
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthier
4
+ # Engine
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Healthier
7
+
8
+ PING_CONF = HashWithIndifferentAccess.new(
9
+ {
10
+ postgresql: {
11
+ pinger: -> { ActiveRecord::Base.connection },
12
+ message: 'PostgreSQL service is not running. Please check your connection'
13
+ },
14
+ mongodb: {
15
+ pinger: -> { Mongoid.default_client.command(ping: 1) },
16
+ message: 'MongoDB service is not running. Please check your connection'
17
+ },
18
+ redis: {
19
+ pinger: -> { Redis.new },
20
+ message: 'Redis service is not running. Please check your connection'
21
+ },
22
+ rabbitmq: {
23
+ pinger: -> { Bunny.new },
24
+ message: 'RabbitMQ service is not running. Please check your connection'
25
+ }
26
+ }
27
+ )
28
+
29
+ # TODO: Refactor this whole code
30
+ SUCCESS = 200
31
+ FAILURE = 400
32
+
33
+ def ping!
34
+ conf['depends_on'].each_with_object({}) do |service, obj|
35
+ obj[service['name']] = ping_it(service['name'])
36
+ end
37
+ end
38
+
39
+ def conf
40
+ @conf ||= YAML.load_file(config_path)['healthier']
41
+ end
42
+
43
+ def config_path
44
+ Rails.root.join('config/healthier/services.yml')
45
+ end
46
+
47
+ def ping_it(service)
48
+ return { status: SUCCESS, message: 'pong' } if PING_CONF[service]['pinger'].call
49
+
50
+ { status: FAILURE, message: PING_CONF[service]['message'] }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthier
4
+ # MAJOR.MINOR.PATCH
5
+ VERSION = '0.1.2'
6
+ end
data/lib/healthier.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'healthier/version'
4
+ require 'healthier/engine'
5
+
6
+ # Healthier
7
+ module Healthier
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :healthier do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: healthier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Nima Yonten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ description: Description of Healthier.
28
+ email:
29
+ - 92887110+unimafy@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/controllers/healthier/application_controller.rb
38
+ - app/controllers/healthier/checks_controller.rb
39
+ - app/services/basic_auth_service.rb
40
+ - config/routes.rb
41
+ - lib/healthier.rb
42
+ - lib/healthier/engine.rb
43
+ - lib/healthier/version.rb
44
+ - lib/tasks/healthier_tasks.rake
45
+ homepage: https://github.com/selisebt/healthier
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ allowed_push_host: https://rubygems.org
50
+ homepage_uri: https://github.com/selisebt/healthier
51
+ source_code_uri: https://github.com/selisebt/healthier
52
+ changelog_uri: https://github.com/selisebt/healthier
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.7
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.4.10
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Summary of Healthier.
72
+ test_files: []