mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Cleaned up rspec create settings and refactored whois_record
This commit is contained in:
parent
acab58b71c
commit
4cf57239a0
32 changed files with 210 additions and 198 deletions
|
@ -54,7 +54,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
after_save :manage_automatic_statuses
|
||||
after_save :update_whois_record
|
||||
after_save :update_whois_server
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
validates :period, numericality: { only_integer: true }
|
||||
|
@ -123,6 +122,7 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def included
|
||||
includes(
|
||||
:registrant,
|
||||
:registrar,
|
||||
:nameservers,
|
||||
:whois_record,
|
||||
|
@ -244,15 +244,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_whois_record
|
||||
self.whois_record = WhoisRecord.create if whois_record.blank?
|
||||
whois_record.update
|
||||
end
|
||||
|
||||
def update_whois_server
|
||||
if whois_record.present?
|
||||
whois_record.update_whois_server
|
||||
else
|
||||
logger.info "NO WHOIS BODY for domain: #{name}"
|
||||
end
|
||||
whois_record.blank? ? create_whois_record : whois_record.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,8 +37,6 @@ class Registrar < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
after_save :touch_domains_version
|
||||
|
||||
validates :email, :billing_email, format: /@/, allow_blank: true
|
||||
|
||||
class << self
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
class WhoisRecord < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
|
||||
def update_whois_server
|
||||
return logger.info "NO WHOIS NAME for whois record id: #{id}" if name.blank?
|
||||
wd = Whois::Record.find_or_initialize_by(name: name)
|
||||
wd.body = body
|
||||
wd.json = json
|
||||
wd.save
|
||||
validates :domain, :name, :body, :json, presence: true
|
||||
|
||||
before_validation :populate
|
||||
def populate
|
||||
return if domain.blank?
|
||||
self.json = generate_json
|
||||
self.name = json['name']
|
||||
self.body = generated_body
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def h
|
||||
@h ||= HashWithIndifferentAccess.new
|
||||
end
|
||||
def generate_json
|
||||
h = HashWithIndifferentAccess.new
|
||||
return h if domain.blank?
|
||||
|
||||
def update
|
||||
@disclosed = []
|
||||
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[:registered] = domain.registered_at.try(:to_s, :iso8601)
|
||||
h[:updated_at] = domain.updated_at.try(:to_s, :iso8601)
|
||||
h[:valid_to] = domain.valid_to.try(:to_s, :iso8601)
|
||||
|
||||
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[:registrar_update_at] = domain.registrar.updated_at.try(:to_s, :iso8601)
|
||||
h[:admin_contacts] = []
|
||||
domain.admin_contacts.each do |ac|
|
||||
@disclosed << [:email, ac.email]
|
||||
|
@ -34,7 +35,7 @@ class WhoisRecord < ActiveRecord::Base
|
|||
name: ac.name,
|
||||
email: ac.email,
|
||||
registrar: ac.registrar.name,
|
||||
created_at: ac.created_at.to_s(:db)
|
||||
created_at: ac.created_at.try(:to_s, :iso8601)
|
||||
}
|
||||
end
|
||||
h[:tech_contacts] = []
|
||||
|
@ -44,23 +45,18 @@ class WhoisRecord < ActiveRecord::Base
|
|||
name: tc.name,
|
||||
email: tc.email,
|
||||
registrar: tc.registrar.name,
|
||||
created_at: tc.created_at.to_s(:db)
|
||||
created_at: tc.created_at.try(:to_s, :iso8601)
|
||||
}
|
||||
end
|
||||
h[:nameservers] = []
|
||||
domain.nameservers.each do |ns|
|
||||
h[:nameservers] << {
|
||||
hostname: ns.hostname,
|
||||
updated_at: ns.updated_at.to_s(:db)
|
||||
updated_at: ns.updated_at.try(:to_s, :iso8601)
|
||||
}
|
||||
end
|
||||
|
||||
h[:disclosed] = @disclosed
|
||||
|
||||
self.name = h[:name]
|
||||
self.body = generated_body
|
||||
self.json = h
|
||||
save
|
||||
h
|
||||
end
|
||||
|
||||
def generated_body
|
||||
|
@ -68,21 +64,21 @@ class WhoisRecord < ActiveRecord::Base
|
|||
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]}
|
||||
name: #{json['name']}
|
||||
registrant: #{json['registrant']}
|
||||
status: #{json['status']}
|
||||
registered: #{Time.zone.parse(json['registered'])}
|
||||
changed: #{Time.zone.parse(json['updated_at'])}
|
||||
expire: #{Time.zone.parse(json['valid_to'])}
|
||||
outzone:
|
||||
delete:
|
||||
#{contacts_body(h[:admin_contacts], h[:tech_contacts])}
|
||||
#{contacts_body(json['admin_contacts'], json['tech_contacts'])}
|
||||
Registrar:
|
||||
name: #{h[:registrar]}
|
||||
phone: #{h[:registrar_phone]}
|
||||
address: #{h[:registrar_address]}
|
||||
changed: #{h[:registrar_update_at]}
|
||||
#{nameservers_body(h[:nameservers])}
|
||||
name: #{json['registrar']}
|
||||
phone: #{json['registrar_phone']}
|
||||
address: #{json['registrar_address']}
|
||||
changed: #{Time.zone.parse(json['registrar_update_at'])}
|
||||
#{nameservers_body(json['nameservers'])}
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
|
@ -90,34 +86,47 @@ More information at http://internet.ee
|
|||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts_body(admins, techs)
|
||||
admins ||= []
|
||||
techs ||= []
|
||||
|
||||
out = ''
|
||||
out << (admins.size > 1 ? "\nAdministrative contacts" : "\nAdministrative contact")
|
||||
admins.each do |c|
|
||||
out << "\n name: #{c[:name]}"
|
||||
out << "\n name: #{c['name']}"
|
||||
out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{c[:created_at]}"
|
||||
out << "\n registrar: #{c['registrar']}"
|
||||
out << "\n created: #{Time.zone.parse(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 name: #{c['name']}"
|
||||
out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{c[:created_at]}"
|
||||
out << "\n registrar: #{c['registrar']}"
|
||||
out << "\n created: #{Time.zone.parse(c['created_at'])}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def nameservers_body(nservers)
|
||||
nservers ||= []
|
||||
|
||||
out = "\nName servers:"
|
||||
nservers.each do |ns|
|
||||
out << "\n nserver: #{ns[:hostname]}"
|
||||
out << "\n changed: #{ns[:updated_at]}"
|
||||
out << "\n nserver: #{ns['hostname']}"
|
||||
out << "\n changed: #{Time.zone.parse(ns['updated_at'])}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def update_whois_server
|
||||
return logger.info "NO WHOIS NAME for whois record id: #{id}" if name.blank?
|
||||
wd = Whois::Record.find_or_initialize_by(name: name)
|
||||
wd.body = body
|
||||
wd.json = json
|
||||
wd.save
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue