Skip to content

Commit c9c671c

Browse files
authored
feat(dns): update set command and fix doc (#1947)
Co-authored-by: Jeremy JACQUEMIN <[email protected]>
1 parent 0e634d3 commit c9c671c

10 files changed

+131
-25
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ scw k8s cluster create name=foo version=1.17.4 pools.0.size=3 pools.0.node-type=
165165
| `config` | Config file management | [CLI](./docs/commands/config.md) |
166166
| `feedback` | Send feedback to the Scaleway CLI Team! | [CLI](./docs/commands/feedback.md) |
167167
| `info` | Get info about current settings | [CLI](./docs/commands/info.md) |
168-
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |
169168
| `init` | Initialize the config | [CLI](./docs/commands/init.md) |
169+
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |
170+
| `dns` | DNS API | [CLI](./docs/commands/dns.md) / [API](https://developers.scaleway.com/en/products/domain/dns/api/) |
170171
| `instance` | Instance API | [CLI](./docs/commands/instance.md) / [API](https://developers.scaleway.com/en/products/instance/api/) |
171172
| `k8s` | Kapsule API | [CLI](./docs/commands/k8s.md) / [API](https://developers.scaleway.com/en/products/k8s/api/) |
172173
| `marketplace` | Marketplace API | [CLI](./docs/commands/marketplace.md) |

cmd/scw/testdata/test-all-usage-dns-record-add-usage.golden

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ Add a new DNS record
55
USAGE:
66
scw dns record add <dns-zone ...> [arg=value ...]
77

8+
EXAMPLES:
9+
Add a CNAME
10+
scw dns record add my-domain.tld data=www name=www2 type=CNAME
11+
12+
Add an IP
13+
scw dns record add my-domain.tld data=1.2.3.4 name=vpn type=A
14+
815
ARGS:
916
dns-zone DNS zone in which to add the record
1017
data
1118
[name]
1219
[priority]
1320
ttl=300
14-
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
21+
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)
1522
[comment]
1623
[geo-ip-config.matches.{index}.countries.{index}]
1724
[geo-ip-config.matches.{index}.continents.{index}]

cmd/scw/testdata/test-all-usage-dns-record-delete-usage.golden

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ Delete a DNS record
55
USAGE:
66
scw dns record delete <dns-zone ...> [arg=value ...]
77

8+
EXAMPLES:
9+
Delete a CNAME
10+
scw dns record delete my-domain.tld name=www type=CNAME
11+
12+
Delete a single IP from a record with more than one
13+
scw dns record delete my-domain.tld data=1.2.3.4 name=vpn type=A
14+
815
ARGS:
916
dns-zone DNS zone in which to delete the record
1017
[data]
1118
[name]
1219
[ttl]
13-
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
20+
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)
1421

1522
FLAGS:
1623
-h, --help help for delete

cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
This command will clear all the data for this record, replacing it with the given data.
3+
This command will replace all the data for this record with the given values.
44

55
USAGE:
66
scw dns record set <dns-zone ...> [arg=value ...]
77

8+
EXAMPLES:
9+
Add or replace a CNAME
10+
scw dns record set my-domain.tld values.0=www name=www2 type=CNAME
11+
12+
Add or replace a list of IP
13+
scw dns record set my-domain.tld values.0=1.2.3.4 values.1=1.2.3.5 name=vpn type=A
14+
815
ARGS:
916
dns-zone DNS zone in which to set the record
10-
data.{index}
11-
[name]
17+
values.{index} A list of values for replacing the record data. (multiple values cannot be used for all type)
18+
name
1219
[priority]
1320
ttl=300
14-
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
21+
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)
1522
[comment]
1623
[geo-ip-config.matches.{index}.countries.{index}]
1724
[geo-ip-config.matches.{index}.continents.{index}]

cmd/scw/testdata/test-all-usage-dns-record-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ AVAILABLE COMMANDS:
1212
delete Delete a DNS record
1313
list List DNS zone records
1414
list-nameservers List DNS zone nameservers
15-
set Clear and set a DNS record
15+
set Update a DNS record
1616
update-nameservers Update DNS zone nameservers
1717

1818
FLAGS:

docs/commands/dns.md

+53-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Manage your DNS zones and records.
1414
- [Delete a DNS record](#delete-a-dns-record)
1515
- [List DNS zone records](#list-dns-zone-records)
1616
- [List DNS zone nameservers](#list-dns-zone-nameservers)
17-
- [Clear and set a DNS record](#clear-and-set-a-dns-record)
17+
- [Update a DNS record](#update-a-dns-record)
1818
- [Update DNS zone nameservers](#update-dns-zone-nameservers)
1919
- [Transaction SIGnature key management](#transaction-signature-key-management)
2020
- [Delete the DNS zone TSIG Key](#delete-the-dns-zone-tsig-key)
@@ -143,7 +143,7 @@ scw dns record add <dns-zone ...> [arg=value ...]
143143
| name | | |
144144
| priority | | |
145145
| ttl | Required<br />Default: `300` | |
146-
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | |
146+
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS`, `LOC`, `SSHFP`, `HINFO`, `RP`, `URI`, `DS`, `NAPTR` | |
147147
| comment | | |
148148
| geo-ip-config.matches.{index}.countries.{index} | | |
149149
| geo-ip-config.matches.{index}.continents.{index} | | |
@@ -160,6 +160,21 @@ scw dns record add <dns-zone ...> [arg=value ...]
160160
| view-config.views.{index}.data | | |
161161

162162

163+
**Examples:**
164+
165+
166+
Add a CNAME
167+
```
168+
scw dns record add my-domain.tld data=www name=www2 type=CNAME
169+
```
170+
171+
Add an IP
172+
```
173+
scw dns record add my-domain.tld data=1.2.3.4 name=vpn type=A
174+
```
175+
176+
177+
163178

164179
### Update DNS zone records
165180

@@ -289,7 +304,22 @@ scw dns record delete <dns-zone ...> [arg=value ...]
289304
| data | | |
290305
| name | | |
291306
| ttl | | |
292-
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | |
307+
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS`, `LOC`, `SSHFP`, `HINFO`, `RP`, `URI`, `DS`, `NAPTR` | |
308+
309+
310+
**Examples:**
311+
312+
313+
Delete a CNAME
314+
```
315+
scw dns record delete my-domain.tld name=www type=CNAME
316+
```
317+
318+
Delete a single IP from a record with more than one
319+
```
320+
scw dns record delete my-domain.tld data=1.2.3.4 name=vpn type=A
321+
```
322+
293323

294324

295325

@@ -338,9 +368,9 @@ scw dns record list-nameservers <dns-zone ...> [arg=value ...]
338368

339369

340370

341-
### Clear and set a DNS record
371+
### Update a DNS record
342372

343-
This command will clear all the data for this record, replacing it with the given data.
373+
This command will replace all the data for this record with the given values.
344374

345375
**Usage:**
346376

@@ -354,11 +384,11 @@ scw dns record set <dns-zone ...> [arg=value ...]
354384
| Name | | Description |
355385
|------|---|-------------|
356386
| dns-zone | Required | DNS zone in which to set the record |
357-
| data.{index} | Required | |
358-
| name | | |
387+
| values.{index} | Required | A list of values for replacing the record data. (multiple values cannot be used for all type) |
388+
| name | Required | |
359389
| priority | | |
360390
| ttl | Required<br />Default: `300` | |
361-
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | |
391+
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS`, `LOC`, `SSHFP`, `HINFO`, `RP`, `URI`, `DS`, `NAPTR` | |
362392
| comment | | |
363393
| geo-ip-config.matches.{index}.countries.{index} | | |
364394
| geo-ip-config.matches.{index}.continents.{index} | | |
@@ -375,6 +405,21 @@ scw dns record set <dns-zone ...> [arg=value ...]
375405
| view-config.views.{index}.data | | |
376406

377407

408+
**Examples:**
409+
410+
411+
Add or replace a CNAME
412+
```
413+
scw dns record set my-domain.tld values.0=www name=www2 type=CNAME
414+
```
415+
416+
Add or replace a list of IP
417+
```
418+
scw dns record set my-domain.tld values.0=1.2.3.4 values.1=1.2.3.5 name=vpn type=A
419+
```
420+
421+
422+
378423

379424
### Update DNS zone nameservers
380425

internal/namespaces/domain/v2beta1/custom.go

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
domain "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
77
)
88

9+
var (
10+
domainTypes = []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS", "LOC", "SSHFP", "HINFO", "RP", "URI", "DS", "NAPTR"}
11+
)
12+
913
// GetCommands returns dns commands.
1014
//
1115
// This function:

internal/namespaces/domain/v2beta1/custom_record_add.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func dnsRecordAddCommand() *core.Command {
5858
Required: true,
5959
Deprecated: false,
6060
Positional: false,
61-
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
61+
EnumValues: domainTypes,
6262
},
6363
{
6464
Name: "comment",
@@ -147,6 +147,16 @@ func dnsRecordAddCommand() *core.Command {
147147
},
148148
},
149149
Run: dnsRecordAddRun,
150+
Examples: []*core.Example{
151+
{
152+
Short: "Add a CNAME",
153+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www2", "type": "CNAME", "data": "www"}`,
154+
},
155+
{
156+
Short: "Add an IP",
157+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "data": "1.2.3.4"}`,
158+
},
159+
},
150160
}
151161
}
152162

internal/namespaces/domain/v2beta1/custom_record_delete.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ func dnsRecordDeleteCommand() *core.Command {
5454
Required: true,
5555
Deprecated: false,
5656
Positional: false,
57-
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
57+
EnumValues: domainTypes,
5858
},
5959
},
6060
Run: dnsRecordDeleteRun,
61+
Examples: []*core.Example{
62+
{
63+
Short: "Delete a CNAME",
64+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www", "type": "CNAME"}`,
65+
},
66+
{
67+
Short: "Delete a single IP from a record with more than one",
68+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "data": "1.2.3.4"}`,
69+
},
70+
},
6171
}
6272
}
6373

internal/namespaces/domain/v2beta1/custom_record_set.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111

1212
type dnsRecordSetRequest struct {
1313
DNSZone string
14-
Data []string
14+
Values []string
1515
*domain.Record
1616
}
1717

1818
func dnsRecordSetCommand() *core.Command {
1919
return &core.Command{
20-
Short: `Clear and set a DNS record`,
21-
Long: `This command will clear all the data for this record, replacing it with the given data.`,
20+
Short: `Update a DNS record`,
21+
Long: `This command will replace all the data for this record with the given values.`,
2222
Namespace: "dns",
2323
Verb: "set",
2424
Resource: "record",
@@ -31,14 +31,15 @@ func dnsRecordSetCommand() *core.Command {
3131
Positional: true,
3232
},
3333
{
34-
Name: "data.{index}",
34+
Name: "values.{index}",
35+
Short: "A list of values for replacing the record data. (multiple values cannot be used for all type)",
3536
Required: true,
3637
Deprecated: false,
3738
Positional: false,
3839
},
3940
{
4041
Name: "name",
41-
Required: false,
42+
Required: true,
4243
Deprecated: false,
4344
Positional: false,
4445
},
@@ -60,7 +61,7 @@ func dnsRecordSetCommand() *core.Command {
6061
Required: true,
6162
Deprecated: false,
6263
Positional: false,
63-
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
64+
EnumValues: domainTypes,
6465
},
6566
{
6667
Name: "comment",
@@ -149,6 +150,16 @@ func dnsRecordSetCommand() *core.Command {
149150
},
150151
},
151152
Run: dnsRecordSetRun,
153+
Examples: []*core.Example{
154+
{
155+
Short: "Add or replace a CNAME",
156+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www2", "type": "CNAME", "values": ["www"]}`,
157+
},
158+
{
159+
Short: "Add or replace a list of IP",
160+
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "values": ["1.2.3.4", "1.2.3.5"]}`,
161+
},
162+
},
152163
}
153164
}
154165

@@ -169,7 +180,11 @@ func dnsRecordSetRun(ctx context.Context, argsI interface{}) (i interface{}, e e
169180
},
170181
}
171182

172-
for _, data := range request.Data {
183+
if len(request.Values) == 0 {
184+
return nil, fmt.Errorf("at least one values (eg: values.0) is required")
185+
}
186+
187+
for _, data := range request.Values {
173188
record := *request.Record
174189
record.Data = data
175190
dnsRecordSetReq.Changes[0].Set.Records = append(dnsRecordSetReq.Changes[0].Set.Records, &record)

0 commit comments

Comments
 (0)