get-zones: new output format nameonly; remove tsvfqdn (#644)

* Add nameonly; remove tsvfqdn

* document tsv fields
This commit is contained in:
Tom Limoncelli 2020-02-21 14:59:47 -05:00 committed by GitHub
parent 1ec696e4fa
commit 3c507d6b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 27 deletions

View file

@ -38,10 +38,10 @@ ARGUMENTS:
zone: One or more zones (domains) to download; or "all".
FORMATS:
--format=dsl dnsconfig.js format (a decent first draft)
--format=pretty BIND Zonefile format
--format=tsv TAB separated value (useful for AWK)
--format=tsvfqdn tsv with FQDNs (useful for multiple zones)
--format=dsl dnsconfig.js format (not perfect, but a decent first draft)
--format=nameonly Just print the zone names
--format=pretty BIND Zonefile format
--format=tsv TAB separated value (useful for AWK)
EXAMPLES:
dnscontrol get-zones myr53 ROUTE53 example.com
@ -69,7 +69,7 @@ func (args *GetZoneArgs) flags() []cli.Flag {
Name: "format",
Destination: &args.OutputFormat,
Value: "pretty",
Usage: `Output format: dsl pretty tsv tsvfqdn`,
Usage: `Output format: dsl pretty tsv nameonly`,
})
flags = append(flags, &cli.StringFlag{
Name: "out",
@ -113,6 +113,23 @@ func GetZone(args GetZoneArgs) error {
}
}
// first open output stream and print initial header (if applicable)
w := os.Stdout
if args.OutputFile != "" {
w, err = os.Create(args.OutputFile)
}
if err != nil {
return err
}
defer w.Close()
if args.OutputFormat == "nameonly" {
for _, zone := range zones {
fmt.Fprintln(w, zone)
}
return nil
}
// actually fetch all of the records
zoneRecs := make([]models.Records, len(zones))
for i, zone := range zones {
@ -125,23 +142,15 @@ func GetZone(args GetZoneArgs) error {
// Write it out:
// first open output stream and print initial header (if applicable)
w := os.Stdout
if args.OutputFile != "" {
w, err = os.Create(args.OutputFile)
}
if err != nil {
return err
}
defer w.Close()
if args.OutputFormat == "dsl" {
fmt.Fprintf(w, `var %s = NewDnsProvider("%s", "%s");`+"\n",
args.CredName, args.CredName, args.ProviderName)
}
// now print all zones
for i, recs := range zoneRecs {
zoneName := zones[i]
// now print all zones
z := prettyzone.PrettySort(recs, zoneName, 0)
switch args.OutputFormat {
case "pretty":
@ -159,14 +168,8 @@ func GetZone(args GetZoneArgs) error {
case "tsv":
for _, rec := range recs {
fmt.Fprintf(w,
fmt.Sprintf("%s\t%d\tIN\t%s\t%s\n",
rec.Name, rec.TTL, rec.Type, rec.GetTargetCombined()))
}
case "tsvfqdn":
for _, rec := range recs {
fmt.Fprintf(w,
fmt.Sprintf("%s\t%d\tIN\t%s\t%s\n",
rec.NameFQDN, rec.TTL, rec.Type, rec.GetTargetCombined()))
fmt.Sprintf("%s\t%s\t%d\tIN\t%s\t%s\n",
rec.NameFQDN, rec.Name, rec.TTL, rec.Type, rec.GetTargetCombined()))
}
default:
return fmt.Errorf("format %q unknown", args.OutputFile)

View file

@ -19,7 +19,7 @@ Syntax:
dnscontrol get-zones [command options] credkey provider zone [...]
--creds value Provider credentials JSON file (default: "creds.json")
--format value Output format: dsl tsv pretty (default: "pretty")
--format value Output format: pretty dsl tsv nameonly (default: "pretty")
--out value Instead of stdout, write to this file
ARGUMENTS:
@ -27,6 +27,19 @@ ARGUMENTS:
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
zone: One or more zones (domains) to download; or "all".
FORMATS:
--format=dsl dnsconfig.js format (not perfect, but a decent first draft)
--format=nameonly Just print the zone names
--format=pretty BIND Zonefile format
--format=tsv TAB separated value (useful for AWK)
When using `tsv`, the columns are:
FQDN (the label with the domain)
ShortName (just the label, "@" if it is the naked domain)
TTL
Record Type (A, AAAA, CNAME, etc.)
Target and arguments (quoted like in a zonefile)
EXAMPLES:
dnscontrol get-zones myr53 ROUTE53 example.com
dnscontrol get-zones gmain GANDI_V5 example.comn other.com
@ -76,9 +89,9 @@ Once that is done the `get-zone` subcommand should work.
4. Optionally implemement the `ListZones` function
If the `ListZones` function is implemented, the command will activate
the ability to specify `all` as the zone, at which point all zones
will be downloaded.
If the `ListZones` function is implemented, the "all" special case
will be activated. In this case, listing a single zone named `all`
will query the provider for the list of zones.
(Technically what is happening is by implementing the `ListZones`
function, you are completing the `ZoneLister` interface for that