From 4caa0ef9030556a24a94cde393c81aa535d46809 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 21 Nov 2014 19:16:22 +0200 Subject: [PATCH] Refactor, spacing in zone file --- app/models/zonefile.rb | 3 --- config/locales/en.yml | 8 +------- .../20141120110330_create_zonefile_setting.rb | 15 +++++++++++++- .../20141120140837_add_ee_domain_objects.rb | 14 ++++++++++++- .../20141121093125_add_zonefile_procedure.rb | 20 +++++++++++++++---- db/schema.rb | 14 +------------ db/seeds.rb | 9 --------- 7 files changed, 45 insertions(+), 38 deletions(-) delete mode 100644 app/models/zonefile.rb diff --git a/app/models/zonefile.rb b/app/models/zonefile.rb deleted file mode 100644 index 5e42b165a..000000000 --- a/app/models/zonefile.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Zonefile < ActiveRecord::Base - -end diff --git a/config/locales/en.yml b/config/locales/en.yml index b4e8d1538..79317856a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -221,7 +221,7 @@ en: refresh: 'Refresh' retry: 'Retry' expire: 'Expire' - minimum_ttl: 'Minimum ttl' + minimum_ttl: 'Minimum TTL' email: 'E-Mail' errors: @@ -420,12 +420,6 @@ en: zonefile: 'Zonefile' only_one_parameter_allowed: 'Only one parameter allowed: %{param_1} or %{param_2}' required_parameter_missing_choice: 'Required parameter missing: %{param_1} or %{param_2}' - zonefile_ttl: 'Zonefile TTL' - zonefile_refresh: 'Zonefile refresh' - zonefile_retry: 'Zonefile retry' - zonefile_expire: 'Zonefile expire' - zonefile_minimum_ttl: 'Zonefile minimum TTL' - zonefile_email: 'Zonefile e-mail' transfer_wait_time: 'Transfer wait time' ns_min_count: 'Nameserver minimum count' ns_max_count: 'Nameserver maximum count' diff --git a/db/migrate/20141120110330_create_zonefile_setting.rb b/db/migrate/20141120110330_create_zonefile_setting.rb index b91320051..fdba51948 100644 --- a/db/migrate/20141120110330_create_zonefile_setting.rb +++ b/db/migrate/20141120110330_create_zonefile_setting.rb @@ -8,6 +8,7 @@ class CreateZonefileSetting < ActiveRecord::Migration t.integer :expire t.integer :minimum_ttl t.string :email + t.string :master_nameserver t.timestamps end @@ -20,7 +21,19 @@ class CreateZonefileSetting < ActiveRecord::Migration retry: 900, expire: 1209600, minimum_ttl: 3600, - email: 'hostmaster.eestiinternet.ee' + email: 'hostmaster.eestiinternet.ee', + master_nameserver: 'ns.tld.ee' + }) + + ZonefileSetting.create({ + origin: 'pri.ee', + ttl: 43200, + refresh: 3600, + retry: 900, + expire: 1209600, + minimum_ttl: 3600, + email: 'hostmaster.eestiinternet.ee', + master_nameserver: 'ns.tld.ee' }) end end diff --git a/db/migrate/20141120140837_add_ee_domain_objects.rb b/db/migrate/20141120140837_add_ee_domain_objects.rb index ab00f7b07..af1a63325 100644 --- a/db/migrate/20141120140837_add_ee_domain_objects.rb +++ b/db/migrate/20141120140837_add_ee_domain_objects.rb @@ -45,14 +45,26 @@ class AddEeDomainObjects < ActiveRecord::Migration admin_contacts: [c], registrar: r ) + + pri = Domain.new( + name: 'pri.ee', + valid_to: Date.new(9999, 1, 1), + period: 1, + period_unit: 'y', + owner_contact: c, + admin_contacts: [c], + registrar: r + ) + + pri.save(validate: false) end # rubocop:enable Metrics/MethodLength def down Domain.find_by(name: 'ee').destroy + Domain.find_by(name: 'pri.ee').destroy EppUser.find_by(username: 'testeis').destroy Contact.find_by(name: 'EIS').destroy Registrar.find_by(name: 'EIS').destroy - end end diff --git a/db/migrate/20141121093125_add_zonefile_procedure.rb b/db/migrate/20141121093125_add_zonefile_procedure.rb index cd92bc635..1eb53d50d 100644 --- a/db/migrate/20141121093125_add_zonefile_procedure.rb +++ b/db/migrate/20141121093125_add_zonefile_procedure.rb @@ -6,17 +6,29 @@ class AddZonefileProcedure < ActiveRecord::Migration RETURNS text AS $$ DECLARE zone_header text := concat('$ORIGIN ', i_origin, '.'); - tmp text := ''; + include_filter varchar := ''; + exclude_filter varchar := ''; ns_records text := ''; a_records text := ''; a4_records text := ''; ds_records text := ''; BEGIN + -- define filters + include_filter = '%' || i_origin; + + -- for %.%.% + IF i_origin ~ '\.' THEN + exclude_filter := ''; + -- for %.% + ELSE + exclude_filter = '%.%.' || i_origin; + END IF; + -- zonefile header SELECT concat( format('%-10s', '$ORIGIN'), i_origin, '.', chr(10), format('%-10s', '$TTL'), zf.ttl, chr(10), chr(10), - format('%-10s', i_origin || '.'), 'IN SOA ', 'ns.tld.ee', '. ', zf.email, '. (', chr(10), + format('%-10s', i_origin || '.'), 'IN SOA ', zf.master_nameserver, '. ', zf.email, '. (', chr(10), format('%-17s', ''), format('%-12s', '2014111210'), '; serial number', chr(10), format('%-17s', ''), format('%-12s', zf.refresh), '; refresh, seconds', chr(10), format('%-17s', ''), format('%-12s', zf.retry), '; retry, seconds', chr(10), @@ -24,14 +36,14 @@ class AddZonefileProcedure < ActiveRecord::Migration format('%-17s', ''), format('%-12s', zf.minimum_ttl), '; minimum TTL, seconds', chr(10), format('%-17s', ''), ')' ) FROM zonefile_settings zf WHERE i_origin = zf.origin INTO zone_header; - + RAISE NOTICE '%', include_filter; -- ns records SELECT array_to_string( array( SELECT concat(d.name, '. IN NS ', ns.hostname, '.') FROM domains d JOIN nameservers ns ON ns.domain_id = d.id - WHERE d.name LIKE '%' || i_origin + WHERE d.name LIKE include_filter ORDER BY CASE d.name WHEN i_origin THEN 1 diff --git a/db/schema.rb b/db/schema.rb index 39a8d94f8..295d7b948 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141121093125) do +ActiveRecord::Schema.define(version: 20141114130737) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -335,16 +335,4 @@ ActiveRecord::Schema.define(version: 20141121093125) do add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree - create_table "zonefile_settings", force: true do |t| - t.string "origin" - t.integer "ttl" - t.integer "refresh" - t.integer "retry" - t.integer "expire" - t.integer "minimum_ttl" - t.string "email" - t.datetime "created_at" - t.datetime "updated_at" - end - end diff --git a/db/seeds.rb b/db/seeds.rb index 24d16ffb2..8769d15bc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -78,13 +78,4 @@ Setting.ns_max_count = 11 Setting.transfer_wait_time = 0 -# rubocop: disable Style/NumericLiterals -Setting.zonefile_ttl = 43200 -Setting.zonefile_refresh = 3600 -Setting.zonefile_retry = 900 -Setting.zonefile_expire = 1209600 -Setting.zonefile_minimum_ttl = 3600 -Setting.zonefile_email = 'hostmaster.eestiinternet.ee' -# rubocop: enable Style/NumericLiterals - # Setting.whois_enabled = true only uncomment this if you wish whois