Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dns): update set command and fix doc #1947

Merged
merged 1 commit into from
Jul 7, 2021
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ scw k8s cluster create name=foo version=1.17.4 pools.0.size=3 pools.0.node-type=
| `config` | Config file management | [CLI](./docs/commands/config.md) |
| `feedback` | Send feedback to the Scaleway CLI Team! | [CLI](./docs/commands/feedback.md) |
| `info` | Get info about current settings | [CLI](./docs/commands/info.md) |
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |
| `init` | Initialize the config | [CLI](./docs/commands/init.md) |
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |
| `dns` | DNS API | [CLI](./docs/commands/dns.md) / [API](https://developers.scaleway.com/en/products/domain/dns/api/) |
| `instance` | Instance API | [CLI](./docs/commands/instance.md) / [API](https://developers.scaleway.com/en/products/instance/api/) |
| `k8s` | Kapsule API | [CLI](./docs/commands/k8s.md) / [API](https://developers.scaleway.com/en/products/k8s/api/) |
| `marketplace` | Marketplace API | [CLI](./docs/commands/marketplace.md) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ Add a new DNS record
USAGE:
scw dns record add <dns-zone ...> [arg=value ...]

EXAMPLES:
Add a CNAME
scw dns record add my-domain.tld data=www name=www2 type=CNAME

Add an IP
scw dns record add my-domain.tld data=1.2.3.4 name=vpn type=A

ARGS:
dns-zone DNS zone in which to add the record
data
[name]
[priority]
ttl=300
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)
[comment]
[geo-ip-config.matches.{index}.countries.{index}]
[geo-ip-config.matches.{index}.continents.{index}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ Delete a DNS record
USAGE:
scw dns record delete <dns-zone ...> [arg=value ...]

EXAMPLES:
Delete a CNAME
scw dns record delete my-domain.tld name=www type=CNAME

Delete a single IP from a record with more than one
scw dns record delete my-domain.tld data=1.2.3.4 name=vpn type=A

ARGS:
dns-zone DNS zone in which to delete the record
[data]
[name]
[ttl]
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)

FLAGS:
-h, --help help for delete
Expand Down
15 changes: 11 additions & 4 deletions cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This command will clear all the data for this record, replacing it with the given data.
This command will replace all the data for this record with the given values.

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

EXAMPLES:
Add or replace a CNAME
scw dns record set my-domain.tld values.0=www name=www2 type=CNAME

Add or replace a list of IP
scw dns record set my-domain.tld values.0=1.2.3.4 values.1=1.2.3.5 name=vpn type=A

ARGS:
dns-zone DNS zone in which to set the record
data.{index}
[name]
values.{index} A list of values for replacing the record data. (multiple values cannot be used for all type)
name
[priority]
ttl=300
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS)
type (A | AAAA | CNAME | TXT | SRV | TLSA | MX | NS | PTR | CAA | ALIAS | LOC | SSHFP | HINFO | RP | URI | DS | NAPTR)
[comment]
[geo-ip-config.matches.{index}.countries.{index}]
[geo-ip-config.matches.{index}.continents.{index}]
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-dns-record-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AVAILABLE COMMANDS:
delete Delete a DNS record
list List DNS zone records
list-nameservers List DNS zone nameservers
set Clear and set a DNS record
set Update a DNS record
update-nameservers Update DNS zone nameservers

FLAGS:
Expand Down
61 changes: 53 additions & 8 deletions docs/commands/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Manage your DNS zones and records.
- [Delete a DNS record](#delete-a-dns-record)
- [List DNS zone records](#list-dns-zone-records)
- [List DNS zone nameservers](#list-dns-zone-nameservers)
- [Clear and set a DNS record](#clear-and-set-a-dns-record)
- [Update a DNS record](#update-a-dns-record)
- [Update DNS zone nameservers](#update-dns-zone-nameservers)
- [Transaction SIGnature key management](#transaction-signature-key-management)
- [Delete the DNS zone TSIG Key](#delete-the-dns-zone-tsig-key)
Expand Down Expand Up @@ -143,7 +143,7 @@ scw dns record add <dns-zone ...> [arg=value ...]
| name | | |
| priority | | |
| ttl | Required<br />Default: `300` | |
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | |
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS`, `LOC`, `SSHFP`, `HINFO`, `RP`, `URI`, `DS`, `NAPTR` | |
| comment | | |
| geo-ip-config.matches.{index}.countries.{index} | | |
| geo-ip-config.matches.{index}.continents.{index} | | |
Expand All @@ -160,6 +160,21 @@ scw dns record add <dns-zone ...> [arg=value ...]
| view-config.views.{index}.data | | |


**Examples:**


Add a CNAME
```
scw dns record add my-domain.tld data=www name=www2 type=CNAME
```

Add an IP
```
scw dns record add my-domain.tld data=1.2.3.4 name=vpn type=A
```




### Update DNS zone records

Expand Down Expand Up @@ -289,7 +304,22 @@ scw dns record delete <dns-zone ...> [arg=value ...]
| data | | |
| name | | |
| ttl | | |
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | |
| type | Required<br />One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS`, `LOC`, `SSHFP`, `HINFO`, `RP`, `URI`, `DS`, `NAPTR` | |


**Examples:**


Delete a CNAME
```
scw dns record delete my-domain.tld name=www type=CNAME
```

Delete a single IP from a record with more than one
```
scw dns record delete my-domain.tld data=1.2.3.4 name=vpn type=A
```




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



### Clear and set a DNS record
### Update a DNS record

This command will clear all the data for this record, replacing it with the given data.
This command will replace all the data for this record with the given values.

**Usage:**

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


**Examples:**


Add or replace a CNAME
```
scw dns record set my-domain.tld values.0=www name=www2 type=CNAME
```

Add or replace a list of IP
```
scw dns record set my-domain.tld values.0=1.2.3.4 values.1=1.2.3.5 name=vpn type=A
```




### Update DNS zone nameservers

Expand Down
4 changes: 4 additions & 0 deletions internal/namespaces/domain/v2beta1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
domain "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
)

var (
domainTypes = []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS", "LOC", "SSHFP", "HINFO", "RP", "URI", "DS", "NAPTR"}
)

// GetCommands returns dns commands.
//
// This function:
Expand Down
12 changes: 11 additions & 1 deletion internal/namespaces/domain/v2beta1/custom_record_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dnsRecordAddCommand() *core.Command {
Required: true,
Deprecated: false,
Positional: false,
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
EnumValues: domainTypes,
},
{
Name: "comment",
Expand Down Expand Up @@ -147,6 +147,16 @@ func dnsRecordAddCommand() *core.Command {
},
},
Run: dnsRecordAddRun,
Examples: []*core.Example{
{
Short: "Add a CNAME",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www2", "type": "CNAME", "data": "www"}`,
},
{
Short: "Add an IP",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "data": "1.2.3.4"}`,
},
},
}
}

Expand Down
12 changes: 11 additions & 1 deletion internal/namespaces/domain/v2beta1/custom_record_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ func dnsRecordDeleteCommand() *core.Command {
Required: true,
Deprecated: false,
Positional: false,
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
EnumValues: domainTypes,
},
},
Run: dnsRecordDeleteRun,
Examples: []*core.Example{
{
Short: "Delete a CNAME",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www", "type": "CNAME"}`,
},
{
Short: "Delete a single IP from a record with more than one",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "data": "1.2.3.4"}`,
},
},
}
}

Expand Down
29 changes: 22 additions & 7 deletions internal/namespaces/domain/v2beta1/custom_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (

type dnsRecordSetRequest struct {
DNSZone string
Data []string
Values []string
*domain.Record
}

func dnsRecordSetCommand() *core.Command {
return &core.Command{
Short: `Clear and set a DNS record`,
Long: `This command will clear all the data for this record, replacing it with the given data.`,
Short: `Update a DNS record`,
Long: `This command will replace all the data for this record with the given values.`,
Namespace: "dns",
Verb: "set",
Resource: "record",
Expand All @@ -31,14 +31,15 @@ func dnsRecordSetCommand() *core.Command {
Positional: true,
},
{
Name: "data.{index}",
Name: "values.{index}",
Short: "A list of values for replacing the record data. (multiple values cannot be used for all type)",
Required: true,
Deprecated: false,
Positional: false,
},
{
Name: "name",
Required: false,
Required: true,
Deprecated: false,
Positional: false,
},
Expand All @@ -60,7 +61,7 @@ func dnsRecordSetCommand() *core.Command {
Required: true,
Deprecated: false,
Positional: false,
EnumValues: []string{"A", "AAAA", "CNAME", "TXT", "SRV", "TLSA", "MX", "NS", "PTR", "CAA", "ALIAS"},
EnumValues: domainTypes,
},
{
Name: "comment",
Expand Down Expand Up @@ -149,6 +150,16 @@ func dnsRecordSetCommand() *core.Command {
},
},
Run: dnsRecordSetRun,
Examples: []*core.Example{
{
Short: "Add or replace a CNAME",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "www2", "type": "CNAME", "values": ["www"]}`,
},
{
Short: "Add or replace a list of IP",
ArgsJSON: `{"dns_zone": "my-domain.tld", "name": "vpn", "type": "A", "values": ["1.2.3.4", "1.2.3.5"]}`,
},
},
}
}

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

for _, data := range request.Data {
if len(request.Values) == 0 {
return nil, fmt.Errorf("at least one values (eg: values.0) is required")
}

for _, data := range request.Values {
record := *request.Record
record.Data = data
dnsRecordSetReq.Changes[0].Set.Records = append(dnsRecordSetReq.Changes[0].Set.Records, &record)
Expand Down