healthier 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -10
- data/app/controllers/healthier/application_controller.rb +0 -7
- data/app/controllers/healthier/checks_controller.rb +14 -0
- data/lib/generators/healthier/config_generator.rb +31 -0
- data/lib/healthier/api_authenticator.rb +28 -0
- data/lib/healthier/engine.rb +1 -5
- data/lib/healthier/version.rb +1 -1
- data/lib/healthier.rb +8 -1
- metadata +4 -3
- data/app/services/basic_auth_service.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9085660c0bf98cddf325db77e9d7f7a655c34e4af17e0febcc2d0468d42a10
|
4
|
+
data.tar.gz: b4cbbda7e758b1375c07d3ff98efa31ac85a52a9ede9c67dd2a06a95c75f9103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 522eea93d714a4afe55e18f20be294674a3406915b31c858567471117aa6e9089d8a8269517efb6bd2b8c29a70d895109e1047a93c7ec68a739d856b8656d6a2
|
7
|
+
data.tar.gz: 65e6082188ace39b2013404301fa137596b501d0f301fa0679697311038217642a08e29a7b5786fb406fdecf54016d90d49e6f652e90b89a9ae101b2db29448a
|
data/README.md
CHANGED
@@ -26,23 +26,35 @@ Or install it yourself as:
|
|
26
26
|
$ gem install healthier
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
# Installer:
|
30
30
|
|
31
|
-
```
|
32
|
-
|
31
|
+
```bash
|
32
|
+
rails generate healthier:config
|
33
33
|
```
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
This will generate these two files:
|
36
|
+
1. config/healthier.yml
|
38
37
|
```yaml
|
39
38
|
---
|
40
39
|
healthier:
|
41
40
|
depends_on:
|
42
|
-
|
43
|
-
- name: '
|
44
|
-
- name: '
|
45
|
-
- name: '
|
41
|
+
# Uncomment accordingly
|
42
|
+
# - name: 'postgresql'
|
43
|
+
# - name: 'mongodb'
|
44
|
+
# - name: 'redis'
|
45
|
+
# - name: 'rabbitmq'
|
46
|
+
```
|
47
|
+
2. config/initializers/healthier.rb
|
48
|
+
```ruby
|
49
|
+
Healthier.setup do |config|
|
50
|
+
config.depends_on = config.healthier.call
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
In your application routes.rb file:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
mount Healthier::Engine => '/healthier'
|
46
58
|
```
|
47
59
|
|
48
60
|
ENVs for basic authentication:
|
@@ -3,12 +3,5 @@
|
|
3
3
|
module Healthier
|
4
4
|
# ApplicationController
|
5
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
6
|
end
|
14
7
|
end
|
@@ -3,8 +3,22 @@
|
|
3
3
|
module Healthier
|
4
4
|
# Controller for performing health checks
|
5
5
|
class ChecksController < ApplicationController
|
6
|
+
include ActionController::HttpAuthentication::Basic::ControllerMethods
|
7
|
+
|
8
|
+
before_action :authenticate_request
|
9
|
+
|
6
10
|
def ping
|
7
11
|
render json: Healthier::Engine.ping!
|
8
12
|
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def authenticate_request
|
17
|
+
api_authenticator.authenticate
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_authenticator
|
21
|
+
Healthier::ApiAuthenticator.new(self)
|
22
|
+
end
|
9
23
|
end
|
10
24
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Healthier
|
4
|
+
# Generates a healthier.yml
|
5
|
+
class ConfigGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def create_healthier_file
|
9
|
+
create_file 'config/initializers/healthier.rb', <<~RUBY
|
10
|
+
# frozen_string_literal: true
|
11
|
+
|
12
|
+
Healthier.setup do |config|
|
13
|
+
config.depends_on = config.healthier.call
|
14
|
+
end
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_healthier_yaml
|
19
|
+
create_file 'config/healthier.yml', <<~YAML
|
20
|
+
---
|
21
|
+
healthier:
|
22
|
+
# Uncomment accordingly
|
23
|
+
depends_on:
|
24
|
+
# - name: 'postgresql'
|
25
|
+
# - name: 'mongodb'
|
26
|
+
# - name: 'redis'
|
27
|
+
# - name: 'rabbitmq'
|
28
|
+
YAML
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Healthier
|
4
|
+
# Engine
|
5
|
+
class ApiAuthenticator
|
6
|
+
attr_accessor :controller
|
7
|
+
|
8
|
+
def initialize(controller)
|
9
|
+
@controller = controller
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticate
|
13
|
+
send("authenticate_with_#{Healthier.auth_mechanism}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def authenticate_with_bearer_token
|
17
|
+
controller.authenticate_with_http_token do |token, _options|
|
18
|
+
ENV['BEARER_TOKEN'] == token
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def authenticate_with_basic_auth
|
23
|
+
controller.authenticate_or_request_with_http_basic do |username, password|
|
24
|
+
username == ENV['USERNAME'] && password == ENV['PASSWORD']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/healthier/engine.rb
CHANGED
@@ -37,11 +37,7 @@ module Healthier
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def conf
|
40
|
-
@conf ||=
|
41
|
-
end
|
42
|
-
|
43
|
-
def config_path
|
44
|
-
Rails.root.join('config/healthier/services.yml')
|
40
|
+
@conf ||= Healthier.depends_on['healthier']
|
45
41
|
end
|
46
42
|
|
47
43
|
def ping_it(service)
|
data/lib/healthier/version.rb
CHANGED
data/lib/healthier.rb
CHANGED
@@ -2,8 +2,15 @@
|
|
2
2
|
|
3
3
|
require 'healthier/version'
|
4
4
|
require 'healthier/engine'
|
5
|
+
require 'healthier/api_authenticator'
|
5
6
|
|
6
7
|
# Healthier
|
7
8
|
module Healthier
|
8
|
-
|
9
|
+
def self.setup
|
10
|
+
yield self
|
11
|
+
end
|
12
|
+
|
13
|
+
mattr_accessor :healthier, default: -> { YAML.load_file(Rails.root.join('config/healthier.yml')) }
|
14
|
+
mattr_accessor :auth_mechanism, default: 'basic_auth'
|
15
|
+
mattr_accessor :depends_on, default: {}
|
9
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: healthier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nima Yonten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -36,9 +36,10 @@ files:
|
|
36
36
|
- Rakefile
|
37
37
|
- app/controllers/healthier/application_controller.rb
|
38
38
|
- app/controllers/healthier/checks_controller.rb
|
39
|
-
- app/services/basic_auth_service.rb
|
40
39
|
- config/routes.rb
|
40
|
+
- lib/generators/healthier/config_generator.rb
|
41
41
|
- lib/healthier.rb
|
42
|
+
- lib/healthier/api_authenticator.rb
|
42
43
|
- lib/healthier/engine.rb
|
43
44
|
- lib/healthier/version.rb
|
44
45
|
- lib/tasks/healthier_tasks.rake
|
@@ -1,10 +0,0 @@
|
|
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 == ENV['USERNAME'] && password == ENV['PASSWORD']
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|