mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 20:27:30 +02:00
Move DNS::Zone WHOIS info logic to concern
This commit is contained in:
parent
c9c90888bd
commit
7e640a376e
2 changed files with 60 additions and 49 deletions
59
app/models/concerns/zone/whois_queryable.rb
Normal file
59
app/models/concerns/zone/whois_queryable.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Concerns
|
||||
module Zone
|
||||
module WhoisQueryable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_save :update_whois_record, if: :subzone?
|
||||
after_destroy :update_whois_record, if: :subzone?
|
||||
end
|
||||
|
||||
def subzone?
|
||||
origin.include? '.'
|
||||
end
|
||||
|
||||
def update_whois_record
|
||||
UpdateWhoisRecordJob.enqueue origin, 'zone'
|
||||
end
|
||||
|
||||
def generate_data
|
||||
wr = Whois::Record.find_or_initialize_by(name: origin)
|
||||
wr.json = generate_json
|
||||
wr.save
|
||||
end
|
||||
|
||||
def generate_json
|
||||
data = {}.with_indifferent_access
|
||||
[domain_vars, registrar_vars, registrant_vars].each do |h|
|
||||
data.merge!(h)
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def domain_vars
|
||||
{ disclaimer: Setting.registry_whois_disclaimer, name: origin,
|
||||
registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'],
|
||||
changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email,
|
||||
admin_contacts: [contact_vars], tech_contacts: [contact_vars],
|
||||
nameservers: [master_nameserver] }
|
||||
end
|
||||
|
||||
def registrar_vars
|
||||
{ registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url,
|
||||
registrar_phone: Setting.registry_phone }
|
||||
end
|
||||
|
||||
def registrant_vars
|
||||
{ registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no,
|
||||
registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org',
|
||||
registrant_disclosed_attributes: %w[name email] }
|
||||
end
|
||||
|
||||
def contact_vars
|
||||
{ name: Setting.registry_invoice_contact, email: Setting.registry_email,
|
||||
disclosed_attributes: %w[name email] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,8 +5,7 @@ module DNS
|
|||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
validates :origin, uniqueness: true
|
||||
after_save :update_whois_record, if: :subzone?
|
||||
after_destroy :update_whois_record, if: :subzone?
|
||||
include Concerns::Zone::WhoisQueryable
|
||||
|
||||
before_destroy do
|
||||
throw(:abort) if used?
|
||||
|
@ -47,52 +46,5 @@ module DNS
|
|||
def to_partial_path
|
||||
'zone'
|
||||
end
|
||||
|
||||
def subzone?
|
||||
origin.include? '.'
|
||||
end
|
||||
|
||||
def update_whois_record
|
||||
UpdateWhoisRecordJob.enqueue origin, 'zone'
|
||||
end
|
||||
|
||||
def generate_data
|
||||
wr = Whois::Record.find_or_initialize_by(name: origin)
|
||||
wr.json = generate_json
|
||||
wr.save
|
||||
end
|
||||
|
||||
def generate_json
|
||||
data = {}.with_indifferent_access
|
||||
[domain_vars, registrar_vars, registrant_vars].each do |h|
|
||||
data.merge!(h)
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def domain_vars
|
||||
{ disclaimer: Setting.registry_whois_disclaimer, name: origin,
|
||||
registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'],
|
||||
changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email,
|
||||
admin_contacts: [contact_vars], tech_contacts: [contact_vars],
|
||||
nameservers: [master_nameserver] }
|
||||
end
|
||||
|
||||
def registrar_vars
|
||||
{ registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url,
|
||||
registrar_phone: Setting.registry_phone }
|
||||
end
|
||||
|
||||
def registrant_vars
|
||||
{ registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no,
|
||||
registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org',
|
||||
registrant_disclosed_attributes: %w[name email] }
|
||||
end
|
||||
|
||||
def contact_vars
|
||||
{ name: Setting.registry_invoice_contact, email: Setting.registry_email,
|
||||
disclosed_attributes: %w[name email] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue