Log REPP requests

This commit is contained in:
Martin Lensment 2015-01-13 13:58:38 +02:00
parent 0544dbd3ff
commit 568c52129f
8 changed files with 38 additions and 16 deletions

View file

@ -4,11 +4,24 @@ module Repp
prefix :repp
http_basic do |username, password|
@current_user ||= EppUser.find_by(username: username, password: password)
@current_api_user ||= EppUser.find_by(username: username, password: password)
end
helpers do
attr_reader :current_user
attr_reader :current_api_user
end
after do
ApiLog::ReppLog.create({
request_path: request.path,
request_method: request.request_method,
request_params: request.params.except('route_info').to_json,
response: @response.to_json,
response_code: status,
api_user_name: current_api_user.try(:username),
api_user_registrar: current_api_user.try(:registrar).try(:to_s),
ip: request.ip
})
end
mount Repp::DomainV1

View file

@ -5,8 +5,8 @@ module Repp
resource :contacts do
desc 'Return list of contact'
get '/' do
contacts = current_user.registrar.contacts.page(params[:page])
{
contacts = current_api_user.registrar.contacts.page(params[:page])
@response = {
contacts: contacts,
total_pages: contacts.total_pages
}

View file

@ -5,8 +5,8 @@ module Repp
resource :domains do
desc 'Return list of domains'
get '/' do
domains = current_user.registrar.domains.page(params[:page])
{
domains = current_api_user.registrar.domains.page(params[:page])
@response = {
domains: domains,
total_pages: domains.total_pages
}

View file

@ -121,14 +121,15 @@ module Epp::Common
def write_to_epp_log
request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame]
ApiLog::EppLog.create!({
ApiLog::EppLog.create({
request: params[:frame],
request_command: params[:command],
request_successful: epp_errors.empty?,
request_object: request_object,
response: @response,
api_user_name: @epp_user.try(:to_s) || current_epp_user.try(:to_s),
api_user_registrar: @epp_user.try(:registrar).try(:to_s) || current_epp_user.try(:registrar).try(:to_s)
api_user_registrar: @epp_user.try(:registrar).try(:to_s) || current_epp_user.try(:registrar).try(:to_s),
ip: request.ip
})
end
end

View file

@ -28,6 +28,9 @@
%dt= t('registrar')
%dd= @epp_log.api_user_registrar
%dt= t('ip')
%dd= @epp_log.ip
%dt= t('created_at')
%dd= @epp_log.created_at

View file

@ -489,3 +489,4 @@ en:
request: 'Request'
response: 'Response'
details: 'Details'
ip: 'IP'

View file

@ -24,18 +24,20 @@ ActiveRecord::Schema.define(version: 0) do
t.boolean "request_successful"
t.string "api_user_name"
t.string "api_user_registrar"
t.string "ip"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "repp_logs", force: true do |t|
t.text "request"
t.string "request_path"
t.string "request_method"
t.text "request_params"
t.text "response"
t.string "request_command"
t.string "request_object"
t.boolean "request_successful"
t.string "response_code"
t.string "api_user_name"
t.string "api_user_registrar"
t.string "ip"
t.datetime "created_at"
t.datetime "updated_at"
end

View file

@ -12,18 +12,20 @@ class CreateApiLogTables < ActiveRecord::Migration
t.boolean :request_successful
t.string :api_user_name
t.string :api_user_registrar
t.string :ip
t.timestamps
end
create_table :repp_logs do |t|
t.text :request
t.string :request_path
t.string :request_method
t.text :request_params
t.text :response
t.string :request_command
t.string :request_object
t.boolean :request_successful
t.string :response_code
t.string :api_user_name
t.string :api_user_registrar
t.string :ip
t.timestamps
end