healthier 0.1.6 → 0.1.71

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: aad15d777d50bce0e5ef2f620b4f34249298dc87b709b851fa06df41b3eb7152
4
+ data.tar.gz: 6fd08ae06b1c5e269b248776507c6fa20cbcb57502f5a7dc7004426559bb627a
5
5
  SHA512:
6
- metadata.gz: d45139aea688c64f0411b285c433c354447a2818ccba8d1dc49033a36dd825f9cdda0863fb863b1a6be6b5ea666b1ef67ab64847a30053f4fa57d2f6c54b8ec9
7
- data.tar.gz: eb1e0cb5f18bc67aaa790f2724744514520f5f55b53892bb600056100effcc139e4a351e230e3740d7e0eb59d075e851afb260be75ad9a9e90f6d9c8b57e15f3
6
+ metadata.gz: 3f3540f1b7d0f90603e3ba7776b76873c761c11b28bfc8cfb5e3424040e34b0f9bfe3b277085a8b7ffc11eff6d5d7e896cfc57f43ce1a8d200ce9304563296d1
7
+ data.tar.gz: 37104cd689081b52a891c56feae0f7f6686f09afea731ad3120cc8df21dba3b8f94b57f4e49de3c411dc53f85069b415a14a54ad61e3d1d4b2cbc80bcf220b10
@@ -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,13 @@ module Healthier
16
17
  end
17
18
 
18
19
  def authenticate_with_bearer_token
19
- controller.authenticate_with_http_token do |token, _options|
20
- ENV['BEARER_TOKEN'] == token
21
- end
20
+ tok = request.headers['MONITORING']
21
+ raise StandardError, 'Invalid token' unless tok.eql?(ENV['BEARER_TOKEN'])
22
22
  end
23
23
 
24
24
  def authenticate_with_basic_auth
25
25
  controller.authenticate_or_request_with_http_basic do |username, password|
26
- username == ENV['USERNAME'] && password == ENV['PASSWORD']
26
+ raise StandardError, 'Invalid credentials' unless username == ENV['USERNAME'] && password == ENV['PASSWORD']
27
27
  end
28
28
  end
29
29
  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.71'
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.71
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