Skip to content

Commit

Permalink
Merge pull request #15 from mlibrary/LIBSEARCH-749-liveness-check
Browse files Browse the repository at this point in the history
feat: added liveness check
  • Loading branch information
niquerio authored Jun 20, 2022
2 parents c60e508 + f98120b commit 0a3b4a8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
10 changes: 0 additions & 10 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,4 @@ class ApplicationController < ActionController::API
include ActionController::MimeResponds

include ActionController::ImplicitRender
before_action :require_authorization_token

private

def require_authorization_token
token = request.headers["Authorization"]&.split(" ")&.at(1)
unless AuthToken.exists?(token: token)
render json: {}, status: 401
end
end
end
5 changes: 5 additions & 0 deletions app/controllers/monitoring_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MonitoringController < ApplicationController
def live
head :ok
end
end
2 changes: 1 addition & 1 deletion app/controllers/v1/loans_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module V1
class LoansController < ApplicationController
class LoansController < V1Controller
def index
user = User.find(params[:user_uniqname])
rescue
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module V1
class UsersController < ApplicationController
class UsersController < V1Controller
def show
@user = User.find(params[:uniqname])
rescue
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/v1_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class V1Controller < ApplicationController
before_action :require_authorization_token

private

def require_authorization_token
token = request.headers["Authorization"]&.split(" ")&.at(1)
unless AuthToken.exists?(token: token)
render json: {}, status: 401
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
get "/loans/download", to: "loans#download"
end
end
get "/-/live", to: "monitoring#live"
end
7 changes: 7 additions & 0 deletions spec/requests/monitoring_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "rails_helper"
describe "get /-/live", type: :request do
it "show OK" do
get "/-/live"
expect(response).to have_http_status(:success)
end
end

0 comments on commit 0a3b4a8

Please sign in to comment.