mirror of
https://github.com/internetee/registry.git
synced 2025-06-02 10:48:37 +02:00
29 lines
784 B
Ruby
29 lines
784 B
Ruby
module Api
|
|
module V1
|
|
class BaseController < ActionController::API
|
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
|
|
|
|
private
|
|
|
|
def authenticate
|
|
ip_allowed = allowed_ips.include?(request.remote_ip)
|
|
head :unauthorized unless ip_allowed
|
|
end
|
|
|
|
def authenticate_shared_key
|
|
api_key = "Basic #{ENV['rwhois_internal_api_shared_key']}"
|
|
head(:unauthorized) unless api_key == request.authorization
|
|
end
|
|
|
|
def not_found_error
|
|
uuid = params['uuid']
|
|
json = { error: 'Not Found', uuid: uuid, message: 'Record not found' }
|
|
render json: json, status: :not_found
|
|
end
|
|
|
|
def allowed_ips
|
|
ENV['auction_api_allowed_ips'].split(',').map(&:strip)
|
|
end
|
|
end
|
|
end
|
|
end
|