2022-05-09 02:23:45 +08:00
# creds.json file format change
**Feel free to skip to "How do I convert?" if you don't care about the details.**
Starting in v3.16 the "provider type identifier" (PTI) will be located in
`creds.json` instead of `dnsconfig.js` . The PTI is the all caps string like
`ROUTE53` or `CLOUDFLAREAPI` used to identify a provider's type.
V3.16 will enable a syntax that is backwards and forwards compatible. The old
syntax will be removed in v4.0. There's no planned release date for v4.0 but
it is expected to be after Dec 31, 2022.
The change was discussed
in [Request for Comments: Include the provider type in creds.json, remove it from dnsconfig.js ](https://github.com/StackExchange/dnscontrol/issues/1457 ) where we decided "Plan A" would be selected.
# What does this mean to you?
In a nutshell, `NewRegistrar()` and `NewDnsProvider()` will lose the 2nd
parameter:
2023-01-20 20:56:20 +08:00
{% code title="dnscontrol.js" %}
```diff
var REG_GANDI = NewRegistrar(
- "gandi",
- "GANDI_V5"
+ "gandi"
);
var DSP_CF = NewDnsProvider(
- "cloudflare_tal",
- "CLOUDFLAREAPI"
+ "cloudflare_tal"
);
2022-05-09 02:23:45 +08:00
```
2023-01-20 20:56:20 +08:00
{% endcode %}
2022-05-09 02:23:45 +08:00
2022-11-03 21:12:08 +08:00
The second parameter (`GANDI_V5` and `CLOUDFLAREAPI` in the
2022-05-09 02:23:45 +08:00
above examples) has moved to `creds.json` instead. It will be in a `TYPE`
field, which all providers have. It can appear in both places for backwards compatibility for now.
2023-01-20 20:56:20 +08:00
{% code title="creds.json" %}
```diff
2022-05-09 02:23:45 +08:00
{
"gandi": {
2023-01-20 20:56:20 +08:00
+ "TYPE": "GANDI_V5",
2022-05-09 02:23:45 +08:00
"apikey": "reacted"
},
"cloudflare_tal": {
2023-01-20 20:56:20 +08:00
+ "TYPE": "CLOUDFLAREAPI",
2022-05-09 02:23:45 +08:00
"apikey": "reacted",
"apiuser": "reacted"
}
}
```
2023-01-20 20:56:20 +08:00
{% endcode %}
2022-05-09 02:23:45 +08:00
In the past, a provider didn't need an entry in `creds.json` if there were no credentials to be stored. Starting in v4.0 all providers must have an entry in `creds.json` . To aid the transition, starting in v3.16 warnings will appear on stdout that direct you to convert to the new format.
Also to help in the conversion, if no provider named "none" or "bind" exist, ones will be added for you. They look like this:
2023-01-20 20:56:20 +08:00
{% code title="creds.json" %}
2022-05-09 02:23:45 +08:00
```json
{
"none": { "TYPE": "NONE" },
"bind": { "TYPE": "BIND" }
}
```
2023-01-20 20:56:20 +08:00
{% endcode %}
2022-05-09 02:23:45 +08:00
# Command line tools
How does this affect command line tools?
The following subcommands require the PTI a parameter on the command line:
* `get-zone`
* `get-zones`
* `check-creds`
In 3.16, that parameter can be changed to `-` as a placeholder, or removed
entirely if it is the last parameter on the command line. When you omit this
2022-05-09 02:41:33 +08:00
parameter, DNSControl will find the value in `creds.json` instead.
2022-05-09 02:23:45 +08:00
In 4.0, that parameter will be removed, though a `-` is permitted for backwards compatibility.
In other words, if you add the `TYPE` field to `creds.json` , you no longer need
to specify it on the command line. You can specify `-` instead, or leave it
out entirely starting in v4.0.
For check-creds:
Starting in v3.16 these forms are valid:
2023-01-20 20:56:20 +08:00
```shell
dnscontrol check-creds myr53
dnscontrol check-creds myr53 -
dnscontrol check-creds myr53 ROUTE53
```
2022-05-09 02:23:45 +08:00
Starting in v4.0 this is the only valid form:
2023-01-20 20:56:20 +08:00
```shell
dnscontrol check-creds myr53
```
For backwards compatibility, these are valid until at least v5.0:
```shell
dnscontrol check-creds myr53 -
2022-05-09 02:23:45 +08:00
```
For get-zones/get-zone:
Starting in v3.16 these forms are valid:
2023-01-20 20:56:20 +08:00
```shell
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
```
2022-05-09 02:23:45 +08:00
Starting in v4.0 these forms are valid:
2023-01-20 20:56:20 +08:00
```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
2022-05-09 02:23:45 +08:00
```
# How do I convert?
## Step 1: Upgrade
2022-05-09 02:41:33 +08:00
Upgrade to v3.16 or later. If DNSControl is installed in many places, do not
2022-05-09 02:23:45 +08:00
continue until they are all at v3.16 or later.
## Step 2: Edit creds.json
Now that all uses of DNSControl are on v3.16 or later...
For each `creds.json` entry, add a field "TYPE" set to the provider type
identifier. This is the all-caps name such as `ROUTE53` , `GCLOUD` , or
`CLOUDFLAREAPI` .
For example, here is a new-style `creds.json` file with `TYPE` fields added:
2023-01-20 20:56:20 +08:00
{% code title="creds.json" %}
```diff
2022-05-09 02:23:45 +08:00
{
"bind_inside": {
2023-01-20 20:56:20 +08:00
+ "TYPE": "BIND",
2022-05-09 02:23:45 +08:00
"directory": "inzones"
},
"cloudflare_tal": {
2023-01-20 20:56:20 +08:00
+ "TYPE": "CLOUDFLAREAPI",
2022-05-09 02:23:45 +08:00
"apikey": "redacted",
"apiuser": "redacted"
},
"gandi": {
2023-01-20 20:56:20 +08:00
+ "TYPE": "GANDI_V5",
2022-05-09 02:23:45 +08:00
"apikey": "redacted"
2023-01-20 20:56:20 +08:00
}
}
2022-05-09 02:23:45 +08:00
```
2023-01-20 20:56:20 +08:00
{% endcode %}
2022-05-09 02:23:45 +08:00
## Step 3: Cross-check
Run `dnscontrol preview` as one normally would. Fix any errors, warnings, or informational messages that appear on stdout.
Here are some examples:
2022-05-09 02:41:33 +08:00
If you see something like...
2022-11-01 06:09:43 +08:00
```text
2023-01-20 20:56:20 +08:00
WARNING: For future compatibility, update the "namedotcom_main" entry in `creds.json` by adding: "TYPE": "NAMEDOTCOM", (See https://docs.dnscontrol.org/commands/creds-json#missing)
2022-05-09 02:23:45 +08:00
```
2022-05-09 02:41:33 +08:00
...it means that the TYPE field is missing from that entry in `creds.json` .
If you see something like...
2022-11-01 06:09:43 +08:00
```text
2023-01-20 20:56:20 +08:00
ERROR: Mismatch found! creds.json entry "namedotcom_main" has "TYPE" set to "ROUTE53" but dnsconfig.js specifies New*("namedotcom_main", "NAMEDOTCOM") (See https://docs.dnscontrol.org/commands/creds-json#mismatch)
2022-05-09 02:23:45 +08:00
```
2022-05-09 02:41:33 +08:00
...it means your `dnsconfig.js` and `creds.json` specify mismatched values. Fix one or the other.
After you correct some warnings, you may receive information messages like...
2022-05-09 02:23:45 +08:00
2022-11-01 06:09:43 +08:00
```text
2023-01-20 20:56:20 +08:00
INFO: In dnsconfig.js New*("namedotcom_main", "NAMEDOTCOM") can be simplified to New*("namedotcom_main") (See https://docs.dnscontrol.org/commands/creds-json#cleanup)
2022-05-09 02:23:45 +08:00
```
2022-05-09 02:41:33 +08:00
...which is a message that will disappear as you update `dnsconfig.js` in the next step.
2022-05-09 02:23:45 +08:00
## Step 4: Edit dnsconfig.js
Remove the 2nd parameter to any NewDnsProvider() or NewRegistrar() functions.
2023-01-20 20:56:20 +08:00
{% code title="dnsconfig.js" %}
```diff
var REG_NAMEDOTCOM_TAL = NewRegistrar(
- "namedotcom_tal",
- "NAMEDOTCOM"
+ "namedotcom_tal"
);
var DNS_GANDI_TAL = NewDnsProvider(
- "gandi_v5_tal",
- "GANDI_V5"
+ "gandi_v5_tal"
);
2022-05-09 02:23:45 +08:00
```
2023-01-20 20:56:20 +08:00
{% endcode %}
2022-05-09 02:23:45 +08:00
Again, run `dnscontrol preview` to verify you setup still works as expected.
## Step 5: Update any shell scripts
Any shell scripts or documentation that uses the subcommands `get-zone` ,
`get-zones` or `check-creds` should be updated. The "provider type" parameter
should be changed to `-` . If it is the last parameter on the command, it can
be removed.
It's unlikely you have scripts that use these commands. However you may have
documentation that refers to them and needs to be updated.
## Step 4: Test
Run `dnscontrol preview` as one normally would. Fix any errors, warnings, or informational messages that appear on stdout.
2023-01-20 20:56:20 +08:00
## Step 5: Done
2022-05-09 02:23:45 +08:00
That's it!