Skip to content
Closed
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
35 changes: 35 additions & 0 deletions cmd/scw/testdata/test-all-usage-dns-task-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve a list of tasks for domain operations (creation, transfer, renewal, etc.).
This is useful for tracking operations and retrieving task IDs needed for Terraform imports.

USAGE:
scw dns task list [arg=value ...]

EXAMPLES:
List all tasks
scw dns task list

List tasks for a specific domain
scw dns task list domain=example.com

List tasks with create_domain type
scw dns task list types.0=create_domain

ARGS:
[project-id] Project ID to use. If none is passed the default project ID will be used
[organization-id] Organization ID to filter on
[domain] Domain name to filter on
[types.{index}] Task types to filter on (unknown | create_domain | create_external_domain | renew_domain | transfer_domain | trade_domain | lock_domain_transfer | unlock_domain_transfer | enable_dnssec | disable_dnssec | update_domain | update_contact | delete_domain | cancel_task | generate_ssl_certificate | renew_ssl_certificate | send_message | delete_domain_expired | delete_external_domain | create_host | update_host | delete_host | move_project | transfer_online_domain)
[statuses.{index}] Task statuses to filter on (unavailable | new | waiting_payment | pending | success | error)
[order-by=domain_desc] Sort order of the returned tasks (domain_desc | domain_asc)

FLAGS:
-h, --help help for list
--list-sub-commands List all subcommands

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
21 changes: 21 additions & 0 deletions cmd/scw/testdata/test-all-usage-dns-task-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
DNS tasks management.

USAGE:
scw dns task <command>

AVAILABLE COMMANDS:
list List DNS tasks

