mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
Refactored whois from domain into whois body
This commit is contained in:
parent
920b3e71e0
commit
3d0d98d9b1
7 changed files with 204 additions and 51 deletions
|
@ -238,55 +238,10 @@ class Domain < ActiveRecord::Base
|
|||
log
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def update_whois_body
|
||||
self.whois_body = <<-EOS
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
|
||||
domain: #{name}
|
||||
registrant: #{registrant.name}
|
||||
status: #{domain_statuses.map(&:value).join(', ')}
|
||||
registered: #{registered_at and registered_at.to_s(:db)}
|
||||
changed: #{updated_at and updated_at.to_s(:db)}
|
||||
expire: #{valid_to and valid_to.to_s(:db)}
|
||||
outzone:
|
||||
delete:
|
||||
|
||||
#{contacts_body}
|
||||
|
||||
nsset:
|
||||
nserver:
|
||||
|
||||
registrar: #{registrar}
|
||||
phone: #{registrar.phone}
|
||||
address: #{registrar.address}
|
||||
created: #{registrar.created_at.to_s(:db)}
|
||||
changed: #{registrar.updated_at.to_s(:db)}
|
||||
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts_body
|
||||
out = ''
|
||||
admin_contacts.each do |c|
|
||||
out << 'Admin contact:'
|
||||
out << "name: #{c.name}"
|
||||
out << "email: #{c.email}"
|
||||
out << "registrar: #{c.registrar}"
|
||||
out << "created: #{c.created_at.to_s(:db)}"
|
||||
end
|
||||
|
||||
tech_contacts.each do |c|
|
||||
out << 'Tech contact:'
|
||||
out << "name: #{c.name}"
|
||||
out << "email: #{c.email}"
|
||||
out << "registrar: #{c.registrar}"
|
||||
out << "created: #{c.created_at.to_s(:db)}"
|
||||
end
|
||||
out
|
||||
whois = Whois::Body.new(self)
|
||||
self.whois_json = whois.whois_json
|
||||
self.whois_body = whois.whois_body
|
||||
end
|
||||
|
||||
def update_whois_server
|
||||
|
|
|
@ -109,6 +109,15 @@ class DomainStatus < ActiveRecord::Base
|
|||
CLIENT_STATUSES.include?(value)
|
||||
end
|
||||
|
||||
def human_value
|
||||
case value
|
||||
when 'ok'
|
||||
'ok (paid and in zone)'
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def statuses_for_client
|
||||
CLIENT_STATUSES.map { |x| x.sub('client', '') }
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
module Whois
|
||||
end
|
107
app/models/whois/body.rb
Normal file
107
app/models/whois/body.rb
Normal file
|
@ -0,0 +1,107 @@
|
|||
class Whois::Body
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def h
|
||||
@h ||= HashWithIndifferentAccess.new
|
||||
end
|
||||
|
||||
def initialize(domain)
|
||||
h[:name] = domain.name
|
||||
h[:registrant] = domain.registrant.name
|
||||
h[:status] = domain.domain_statuses.map(&:human_value).join(', ')
|
||||
h[:registered] = domain.registered_at and domain.registered_at.to_s(:db)
|
||||
h[:updated_at] = domain.updated_at and domain.updated_at.to_s(:db)
|
||||
h[:valid_to] = domain.valid_to and domain.valid_to.to_s(:db)
|
||||
|
||||
h[:registrar] = domain.registrar.name
|
||||
h[:registrar_phone] = domain.registrar.phone
|
||||
h[:registrar_address] = domain.registrar.address
|
||||
h[:registrar_update_at] = domain.registrar.updated_at.to_s(:db)
|
||||
h[:admin_contacts] = []
|
||||
domain.admin_contacts.each do |ac|
|
||||
h[:admin_contacts] << {
|
||||
name: ac.name,
|
||||
email: ac.email,
|
||||
registrar: ac.registrar.name,
|
||||
created_at: ac.created_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
h[:tech_contacts] = []
|
||||
domain.tech_contacts.each do |tc|
|
||||
h[:tech_contacts] << {
|
||||
name: tc.name,
|
||||
email: tc.email,
|
||||
registrar: tc.registrar.name,
|
||||
created_at: tc.created_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
h[:nameservers] = []
|
||||
domain.nameservers.each do |ns|
|
||||
h[:nameservers] << {
|
||||
hostname: ns.hostname,
|
||||
updated_at: ns.updated_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def whois_json
|
||||
h
|
||||
end
|
||||
|
||||
def whois_body
|
||||
<<-EOS
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
|
||||
Domain:
|
||||
name: #{h[:name]}
|
||||
registrant: #{h[:registrant]}
|
||||
status: #{h[:status]}
|
||||
registered: #{h[:registered]}
|
||||
changed: #{h[:updated_at]}
|
||||
expire: #{h[:valid_to]}
|
||||
outzone:
|
||||
delete:
|
||||
#{contacts_body(h[:admin_contacts], h[:tech_contacts])}
|
||||
Registrar:
|
||||
name: #{h[:registrar]}
|
||||
phone: #{h[:registrar_phone]}
|
||||
address: #{h[:registrar_address]}
|
||||
changed: #{h[:registrar_update_at]}
|
||||
#{nameservers_body(h[:nameservers])}
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts_body(admins, techs)
|
||||
out = ''
|
||||
out << (admins.size > 1 ? "\nAdministrative contacts" : "\nAdministrative contact")
|
||||
admins.each do |c|
|
||||
out << "\n name: #{c[:name]}"
|
||||
out << "\n e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{c[:created_at]}"
|
||||
out << "\n"
|
||||
end
|
||||
|
||||
out << (techs.size > 1 ? "\nTechnical contacts" : "\nTechnical contact:")
|
||||
techs.each do |c|
|
||||
out << "\n name: #{c[:name]}"
|
||||
out << "\n e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{c[:created_at]}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def nameservers_body(nservers)
|
||||
out = "\nName servers:"
|
||||
nservers.each do |ns|
|
||||
out << "\n nserver: #{ns[:hostname]}"
|
||||
out << "\n changed: #{ns[:updated_at]}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
end
|
5
db/migrate/20150421134820_add_whosi_json_body.rb
Normal file
5
db/migrate/20150421134820_add_whosi_json_body.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddWhosiJsonBody < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :domains, :whois_json, :json
|
||||
end
|
||||
end
|
|
@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20150423083308) do
|
|||
t.integer "legacy_id"
|
||||
t.integer "legacy_registrar_id"
|
||||
t.integer "legacy_registrant_id"
|
||||
t.json "whois_json"
|
||||
end
|
||||
|
||||
add_index "domains", ["registrant_id"], name: "index_domains_on_registrant_id", using: :btree
|
||||
|
|
|
@ -38,6 +38,9 @@ describe Domain do
|
|||
@domain.whois_body.should == nil
|
||||
end
|
||||
|
||||
it 'should not have whois json' do
|
||||
@domain.whois_json.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes' do
|
||||
|
@ -74,10 +77,85 @@ describe Domain do
|
|||
domain.errors.full_messages.should match_array(["Admin domain contacts is invalid"])
|
||||
end
|
||||
|
||||
it 'should not have whois_body present by default' do
|
||||
it 'should have whois body by default' do
|
||||
@domain.whois_body.present?.should == true
|
||||
end
|
||||
|
||||
it 'should have whois json by default' do
|
||||
@domain.whois_json.present?.should == true
|
||||
end
|
||||
|
||||
it 'should have whois_body present by default' do
|
||||
@domain.name = 'yeah.ee'
|
||||
@domain.updated_at = Time.zone.parse('2020.02.02 02:00')
|
||||
@domain.registered_at = Time.zone.parse('2000.01.01 9:00')
|
||||
@domain.valid_to = Time.zone.parse('2016.04.21 0:00')
|
||||
registrar = Fabricate(:registrar,
|
||||
name: 'First Registrar Ltd',
|
||||
created_at: Time.zone.parse('1995.01.01'),
|
||||
updated_at: Time.zone.parse('1996.01.01'))
|
||||
@domain.registrant = Fabricate(:contact,
|
||||
name: 'Jarren Jakubowski0',
|
||||
created_at: Time.zone.parse('2005.01.01'))
|
||||
@domain.admin_contacts = [Fabricate(:contact,
|
||||
name: 'First Admin',
|
||||
registrar: registrar,
|
||||
created_at: Time.zone.parse('2016.01.01'))]
|
||||
@domain.tech_contacts = [Fabricate(:contact,
|
||||
name: 'First Tech',
|
||||
registrar: registrar,
|
||||
created_at: Time.zone.parse('2016.01.01'))]
|
||||
@domain.registrar = registrar
|
||||
ns1 = Fabricate(:nameserver, hostname: 'test.ee')
|
||||
ns1.updated_at = Time.zone.parse('1980.01.01')
|
||||
ns2 = Fabricate(:nameserver, hostname: 'test1.ee')
|
||||
ns2.updated_at = Time.zone.parse('1970.01.01')
|
||||
@domain.nameservers = [ns1, ns2]
|
||||
|
||||
@domain.update_whois_body
|
||||
@domain.whois_body.should == <<-EOS
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
|
||||
Domain:
|
||||
name: yeah.ee
|
||||
registrant: Jarren Jakubowski0
|
||||
status: ok (paid and in zone)
|
||||
registered: 2000-01-01 09:00:00 UTC
|
||||
changed: 2020-02-02 02:00:00 UTC
|
||||
expire: 2016-04-21 00:00:00 UTC
|
||||
outzone:
|
||||
delete:
|
||||
|
||||
Administrative contact
|
||||
name: First Admin
|
||||
e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS
|
||||
registrar: First Registrar Ltd
|
||||
created: 2016-01-01 00:00:00
|
||||
|
||||
Technical contact:
|
||||
name: First Tech
|
||||
e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS
|
||||
registrar: First Registrar Ltd
|
||||
created: 2016-01-01 00:00:00
|
||||
|
||||
Registrar:
|
||||
name: First Registrar Ltd
|
||||
phone:
|
||||
address: Street 999, Town, County, Postal
|
||||
changed: 1996-01-01 00:00:00
|
||||
|
||||
Name servers:
|
||||
nserver: test.ee
|
||||
changed: 1980-01-01 00:00:00
|
||||
|
||||
nserver: test1.ee
|
||||
changed: 1970-01-01 00:00:00
|
||||
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
end
|
||||
|
||||
context 'with versioning' do
|
||||
it 'should not have one version' do
|
||||
with_versioning do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue