healthier 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 711f2ef8a3f208c3e4a4cc710fc86f73ff049a1734e0726caca32ef2d3c597f0
4
- data.tar.gz: ceb81192506fb5d7132840da224ac48bdb6f31d216dc2867da3d2afca0bd5576
3
+ metadata.gz: 9b9085660c0bf98cddf325db77e9d7f7a655c34e4af17e0febcc2d0468d42a10
4
+ data.tar.gz: b4cbbda7e758b1375c07d3ff98efa31ac85a52a9ede9c67dd2a06a95c75f9103
5
5
  SHA512:
6
- metadata.gz: 4c2b4a07809bdb88f6bd292ba9b284c5b6612ca525c0929341d4757aa01a6b98a56c3c0e60a160859e8e1b93d7c41cf13dfe9f1946997ec038b15d46b3516b8f
7
- data.tar.gz: 8b260ec426e1544f745843ede0eaa38719aa08dd75636aa6a839a65412b7308d8bc2f0a90eba950779b76571d6b8117b9cb73de389861f24f6307fe335cc4731
6
+ metadata.gz: 522eea93d714a4afe55e18f20be294674a3406915b31c858567471117aa6e9089d8a8269517efb6bd2b8c29a70d895109e1047a93c7ec68a739d856b8656d6a2
7
+ data.tar.gz: 65e6082188ace39b2013404301fa137596b501d0f301fa0679697311038217642a08e29a7b5786fb406fdecf54016d90d49e6f652e90b89a9ae101b2db29448a
@@ -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,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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Healthier
4
4
  # MAJOR.MINOR.PATCH
5
- VERSION = '0.1.4'
5
+ VERSION = '0.1.5'
6
6
  end
data/lib/healthier.rb CHANGED
@@ -2,6 +2,7 @@
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
@@ -10,5 +11,6 @@ module Healthier
10
11
  end
11
12
 
12
13
  mattr_accessor :healthier, default: -> { YAML.load_file(Rails.root.join('config/healthier.yml')) }
14
+ mattr_accessor :auth_mechanism, default: 'basic_auth'
13
15
  mattr_accessor :depends_on, default: {}
14
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
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-04-10 00:00:00.000000000 Z
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,10 +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
41
40
  - lib/generators/healthier/config_generator.rb
42
41
  - lib/healthier.rb
42
+ - lib/healthier/api_authenticator.rb
43
43
  - lib/healthier/engine.rb
44
44
  - lib/healthier/version.rb
45
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