elsloo closed pull request #1720: Adding TXT Records support URL: https://github.com/apache/incubator-trafficcontrol/pull/1720
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql index b14fa61929..6870298ad7 100644 --- a/traffic_ops/app/db/seeds.sql +++ b/traffic_ops/app/db/seeds.sql @@ -396,6 +396,7 @@ insert into type (name, description, use_in_table) values ('RESOLVE6', 'federati insert into type (name, description, use_in_table) values ('A_RECORD', 'Static DNS A entry', 'staticdnsentry') ON CONFLICT (name) DO NOTHING; insert into type (name, description, use_in_table) values ('AAAA_RECORD', 'Static DNS AAAA entry', 'staticdnsentry') ON CONFLICT (name) DO NOTHING; insert into type (name, description, use_in_table) values ('CNAME_RECORD', 'Static DNS CNAME entry', 'staticdnsentry') ON CONFLICT (name) DO NOTHING; +insert into type (name, description, use_in_table) values ('TXT_RECORD', 'Static DNS TXT entry', 'staticdnsentry') ON CONFLICT (name) DO NOTHING; --steering_target types insert into type (name, description, use_in_table) values ('STEERING_WEIGHT', 'Weighted steering target', 'steering_target') ON CONFLICT (name) DO NOTHING; diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManager.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManager.java index 1a6e36dbcd..cb4803f040 100644 --- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManager.java +++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManager.java @@ -55,6 +55,7 @@ import org.xbill.DNS.SOARecord; import org.xbill.DNS.SetResponse; import org.xbill.DNS.TextParseException; +import org.xbill.DNS.TXTRecord; import org.xbill.DNS.Type; import org.xbill.DNS.Zone; @@ -488,6 +489,7 @@ public void run() { return records; } + @SuppressWarnings("PMD.CyclomaticComplexity") private static void addStaticDnsEntries(final List<Record> list, final DeliveryService ds, final String domain) throws TextParseException, UnknownHostException { if (ds != null && ds.getStaticDnsEntries() != null) { @@ -505,13 +507,19 @@ private static void addStaticDnsEntries(final List<Record> list, final DeliveryS if (ttl == 0) { ttl = ZoneUtils.getLong(ds.getTtls(), type, 60); } - - if ("A".equals(type)) { - list.add(new ARecord(name, DClass.IN, ttl, InetAddress.getByName(value))); - } else if (AAAA.equals(type)) { - list.add(new AAAARecord(name, DClass.IN, ttl, InetAddress.getByName(value))); - } else if ("CNAME".equals(type)) { - list.add(new CNAMERecord(name, DClass.IN, ttl, new Name(value))); + switch(type) { + case "A": + list.add(new ARecord(name, DClass.IN, ttl, InetAddress.getByName(value))); + break; + case "AAAA": + list.add(new AAAARecord(name, DClass.IN, ttl, InetAddress.getByName(value))); + break; + case "CNAME": + list.add(new CNAMERecord(name, DClass.IN, ttl, new Name(value))); + break; + case "TXT": + list.add(new TXTRecord(name, DClass.IN, ttl, new String(value))); + break; } } catch (JSONException e) { LOGGER.error(e); diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/keys/ZoneTestRecords.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/keys/ZoneTestRecords.java index e3535f68c9..c0e6ccb4e0 100644 --- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/keys/ZoneTestRecords.java +++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/keys/ZoneTestRecords.java @@ -25,6 +25,7 @@ import org.xbill.DNS.NSRecord; import org.xbill.DNS.Name; import org.xbill.DNS.Record; +import org.xbill.DNS.TXTRecord; import org.xbill.DNS.SOARecord; import java.net.Inet6Address; @@ -103,6 +104,8 @@ private static KeyPair recreateKeyPair(String publicKey, String privateKey) thro Name webMirror = new Name("mirror.www.example.com."); Name ftpMirror = new Name("mirror.ftp.example.com."); + String txtRecord = new String("dead0123456789"); + records = new ArrayList<>(Arrays.asList( new AAAARecord(webServer, DClass.IN, threeDays.getSeconds(), Inet6Address.getByName("2001:db8::5:6:7:8")), new AAAARecord(ftpServer, DClass.IN, threeDays.getSeconds(), Inet6Address.getByName("2001:db8::12:34:56:78")), @@ -118,6 +121,7 @@ private static KeyPair recreateKeyPair(String publicKey, String privateKey) thro new AAAARecord(ftpServer, DClass.IN, threeDays.getSeconds(), Inet6Address.getByName("2001:db8::21:43:65:87")), new CNAMERecord(webMirror, DClass.IN, tenYears.getSeconds(), webServer), new CNAMERecord(ftpMirror, DClass.IN, tenYears.getSeconds(), ftpServer) + new TXTRecord(txtRecord, DClass.IN, tenYears.getSeconds(), txtRecord) )); if (makeNewKeyPairs) { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services