mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +02:00
Create nameservers cache
This commit is contained in:
parent
4caa0ef903
commit
e695a6e628
8 changed files with 104 additions and 31 deletions
|
@ -2,7 +2,20 @@ class Admin::ZonefilesController < ApplicationController
|
|||
# TODO: Refactor this
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def index
|
||||
@zonefile = ActiveRecord::Base.connection.execute("select generate_zonefile('ee')")[0]['generate_zonefile']
|
||||
send_data @zonefile, filename: 'zonefile-1000.txt'
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
if ZonefileSetting.pluck(:origin).include?(params[:origin])
|
||||
|
||||
@zonefile = ActiveRecord::Base.connection.execute(
|
||||
"select generate_zonefile('#{params[:origin]}')"
|
||||
)[0]['generate_zonefile']
|
||||
|
||||
send_data @zonefile, filename: "#{params[:origin]}.txt"
|
||||
else
|
||||
flash[:alert] = 'Origin not supported'
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
2
app/models/cached_nameserver.rb
Normal file
2
app/models/cached_nameserver.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class CachedNameserver < ActiveRecord::Base
|
||||
end
|
|
@ -10,6 +10,10 @@ class Nameserver < ActiveRecord::Base
|
|||
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
||||
# rubocop: enable Metrics/LineLength
|
||||
|
||||
# caching
|
||||
after_commit :clear_cache
|
||||
after_commit :create_cache, on: [:create, :update]
|
||||
|
||||
# archiving
|
||||
has_paper_trail class_name: 'NameserverVersion'
|
||||
after_destroy :domain_version
|
||||
|
@ -52,6 +56,16 @@ class Nameserver < ActiveRecord::Base
|
|||
domain.create_version if domain
|
||||
end
|
||||
|
||||
def create_cache
|
||||
CachedNameserver.create(snapshot)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
logger.info('Nameserver already exists in cache; not caching')
|
||||
end
|
||||
|
||||
def clear_cache
|
||||
CachedNameserver.find_by(snapshot).try(:delete)
|
||||
end
|
||||
|
||||
def to_s
|
||||
hostname
|
||||
end
|
||||
|
|
|
@ -17,4 +17,4 @@
|
|||
%tr
|
||||
%td= link_to(x, edit_admin_zonefile_setting_path(x))
|
||||
%td
|
||||
= link_to(t('generate_zonefile'), admin_zonefiles_path, class: 'btn btn-xs btn-primary')
|
||||
= link_to(t('generate_zonefile'), admin_zonefiles_path(origin: x.origin), method: 'post', class: 'btn btn-xs btn-primary')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue