Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 36 additions & 39 deletions commands/getZones.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,52 @@ var _ = cmd(catUtils, func() *cli.Command {
Aliases: []string{"get-zone"},
Usage: "gets a zone from a provider (stand-alone)",
Action: func(ctx context.Context, c *cli.Command) error {
if c.NArg() < 3 {
return cli.Exit("Arguments should be: credskey providername zone(s) (Ex: r53 ROUTE53 example.com)", 1)
if c.NArg() < 2 {
return cli.Exit("Arguments should be: credskey zone(s) (Ex: my_cloudflare example.com)", 1)
}
args.CredName = c.Args().Get(0)
arg1 := c.Args().Get(1)
args.ProviderName = arg1
// In v4.0, skip the first args.ZoneNames if it equals "-".
args.ZoneNames = c.Args().Slice()[2:]

if arg1 != "" && arg1 != "-" {
// NB(tlim): In v4.0 this "if" can be removed.
fmt.Fprintf(os.Stderr, "WARNING: To retain compatibility in future versions, please change %q to %q. See %q\n",
arg1, "-",
"https://docs.dnscontrol.org/commands/get-zones",
)
if c.NArg() == 2 || c.Args().Get(1) == "-" {
args.ProviderName = ""
if c.Args().Get(1) == "-" {
args.ZoneNames = c.Args().Slice()[2:]
} else {
args.ZoneNames = c.Args().Slice()[1:]
}
} else {
arg1 := c.Args().Get(1)
if _, ok := providers.DNSProviderTypes[arg1]; ok {
// Deprecated form: credkey provider zone [...]
args.ProviderName = arg1
args.ZoneNames = c.Args().Slice()[2:]
fmt.Fprintf(os.Stderr, "WARNING: The provider name argument is deprecated. Please use \"dnscontrol get-zones %s %s\" instead. See %q\n",
args.CredName, strings.Join(args.ZoneNames, " "),
"https://docs.dnscontrol.org/commands/get-zones",
)
} else {
// New form with multiple zones: credkey zone1 zone2 [...]
args.ProviderName = ""
args.ZoneNames = c.Args().Slice()[1:]
}
}

return exit(GetZone(args))
},
Flags: args.flags(),
UsageText: "dnscontrol get-zones [command options] credkey provider zone [...]",
UsageText: "dnscontrol get-zones [command options] credkey zone [...]",
Description: `Download a zone from a provider. This is a stand-alone utility.

ARGUMENTS:
credkey: The name used in creds.json (first parameter to NewDnsProvider() in dnsconfig.js)
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
credkey: The name used in creds.json
zone: One or more zones (domains) to download; or "all".

FORMATS:
--format=js dnsconfig.js format (not perfect, just a decent first draft)
--format=djs js with disco commas (leading commas)
--format=zone BIND zonefile format
--format=tsv TAB separated value (useful for AWK)
--format=nameonly Just print the zone names

The columns in --format=tsv 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)
Either empty or a comma-separated list of properties like "cloudflare_proxy=true"

The --ttl flag only applies to zone/js/djs formats.

EXAMPLES:
dnscontrol get-zones myr53 ROUTE53 example.com
dnscontrol get-zones gmain GANDI_V5 example.com other.com
dnscontrol get-zones cfmain CLOUDFLAREAPI all
dnscontrol get-zones --format=tsv bind BIND example.com
dnscontrol get-zones --format=djs --out=draft.js gcloud GCLOUD example.com`,
dnscontrol get-zones my_route53 example.com
dnscontrol get-zones my_gandi example.com other.com
dnscontrol get-zones my_cloudflare all
dnscontrol get-zones --format=tsv my_bind example.com
dnscontrol get-zones --format=djs --out=draft.js my_gcloud example.com

Documentation: https://docs.dnscontrol.org/commands/get-zones`,
}
}())

Expand Down Expand Up @@ -120,7 +115,9 @@ ARGUMENTS:
EXAMPLES:
dnscontrol check-creds myr53 ROUTE53 # Pre v3.16, or pre-v4.0 for backwards-compatibility
dnscontrol check-creds myr53
dnscontrol check-creds --out=/dev/null myr53 && echo Success`,
dnscontrol check-creds --out=/dev/null myr53 && echo Success

Documentation: https://docs.dnscontrol.org/commands/check-creds`,
}
}())

Expand Down
52 changes: 8 additions & 44 deletions documentation/commands/get-zones.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If a provider supports it, `--format=nameonly` lists the names of the zones at t
## Syntax

```shell
dnscontrol get-zones [command options] credkey provider zone [...]
dnscontrol get-zones [command options] credkey zone [...]

--creds value Provider credentials JSON file (default: "creds.json")
--format value Output format: js djs zone tsv nameonly (default: "zone")
Expand All @@ -42,13 +42,10 @@ dnscontrol get-zones [command options] credkey provider zone [...]

ARGUMENTS:
credkey: The name used in creds.json (first parameter to NewDnsProvider() in dnsconfig.js)
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
zone: One or more zones (domains) to download; or "all".
```

As of [v3.16](../release/v316.md), `provider` can be `-` to indicate that the provider name is listed in `creds.json` in the `TYPE` field. Doing this will be backwards compatible with an (otherwise) breaking change due in v4.0.

As of v4.0 (BREAKING CHANGE), you must not specify `provider`. That value is found in the `TYPE` field of the credkey's `creds.json` file. For backwards compatibility, if the first `zone` is `-`, it will be skipped.
The provider type is read from the `TYPE` field in `creds.json`. For backwards compatibility, you may still specify the provider name explicitly as a second argument (e.g. `dnscontrol get-zones my_route53 ROUTE53 example.com`), but this is deprecated.

```shell
FORMATS:
Expand All @@ -73,50 +70,17 @@ The `--ttl` flag only applies to zone/js/djs formats.
## Examples

```shell
dnscontrol get-zones myr53 ROUTE53 example.com
dnscontrol get-zones gmain GANDI_V5 example.comn other.com
dnscontrol get-zones cfmain CLOUDFLAREAPI all
dnscontrol get-zones --format=tsv bind BIND example.com
dnscontrol get-zones --format=djs --out=draft.js glcoud GCLOUD example.com
```

As of [v3.16](../release/v316.md):

```shell
# NOTE: When "-" appears as the 2nd argument, it is assumed that the
# creds.json entry has a field TYPE with the provider's type name.
dnscontrol get-zones gmain GANDI_V5 example.comn other.com
dnscontrol get-zones gmain - example.comn other.com
dnscontrol get-zones cfmain CLOUDFLAREAPI all
dnscontrol get-zones cfmain - all
dnscontrol get-zones --format=tsv bind BIND example.com
dnscontrol get-zones --format=tsv bind - example.com
dnscontrol get-zones --format=djs --out=draft.js glcoud GCLOUD example.com
dnscontrol get-zones --format=djs --out=draft.js glcoud - example.com
```

As of v4.0:

```shell
dnscontrol get-zones gmain example.comn other.com
dnscontrol get-zones cfmain all
dnscontrol get-zones --format=tsv bind example.com
dnscontrol get-zones --format=djs --out=draft.js glcoud example.com
```

For backwards compatibility, these are valid until at least v5.0

```shell
dnscontrol get-zones gmain - example.comn other.com
dnscontrol get-zones cfmain - all
dnscontrol get-zones --format=tsv bind - example.com
dnscontrol get-zones --format=djs --out=draft.js glcoud - example.com
dnscontrol get-zones my_route53 example.com
dnscontrol get-zones my_gandi example.com other.com
dnscontrol get-zones my_cloudflare all
dnscontrol get-zones --format=tsv my_bind example.com
dnscontrol get-zones --format=djs --out=draft.js my_gcloud example.com
```

Read a zonefile, generate a JS file, then use the JS file to see how different it is from the zonefile:

```shell
dnscontrol get-zone --format=djs -out=foo.djs bind - example.com
dnscontrol get-zones --format=djs --out=foo.djs my_bind example.com
dnscontrol preview --config foo.js
```

Expand Down
Loading