Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

DNS Zone.import fails on default TTL #9

Closed
stephenplusplus opened this issue Oct 24, 2017 · 2 comments
Closed

DNS Zone.import fails on default TTL #9

stephenplusplus opened this issue Oct 24, 2017 · 2 comments
Assignees
Labels
api: dns Issues related to the googleapis/nodejs-dns API. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@stephenplusplus
Copy link
Contributor

From @timwsuqld on August 21, 2017 23:4

Environment details

  • OS: Linux
  • Node.js version: 4.2.6
  • npm version: 3.5.2
  • google-cloud-node version: 0.6.2

Steps to reproduce

  1. Attempt to import a zonefile with a $TTL variable
require('@google-cloud/dns')();
... // fetch zone
zone.import('zonefile').then(function(data) {
  console.log(data);
});

zonefile

$TTL 3600
test.com.                            IN SOA  ns.test.com. domains.test.com. (
                                         2016102701  ; sn
                                         1d ; ref
                                         2h ; retry
                                         4w ; expiry
                                         1h ; min
)
test.com.                            A       1.2.3.4

Throws the error

/home/timw/src/zonefiles/node_modules/string-format-obj/index.js:12
  return template.replace(/{([^}]*)}/g, function (match, key) {
                 ^

TypeError: Cannot read property 'replace' of undefined
    at interpolate (/home/timw/src/zonefiles/node_modules/string-format-obj/index.js:12:18)
    at module.exports (/home/timw/src/zonefiles/node_modules/string-format-obj/index.js:8:10)
    at Function.Record.fromZoneRecord_ (/home/timw/src/zonefiles/node_modules/@google-cloud/dns/src/record.js:92:11)
    at /home/timw/src/zonefiles/node_modules/@google-cloud/dns/src/zone.js:806:37
    at Array.forEach (native)
    at /home/timw/src/zonefiles/node_modules/@google-cloud/dns/src/zone.js:805:21
    at Array.forEach (native)
    at /home/timw/src/zonefiles/node_modules/@google-cloud/dns/src/zone.js:802:17
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

@google-cloud/dns/src/record.js (around 92) doesn't have a record type TTL, hence the error.

Record.fromZoneRecord_ = function(zone, type, bindData) {
  var typeToZoneFormat = {
    a: '{ip}',
    aaaa: '{ip}',
    cname: '{alias}',
    mx: '{preference} {host}',
    ns: '{host}',
    soa: '{mname} {rname} {serial} {retry} {refresh} {expire} {minimum}',
    spf: '{data}',
    srv: '{priority} {weight} {port} {target}',
    txt: '{txt}'
  };

  var metadata = {
    data: format(typeToZoneFormat[type.toLowerCase()], bindData),
    name: bindData.name,
    ttl: bindData.ttl
  };

  return new Record(zone, type, metadata);
};

The underlying dns-zonefile library understands the $TTL variable, and parses it without issues, we just need to not attempt to make a record from the $TTL variable, and instead use that as the default TTL unless it's overridden by the individual record.

The gcloud dns record-sets import --zone-file-format correctly understands the TTL variable and imports without an issue.

Copied from original issue: googleapis/google-cloud-node#2550

@lukesneeringer lukesneeringer added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Nov 10, 2017
@stephenplusplus stephenplusplus added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Feb 20, 2018
@ghost ghost assigned stephenplusplus Mar 14, 2018
@ghost ghost removed the priority: p2 Moderately-important priority. Fix may not be included in next release. label Mar 14, 2018
@timwhite
Copy link

@stephenplusplus Thanks. I've finally gotten to testing this and it's working fine

@stephenplusplus
Copy link
Contributor Author

Thanks!

@google-cloud-label-sync google-cloud-label-sync bot added the api: dns Issues related to the googleapis/nodejs-dns API. label Jan 31, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: dns Issues related to the googleapis/nodejs-dns API. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants