diff --git a/README.md b/README.md index e4c8894327..1c23c87b1a 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/cmd/scw/testdata/test-all-usage-dns-record-add-usage.golden b/cmd/scw/testdata/test-all-usage-dns-record-add-usage.golden index d9b6ca5dbb..f5c3e867d8 100644 --- a/cmd/scw/testdata/test-all-usage-dns-record-add-usage.golden +++ b/cmd/scw/testdata/test-all-usage-dns-record-add-usage.golden @@ -5,13 +5,20 @@ Add a new DNS record USAGE: scw dns record add [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}] diff --git a/cmd/scw/testdata/test-all-usage-dns-record-delete-usage.golden b/cmd/scw/testdata/test-all-usage-dns-record-delete-usage.golden index 4349fab990..5e620ec714 100644 --- a/cmd/scw/testdata/test-all-usage-dns-record-delete-usage.golden +++ b/cmd/scw/testdata/test-all-usage-dns-record-delete-usage.golden @@ -5,12 +5,19 @@ Delete a DNS record USAGE: scw dns record delete [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 diff --git a/cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden b/cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden index 81efe561a1..792413e60b 100644 --- a/cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden +++ b/cmd/scw/testdata/test-all-usage-dns-record-set-usage.golden @@ -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 [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}] diff --git a/cmd/scw/testdata/test-all-usage-dns-record-usage.golden b/cmd/scw/testdata/test-all-usage-dns-record-usage.golden index d56e71f124..2ed4ae946b 100644 --- a/cmd/scw/testdata/test-all-usage-dns-record-usage.golden +++ b/cmd/scw/testdata/test-all-usage-dns-record-usage.golden @@ -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: diff --git a/docs/commands/dns.md b/docs/commands/dns.md index c3ce4f4319..5b1e1aa6b0 100644 --- a/docs/commands/dns.md +++ b/docs/commands/dns.md @@ -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) @@ -143,7 +143,7 @@ scw dns record add [arg=value ...] | name | | | | priority | | | | ttl | Required
Default: `300` | | -| type | Required
One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | | +| type | Required
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} | | | @@ -160,6 +160,21 @@ scw dns record add [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 @@ -289,7 +304,22 @@ scw dns record delete [arg=value ...] | data | | | | name | | | | ttl | | | -| type | Required
One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | | +| type | Required
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 +``` + @@ -338,9 +368,9 @@ scw dns record list-nameservers [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:** @@ -354,11 +384,11 @@ scw dns record set [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
Default: `300` | | -| type | Required
One of: `A`, `AAAA`, `CNAME`, `TXT`, `SRV`, `TLSA`, `MX`, `NS`, `PTR`, `CAA`, `ALIAS` | | +| type | Required
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} | | | @@ -375,6 +405,21 @@ scw dns record set [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 diff --git a/internal/namespaces/domain/v2beta1/custom.go b/internal/namespaces/domain/v2beta1/custom.go index 7a114834a2..b859b6b4fa 100644 --- a/internal/namespaces/domain/v2beta1/custom.go +++ b/internal/namespaces/domain/v2beta1/custom.go @@ -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: diff --git a/internal/namespaces/domain/v2beta1/custom_record_add.go b/internal/namespaces/domain/v2beta1/custom_record_add.go index ef7df47012..6758295050 100644 --- a/internal/namespaces/domain/v2beta1/custom_record_add.go +++ b/internal/namespaces/domain/v2beta1/custom_record_add.go @@ -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", @@ -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"}`, + }, + }, } } diff --git a/internal/namespaces/domain/v2beta1/custom_record_delete.go b/internal/namespaces/domain/v2beta1/custom_record_delete.go index 6d7afbc331..5543f60c32 100644 --- a/internal/namespaces/domain/v2beta1/custom_record_delete.go +++ b/internal/namespaces/domain/v2beta1/custom_record_delete.go @@ -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"}`, + }, + }, } } diff --git a/internal/namespaces/domain/v2beta1/custom_record_set.go b/internal/namespaces/domain/v2beta1/custom_record_set.go index 9959195290..f3a99ef112 100644 --- a/internal/namespaces/domain/v2beta1/custom_record_set.go +++ b/internal/namespaces/domain/v2beta1/custom_record_set.go @@ -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", @@ -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, }, @@ -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", @@ -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"]}`, + }, + }, } } @@ -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)