Skip to content

Commit

Permalink
import: add hide-same-name option
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Mar 26, 2022
1 parent b8528e5 commit 1a915ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Zisi.edu:venera.isi.edu:action.domains.isi.edu:20:7200:600:3600000:60:60::
- [x] write a bind zone file parser
- [x] write a tinydns data file parser
- [ ] add BIND parsing for all RRs supported by dns-rr
- [ ] add support for $INCLUDE (RFC 1035)
- normalize BIND zone records
- [x] expand `@` to zone name
- [x] empty names are same as previous RR record
Expand Down
31 changes: 22 additions & 9 deletions bin/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const zone_opts = {
ttl : opts.ttl || 0,
class : opts.class || 'IN',
hide : {
class : opts['hide-class'],
ttl : opts['hide-ttl'],
origin: opts['hide-origin'],
class : opts['hide-class'],
ttl : opts['hide-ttl'],
origin : opts['hide-origin'],
sameName: opts['hide-same-name'],
},
}
if (opts.verbose) console.error(zone_opts)
Expand All @@ -36,6 +37,7 @@ ingestZoneData()
case 'tinydns':
return tinydns.parseData(r.data)
default:
dz.zoneOpts = zone_opts
return dz.parseZoneFile(r.data).then(dz.expandShortcuts)
}
})
Expand Down Expand Up @@ -116,6 +118,13 @@ function usageOptions () {
description : 'hide TTLs (default: false)',
group : 'out',
},
{
name : 'hide-same-name',
defaultValue: false,
type : Boolean,
description : 'hide name when same as previous RR',
group : 'out',
},
{
name : 'verbose',
alias : 'v',
Expand Down Expand Up @@ -205,11 +214,6 @@ function ingestZoneData () {

res.data = buf.toString()

if (res.type === 'bind' && !/^\$ORIGIN/m.test(res.data)) {
if (opts.verbose) console.error(`inserting $ORIGIN ${zone_opts.origin}`)
res.data = `$ORIGIN ${zone_opts.origin}${os.EOL}${res.data}`
}

resolve(res)
})
})
Expand All @@ -232,22 +236,31 @@ function output (zoneArray) {
}
}

function isBlank (rr) {
if (rr === os.EOL) {
process.stdout.write(rr)
return true
}
}

function toBind (zoneArray, origin) {
for (const rr of zoneArray) {
if (isBlank(rr)) continue
process.stdout.write(rr.toBind(zone_opts))
zone_opts.previousName = rr.get('name')
}
}

function toTinydns (zoneArray) {
for (const rr of zoneArray) {
if (isBlank(rr)) continue
process.stdout.write(rr.toTinydns())
}
}

function toJSON (zoneArray) {
for (const rr of zoneArray) {
// console.error(rr)
if (isBlank(rr)) continue
if (rr.get('comment')) rr.delete('comment')
process.stdout.write(JSON.stringify(Object.fromEntries(rr)))
}
Expand Down

0 comments on commit 1a915ab

Please sign in to comment.