mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 11:16:00 +02:00
Bulk NS change: Verify CSV integrity
This commit is contained in:
parent
067db7aa0a
commit
4170554ca1
1 changed files with 13 additions and 4 deletions
|
@ -7,11 +7,12 @@ class Registrar
|
||||||
ipv6 = params[:ipv6].split("\r\n")
|
ipv6 = params[:ipv6].split("\r\n")
|
||||||
|
|
||||||
domains = domain_list_from_csv
|
domains = domain_list_from_csv
|
||||||
|
return csv_list_empty_guard if domains == []
|
||||||
|
|
||||||
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
||||||
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
||||||
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
|
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
|
||||||
domains: domains,
|
domains: domains || [],
|
||||||
attributes: { hostname: params[:new_hostname],
|
attributes: { hostname: params[:new_hostname],
|
||||||
ipv4: ipv4,
|
ipv4: ipv4,
|
||||||
ipv6: ipv6 } } }.to_json
|
ipv6: ipv6 } } }.to_json
|
||||||
|
@ -42,12 +43,20 @@ class Registrar
|
||||||
notices.join(', ')
|
notices.join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def csv_list_empty_guard
|
||||||
|
notice = 'CSV scoped domain list seems empty. Make sure that domains are added and ' \
|
||||||
|
'"domain_name" header is present.'
|
||||||
|
redirect_to(registrar_domains_url, flash: { notice: notice })
|
||||||
|
end
|
||||||
|
|
||||||
def domain_list_from_csv
|
def domain_list_from_csv
|
||||||
return [] if params[:puny_file].blank?
|
return if params[:puny_file].blank?
|
||||||
|
|
||||||
domains = []
|
domains = []
|
||||||
CSV.read(params[:puny_file].path, headers: true).each { |b| domains << b['domain_name'] }
|
CSV.read(params[:puny_file].path, headers: true).map { |b| domains << b['domain_name'] }
|
||||||
domains
|
domains.compact
|
||||||
|
rescue CSV::MalformedCSVError
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue