mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Log REPP requests
This commit is contained in:
parent
0544dbd3ff
commit
568c52129f
8 changed files with 38 additions and 16 deletions
|
@ -4,11 +4,24 @@ module Repp
|
||||||
prefix :repp
|
prefix :repp
|
||||||
|
|
||||||
http_basic do |username, password|
|
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
|
end
|
||||||
|
|
||||||
helpers do
|
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
|
end
|
||||||
|
|
||||||
mount Repp::DomainV1
|
mount Repp::DomainV1
|
||||||
|
|
|
@ -5,8 +5,8 @@ module Repp
|
||||||
resource :contacts do
|
resource :contacts do
|
||||||
desc 'Return list of contact'
|
desc 'Return list of contact'
|
||||||
get '/' do
|
get '/' do
|
||||||
contacts = current_user.registrar.contacts.page(params[:page])
|
contacts = current_api_user.registrar.contacts.page(params[:page])
|
||||||
{
|
@response = {
|
||||||
contacts: contacts,
|
contacts: contacts,
|
||||||
total_pages: contacts.total_pages
|
total_pages: contacts.total_pages
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ module Repp
|
||||||
resource :domains do
|
resource :domains do
|
||||||
desc 'Return list of domains'
|
desc 'Return list of domains'
|
||||||
get '/' do
|
get '/' do
|
||||||
domains = current_user.registrar.domains.page(params[:page])
|
domains = current_api_user.registrar.domains.page(params[:page])
|
||||||
{
|
@response = {
|
||||||
domains: domains,
|
domains: domains,
|
||||||
total_pages: domains.total_pages
|
total_pages: domains.total_pages
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,14 +121,15 @@ module Epp::Common
|
||||||
|
|
||||||
def write_to_epp_log
|
def write_to_epp_log
|
||||||
request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame]
|
request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame]
|
||||||
ApiLog::EppLog.create!({
|
ApiLog::EppLog.create({
|
||||||
request: params[:frame],
|
request: params[:frame],
|
||||||
request_command: params[:command],
|
request_command: params[:command],
|
||||||
request_successful: epp_errors.empty?,
|
request_successful: epp_errors.empty?,
|
||||||
request_object: request_object,
|
request_object: request_object,
|
||||||
response: @response,
|
response: @response,
|
||||||
api_user_name: @epp_user.try(:to_s) || current_epp_user.try(:to_s),
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
%dt= t('registrar')
|
%dt= t('registrar')
|
||||||
%dd= @epp_log.api_user_registrar
|
%dd= @epp_log.api_user_registrar
|
||||||
|
|
||||||
|
%dt= t('ip')
|
||||||
|
%dd= @epp_log.ip
|
||||||
|
|
||||||
%dt= t('created_at')
|
%dt= t('created_at')
|
||||||
%dd= @epp_log.created_at
|
%dd= @epp_log.created_at
|
||||||
|
|
||||||
|
|
|
@ -489,3 +489,4 @@ en:
|
||||||
request: 'Request'
|
request: 'Request'
|
||||||
response: 'Response'
|
response: 'Response'
|
||||||
details: 'Details'
|
details: 'Details'
|
||||||
|
ip: 'IP'
|
||||||
|
|
|
@ -24,18 +24,20 @@ ActiveRecord::Schema.define(version: 0) do
|
||||||
t.boolean "request_successful"
|
t.boolean "request_successful"
|
||||||
t.string "api_user_name"
|
t.string "api_user_name"
|
||||||
t.string "api_user_registrar"
|
t.string "api_user_registrar"
|
||||||
|
t.string "ip"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "repp_logs", force: true do |t|
|
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.text "response"
|
||||||
t.string "request_command"
|
t.string "response_code"
|
||||||
t.string "request_object"
|
|
||||||
t.boolean "request_successful"
|
|
||||||
t.string "api_user_name"
|
t.string "api_user_name"
|
||||||
t.string "api_user_registrar"
|
t.string "api_user_registrar"
|
||||||
|
t.string "ip"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,18 +12,20 @@ class CreateApiLogTables < ActiveRecord::Migration
|
||||||
t.boolean :request_successful
|
t.boolean :request_successful
|
||||||
t.string :api_user_name
|
t.string :api_user_name
|
||||||
t.string :api_user_registrar
|
t.string :api_user_registrar
|
||||||
|
t.string :ip
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table :repp_logs do |t|
|
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.text :response
|
||||||
t.string :request_command
|
t.string :response_code
|
||||||
t.string :request_object
|
|
||||||
t.boolean :request_successful
|
|
||||||
t.string :api_user_name
|
t.string :api_user_name
|
||||||
t.string :api_user_registrar
|
t.string :api_user_registrar
|
||||||
|
t.string :ip
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue