mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +02:00
Make code more readable
This commit is contained in:
parent
7953b3f8df
commit
c9c90888bd
2 changed files with 43 additions and 47 deletions
|
@ -3,16 +3,10 @@ class UpdateWhoisRecordJob < Que::Job
|
||||||
def run(names, type)
|
def run(names, type)
|
||||||
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{type}"
|
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{type}"
|
||||||
|
|
||||||
klass = case type
|
klass = determine_class(type)
|
||||||
when 'reserved' then ReservedDomain
|
|
||||||
when 'blocked' then BlockedDomain
|
|
||||||
when 'domain' then Domain
|
|
||||||
when 'disputed' then Dispute.active
|
|
||||||
when 'zone' then DNS::Zone
|
|
||||||
end
|
|
||||||
|
|
||||||
Array(names).each do |name|
|
Array(names).each do |name|
|
||||||
record = klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name)
|
record = find_record(klass, name)
|
||||||
if record
|
if record
|
||||||
send "update_#{type}", record
|
send "update_#{type}", record
|
||||||
else
|
else
|
||||||
|
@ -21,6 +15,20 @@ class UpdateWhoisRecordJob < Que::Job
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_record(klass, name)
|
||||||
|
klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def determine_class(type)
|
||||||
|
case type
|
||||||
|
when 'reserved' then ReservedDomain
|
||||||
|
when 'blocked' then BlockedDomain
|
||||||
|
when 'domain' then Domain
|
||||||
|
when 'disputed' then Dispute.active
|
||||||
|
when 'zone' then DNS::Zone
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_domain(domain)
|
def update_domain(domain)
|
||||||
domain.whois_record ? domain.whois_record.save : domain.create_whois_record
|
domain.whois_record ? domain.whois_record.save : domain.create_whois_record
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module DNS
|
module DNS
|
||||||
class Zone < ApplicationRecord
|
class Zone < ApplicationRecord
|
||||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
||||||
|
@ -61,50 +63,36 @@ module DNS
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_json
|
def generate_json
|
||||||
h = HashWithIndifferentAccess.new
|
data = {}.with_indifferent_access
|
||||||
|
[domain_vars, registrar_vars, registrant_vars].each do |h|
|
||||||
|
data.merge!(h)
|
||||||
|
end
|
||||||
|
|
||||||
h[:disclaimer] = Setting.registry_whois_disclaimer if Setting.registry_whois_disclaimer
|
data
|
||||||
h[:name] = origin
|
end
|
||||||
h[:status] = ['ok (paid and in zone)']
|
|
||||||
h[:registered] = created_at.try(:to_s, :iso8601)
|
|
||||||
h[:changed] = updated_at.try(:to_s, :iso8601)
|
|
||||||
h[:expire] = nil
|
|
||||||
h[:outzone] = nil
|
|
||||||
h[:delete] = nil
|
|
||||||
|
|
||||||
h[:registrant] = Setting.registry_juridical_name
|
def domain_vars
|
||||||
h[:registrant_kind] = 'org'
|
{ disclaimer: Setting.registry_whois_disclaimer, name: origin,
|
||||||
h[:registrant_reg_no] = Setting.registry_reg_no
|
registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'],
|
||||||
h[:registrant_ident_country_code] = Setting.registry_country_code
|
changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email,
|
||||||
|
admin_contacts: [contact_vars], tech_contacts: [contact_vars],
|
||||||
|
nameservers: [master_nameserver] }
|
||||||
|
end
|
||||||
|
|
||||||
h[:email] = Setting.registry_email
|
def registrar_vars
|
||||||
h[:registrant_changed] = nil
|
{ registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url,
|
||||||
h[:registrant_disclosed_attributes] = %w[name email],
|
registrar_phone: Setting.registry_phone }
|
||||||
|
end
|
||||||
|
|
||||||
contact = {
|
def registrant_vars
|
||||||
name: Setting.registry_invoice_contact,
|
{ registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no,
|
||||||
email: Setting.registry_email,
|
registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org',
|
||||||
changed: nil,
|
registrant_disclosed_attributes: %w[name email] }
|
||||||
disclosed_attributes: %w[name email],
|
end
|
||||||
}
|
|
||||||
|
|
||||||
h[:admin_contacts] = [contact]
|
def contact_vars
|
||||||
|
{ name: Setting.registry_invoice_contact, email: Setting.registry_email,
|
||||||
h[:tech_contacts] = [contact]
|
disclosed_attributes: %w[name email] }
|
||||||
|
|
||||||
# update registar triggers when adding new attributes
|
|
||||||
h[:registrar] = Setting.registry_juridical_name
|
|
||||||
h[:registrar_website] = Setting.registry_url
|
|
||||||
h[:registrar_phone] = Setting.registry_phone
|
|
||||||
h[:registrar_changed] = nil
|
|
||||||
|
|
||||||
h[:nameservers] = [master_nameserver]
|
|
||||||
h[:nameservers_changed] = nil
|
|
||||||
|
|
||||||
h[:dnssec_keys] = []
|
|
||||||
h[:dnssec_changed] = nil
|
|
||||||
|
|
||||||
h
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue