Skip to content

Commit

Permalink
Release 0.4.0 (#4)
Browse files Browse the repository at this point in the history
- move compiled grammar.js into ./lib
- pass previousName into RR
- tinydns: move functions into lib/tinydns
- add: bind rr parsing for CAA, DNSKEY, DS, HINFO, LOC 
- import: add option hide-same-name
- rewrite the parser grammar
    - parser uses (mostly) BNFs from RFCs 🎉
- add parsing for RRs: naptr, rrsig, smimea, sshfp, spf, srv, tlsa, uri, "TYPE" uint (generic)
- tests: added tests for MX, NS, PTR, SOA, TXT
  • Loading branch information
msimerson committed Mar 27, 2022
1 parent b57e949 commit 81f0be8
Show file tree
Hide file tree
Showing 16 changed files with 899 additions and 468 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: npm install
run: npm install
- run: npm install

- name: Run test suite
run: npm run test
11 changes: 9 additions & 2 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on: [ pull_request ]

name: Coverage

env:
CI: true

jobs:

coverage:
Expand All @@ -21,11 +24,15 @@ jobs:
with:
node-version: 14

- name: install, run
- name: npm install
run: |
npm install
npm install --no-save nyc codecov
npm run cover
- name: run coverage
run: npx nyc --reporter=lcovonly npm run test
env:
NODE_ENV: cov

- name: Coveralls
uses: coverallsapp/github-action@master
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Lint

on: [ push ]

env:
CI: true

jobs:

lint:
Expand All @@ -24,11 +27,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: npm install
run: npm install
- run: npm install

- name: Lint using eslint
- name: Lint
run: npm run lint

env:
CI: true
16 changes: 13 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- master

env:
CI: true
node_version: 14

jobs:
Expand All @@ -26,10 +27,9 @@ jobs:
node-version: ${{ env.node_version }}
registry-url: https://registry.npmjs.org/

- name: npm install
run: npm install
- run: npm install

- name: Run test suite
- name: Run tests
run: npm run test

- name: publish to NPM
Expand All @@ -40,3 +40,13 @@ jobs:
- name: GitHub Release
uses: justincy/github-action-npm-release@2.0.1
id: release

- name: Coverage Run
run: |
npm install --no-save nyc codecov
npx nyc --reporter=lcovonly npm run test
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ dist

# TernJS port file
.tern-port
grammar.js
lib/grammar.js
package-lock.json
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ codecov.yml
.eslintrc.yaml
.eslintrc.json
package-lock.json
grammar.js
lib/grammar.js
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
#### 1.N.N - YYYY-MM-DD


#### 0.4.0 - 2022-03-26

- move compiled grammar.js into ./lib
- pass previousName into RR
- tinydns: move functions into lib/tinydns
- add: bind rr parsing for CAA, DNSKEY, DS, HINFO, LOC
- import: add option hide-same-name
- rewrite the parser grammar
- parser uses (mostly) BNFs from RFCs 🎉
- add parsing for RRs: naptr, rrsig, smimea, sshfp, spf, srv, tlsa, uri, TYPE{N} (generic)
- tests: added tests for MX, NS, PTR, SOA, TXT


#### 0.3.0 - 2022-03-24

- import
Expand Down
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,50 +62,44 @@ Examples
````


#### import to JS
#### import from STDIN to JS

````
➜ cat isi.edu | ./bin/import.js --origin=isi.edu
➜ cat example.com | ./bin/import.js --origin=example.com
[
SOA(12) [Map] {
'name' => 'isi.edu.',
'ttl' => 60,
'name' => 'example.com.',
'ttl' => 3600,
'class' => 'IN',
'type' => 'SOA',
'mname' => 'venera.isi.edu.',
'rname' => 'action.domains.isi.edu.',
'serial' => 20,
'mname' => 'ns.example.com.',
'rname' => 'username.example.com.',
'serial' => 2020091025,
'refresh' => 7200,
'retry' => 600,
'expire' => 3600000,
'minimum' => 60,
'comment' => {
serial: ' ; SERIAL',
refresh: ' ; REFRESH',
retry: ' ; RETRY',
expire: '; EXPIRE',
minimum: ''
}
'retry' => 3600,
'expire' => 1209600,
'minimum' => 3600,
'comment' => { serial: '', refresh: '', retry: '', expire: '', minimum: '' }
},
NS(5) [Map] {
'name' => 'isi.edu.',
'ttl' => 60,
'name' => 'example.com.',
'ttl' => 3600,
'class' => 'IN',
'type' => 'NS',
'dname' => 'a.isi.edu.'
'dname' => 'ns.example.com.'
},
...<snip>...
A(5) [Map] {
'name' => 'vaxa.isi.edu.',
'ttl' => 60,
'name' => 'mail3.example.com.',
'ttl' => 3600,
'class' => 'IN',
'type' => 'A',
'address' => '128.9.0.33'
'address' => '192.0.2.5'
}
]
````

#### to bind
#### from bind file to bind

````
➜ ./bin/import.js -i isi.edu -e bind
Expand All @@ -131,7 +125,7 @@ vaxa 60 IN A 10.2.0.27
vaxa 60 IN A 128.9.0.33
````

#### to bind (relative)
#### from bind to bind (relative)

````
➜ ./bin/import.js -i isi.edu -e bind --ttl=60 --hide-ttl --hide-class --hide-origin
Expand All @@ -158,7 +152,7 @@ vaxa A 128.9.0.33
````


#### to tinydns
#### from bind to tinydns

````
➜ ./bin/import.js -i isi.edu -e tinydns
Expand All @@ -177,10 +171,13 @@ Zisi.edu:venera.isi.edu:action.domains.isi.edu:20:7200:600:3600000:60:60::

## TODO

- [ ] write a named.conf file parser
- [x] write a bind zone file parser
- [ ] write a tinydns data file parser
- normalize the zone records
- importing
- [ ] write a named.conf file parser
- [x] write a bind zone file parser
- [x] write a tinydns data file parser
- [x] 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
- [x] missing TTLs inherit zone TTL, or zone MINIMUM
Expand All @@ -190,4 +187,7 @@ Zisi.edu:venera.isi.edu:action.domains.isi.edu:20:7200:600:3600000:60:60::
- [x] CNAME: cname,
- [x] SOA: mname, rname,
- [x] NS,PTR: dname
- [x] suppress hostname when identical to previous RR
- [ ] validate zone rules
- [ ] make it easy to add test cases: eg, test/fixtures/rr/{mx|a|*}/*
- [ ]
35 changes: 25 additions & 10 deletions bin/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const cmdLineArgs = require('command-line-args')
const cmdLineUsage = require('command-line-usage')

const dz = require('../index')
const tinydns = require('../lib/tinydns')
const RR = require('dns-resource-record')
const rr = new RR.A(null)

Expand All @@ -22,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 @@ -33,8 +35,9 @@ ingestZoneData()
.then(r => {
switch (r.type) {
case 'tinydns':
return dz.parseTinydnsData(r.data)
return tinydns.parseData(r.data)
default:
dz.zoneOpts = zone_opts
return dz.parseZoneFile(r.data).then(dz.expandShortcuts)
}
})
Expand Down Expand Up @@ -115,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 @@ -204,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 @@ -231,21 +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 81f0be8

Please sign in to comment.