healthier 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eecccdf413d2d1d9f36ad797d3cbaae04f6e7d8e4dd4b625e45e87968005942b
4
- data.tar.gz: 6b36f60acf3243c8bb6e0fb230043c0f938e71315de9cbedb814a4ac13b9eacc
3
+ metadata.gz: 851390d021df1149267018e9ec714cee68168c2f1f9b02c0998790c33da63005
4
+ data.tar.gz: d6468040657b6ef60a75d68650c054966e359c9e16e076104e15022daf0ac41c
5
5
  SHA512:
6
- metadata.gz: d45139aea688c64f0411b285c433c354447a2818ccba8d1dc49033a36dd825f9cdda0863fb863b1a6be6b5ea666b1ef67ab64847a30053f4fa57d2f6c54b8ec9
7
- data.tar.gz: eb1e0cb5f18bc67aaa790f2724744514520f5f55b53892bb600056100effcc139e4a351e230e3740d7e0eb59d075e851afb260be75ad9a9e90f6d9c8b57e15f3
6
+ metadata.gz: c4d56fa78ad0f10d2d3cacf39277926636883acbba04c51f0bf85f5cc9888026f3ab4c50484c79a7d7d71e9a644c324ed8421e7a7c6ae5de407380fb114bf397
7
+ data.tar.gz: d53429a445fdc042ec7e73eb9a5f6fe80ec017314a85c287d42074e7fefca2fc67c0417e374effd23c858fa43685dd3916bded4522310ed8e9d58c7d5cca78f3
@@ -3,5 +3,6 @@
3
3
  module Healthier
4
4
  # ApplicationController
5
5
  class ApplicationController < ActionController::Base
6
+ include Errors::ApiErrors
6
7
  end
7
8
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Errors
4
+ module ApiErrors
5
+ def self.included(base)
6
+ base.class_eval do
7
+ rescue_from StandardError, with: :bad_request
8
+ end
9
+ end
10
+
11
+ def bad_request(error)
12
+ render_error(:bad_request, error: { message: error.message })
13
+ end
14
+
15
+ def render_success(status, options = {})
16
+ options[:success] = true
17
+ render json: options, status: status
18
+ end
19
+
20
+ def render_error(status, options = {})
21
+ options[:error] = { message: I18n.t("api_errors.#{status}") } if options[:error].blank?
22
+ options[:success] = false
23
+ Rollbar.error(options[:error])
24
+ render json: options, status: status
25
+ end
26
+
27
+ def render_silent_error(status, options = {})
28
+ options[:error] = { message: I18n.t("api_errors.#{status}") } if options[:error].blank?
29
+ options[:success] = false
30
+ render json: options, status: status
31
+ end
32
+ end
33
+ end
@@ -3,10 +3,11 @@
3
3
  module Healthier
4
4
  # Engine
5
5
  class ApiAuthenticator
6
- attr_accessor :controller
6
+ attr_accessor :controller, :request
7
7
 
8
8
  def initialize(controller)
9
9
  @controller = controller
10
+ @request = controller.request
10
11
  end
11
12
 
12
13
  def authenticate
@@ -16,14 +17,17 @@ module Healthier
16
17
  end
17
18
 
18
19
  def authenticate_with_bearer_token
20
+ tok = request.authorization.to_s
21
+ raise StandardError, 'Access Denied' unless tok.starts_with?('Bearer')
22
+
19
23
  controller.authenticate_with_http_token do |token, _options|
20
- ENV['BEARER_TOKEN'] == token
24
+ raise StandardError, 'Invalid token' unless ENV['BEARER_TOKEN'] == token
21
25
  end
22
26
  end
23
27
 
24
28
  def authenticate_with_basic_auth
25
29
  controller.authenticate_or_request_with_http_basic do |username, password|
26
- username == ENV['USERNAME'] && password == ENV['PASSWORD']
30
+ raise StandardError, 'Invalid credentials' unless username == ENV['USERNAME'] && password == ENV['PASSWORD']
27
31
  end
28
32
  end
29
33
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Healthier
4
4
  # MAJOR.MINOR.PATCH
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.7'
6
6
  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.6
4
+ version: 0.1.7
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-05-04 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,6 +36,7 @@ files:
36
36
  - Rakefile
37
37
  - app/controllers/healthier/application_controller.rb
38
38
  - app/controllers/healthier/checks_controller.rb
39
+ - app/lib/errors/api_errors.rb
39
40
  - config/routes.rb
40
41
  - lib/checkers/mongodb_checker.rb
41
42
  - lib/checkers/postgresql_checker.rb