FLAGS:
-h, --help help for task
--list-sub-commands List all subcommands

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw dns task [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-dns-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ USAGE:
AVAILABLE COMMANDS:
certificate TLS certificate management
record DNS records management
task DNS tasks management
tsig-key Transaction SIGnature key management
version DNS zones version management
zone DNS Zones management
Expand Down
52 changes: 52 additions & 0 deletions docs/commands/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This API allows you to manage your domains, DNS zones and records.
- [List name servers within a DNS zone](#list-name-servers-within-a-dns-zone)
- [Update a DNS record](#update-a-dns-record)
- [Update name servers within a DNS zone](#update-name-servers-within-a-dns-zone)
- [DNS tasks management](#dns-tasks-management)
- [List DNS tasks](#list-dns-tasks)
- [Transaction SIGnature key management](#transaction-signature-key-management)
- [Delete the DNS zone's TSIG key](#delete-the-dns-zone's-tsig-key)
- [Get the DNS zone's TSIG key](#get-the-dns-zone's-tsig-key)
Expand Down Expand Up @@ -435,6 +437,56 @@ scw dns record update-nameservers <dns-zone ...> [arg=value ...]



## DNS tasks management

DNS tasks management.


### List DNS tasks

Retrieve a list of tasks for domain operations (creation, transfer, renewal, etc.).
This is useful for tracking operations and retrieving task IDs needed for Terraform imports.

**Usage:**

```
scw dns task list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| organization-id | | Organization ID to filter on |
| domain | | Domain name to filter on |
| types.{index} | One of: `unknown`, `create_domain`, `create_external_domain`, `renew_domain`, `transfer_domain`, `trade_domain`, `lock_domain_transfer`, `unlock_domain_transfer`, `enable_dnssec`, `disable_dnssec`, `update_domain`, `update_contact`, `delete_domain`, `cancel_task`, `generate_ssl_certificate`, `renew_ssl_certificate`, `send_message`, `delete_domain_expired`, `delete_external_domain`, `create_host`, `update_host`, `delete_host`, `move_project`, `transfer_online_domain` | Task types to filter on |
| statuses.{index} | One of: `unavailable`, `new`, `waiting_payment`, `pending`, `success`, `error` | Task statuses to filter on |
| order-by | Default: `domain_desc`<br />One of: `domain_desc`, `domain_asc` | Sort order of the returned tasks |


**Examples:**


List all tasks
```
scw dns task list
```

List tasks for a specific domain
```
scw dns task list domain=example.com
```

List tasks with create_domain type
```
scw dns task list types.0=create_domain
```




## Transaction SIGnature key management

Transaction SIGnature key management.
Expand Down
6 changes: 6 additions & 0 deletions internal/namespaces/domain/v2beta1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func GetCommands() *core.Commands {
dnsRecordAddCommand(),
dnsRecordSetCommand(),
dnsRecordDeleteCommand(),
dnsTask(),
dnsTaskListCommand(),
))

cmds.MustFind("dns", "zone", "import").ArgSpecs.GetByName("bind-source.content").CanLoadFile = true
Expand All @@ -56,6 +58,10 @@ func GetCommands() *core.Commands {
domain.SSLCertificateStatus(""),
human.EnumMarshalFunc(certificateStatusMarshalSpecs),
)
human.RegisterMarshalerFunc(
domain.TaskStatus(""),
human.EnumMarshalFunc(taskStatusMarshalSpecs),
)

return cmds
}
179 changes: 179 additions & 0 deletions internal/namespaces/domain/v2beta1/custom_task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package domain

import (
"context"
"reflect"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/core/human"
domain "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

//
// Marshalers
//

var taskStatusMarshalSpecs = human.EnumMarshalSpecs{
domain.TaskStatusSuccess: &human.EnumMarshalSpec{Attribute: color.FgGreen},
domain.TaskStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed},
domain.TaskStatusPending: &human.EnumMarshalSpec{Attribute: color.FgBlue},
domain.TaskStatusNew: &human.EnumMarshalSpec{Attribute: color.FgCyan},
domain.TaskStatusWaitingPayment: &human.EnumMarshalSpec{Attribute: color.FgYellow},
}

//
// Commands
//

func dnsTask() *core.Command {
return &core.Command{
Short: `DNS tasks management`,
Long: `DNS tasks management.`,
Namespace: "dns",
Resource: "task",
}
}

func dnsTaskListCommand() *core.Command {
return &core.Command{
Short: `List DNS tasks`,
Long: `Retrieve a list of tasks for domain operations (creation, transfer, renewal, etc.).
This is useful for tracking operations and retrieving task IDs needed for Terraform imports.`,
Namespace: "dns",
Resource: "task",
Verb: "list",
ArgsType: reflect.TypeOf(domain.RegistrarAPIListTasksRequest{}),
ArgSpecs: core.ArgSpecs{
core.ProjectIDArgSpec(),
{
Name: "organization-id",
Short: `Organization ID to filter on`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "domain",
Short: `Domain name to filter on`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "types.{index}",
Short: `Task types to filter on`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{
"unknown",
"create_domain",
"create_external_domain",
"renew_domain",
"transfer_domain",
"trade_domain",
"lock_domain_transfer",
"unlock_domain_transfer",
"enable_dnssec",
"disable_dnssec",
"update_domain",
"update_contact",
"delete_domain",
"cancel_task",
"generate_ssl_certificate",
"renew_ssl_certificate",
"send_message",
"delete_domain_expired",
"delete_external_domain",
"create_host",
"update_host",
"delete_host",
"move_project",
"transfer_online_domain",
},
},
{
Name: "statuses.{index}",
Short: `Task statuses to filter on`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{
"unavailable",
"new",
"waiting_payment",
"pending",
"success",
"error",
},
},
{
Name: "order-by",
Short: `Sort order of the returned tasks`,
Required: false,
Deprecated: false,
Positional: false,
Default: core.DefaultValueSetter("domain_desc"),
EnumValues: []string{
"domain_desc",
"domain_asc",
},
},
},
Run: func(ctx context.Context, args any) (i any, e error) {
request := args.(*domain.RegistrarAPIListTasksRequest)

client := core.ExtractClient(ctx)
api := domain.NewRegistrarAPI(client)
opts := []scw.RequestOption{scw.WithAllPages()}
resp, err := api.ListTasks(request, opts...)
if err != nil {
return nil, err
}

return resp.Tasks, nil
},
View: &core.View{Fields: []*core.ViewField{
{
FieldName: "ID",
},
{
FieldName: "Domain",
},
{
FieldName: "Type",
},
{
FieldName: "Status",
},
{
FieldName: "StartedAt",
},
{
FieldName: "UpdatedAt",
},
{
FieldName: "Message",
},
{
FieldName: "ProjectID",
},
}},
Examples: []*core.Example{
{
Short: "List all tasks",
ArgsJSON: `{}`,
},
{
Short: "List tasks for a specific domain",
ArgsJSON: `{"domain": "example.com"}`,
},
{
Short: "List tasks with create_domain type",
ArgsJSON: `{"types": ["create_domain"]}`,
},
},
}
}
Loading