Skip to content

Commit ccc1068

Browse files
committed
Add dns task list command to retrieve task IDs for domain operations
1 parent 439f6bb commit ccc1068

5 files changed

Lines changed: 244 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Retrieve a list of tasks for domain operations (creation, transfer, renewal, etc.).
4+
This is useful for tracking operations and retrieving task IDs needed for Terraform imports.
5+
6+
USAGE:
7+
scw dns task list [arg=value ...]
8+
9+
EXAMPLES:
10+
List all tasks
11+
scw dns task list
12+
13+
List tasks for a specific domain
14+
scw dns task list domain=example.com
15+
16+
List tasks with create_domain type
17+
scw dns task list types.0=create_domain
18+
19+
ARGS:
20+
[project-id] Project ID to use. If none is passed the default project ID will be used
21+
[organization-id] Organization ID to filter on
22+
[domain] Domain name to filter on
23+
[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)
24+
[statuses.{index}] Task statuses to filter on (unavailable | new | waiting_payment | pending | success | error)
25+
[order-by=domain_desc] Sort order of the returned tasks (domain_desc | domain_asc)
26+
27+
FLAGS:
28+
-h, --help help for list
29+
--list-sub-commands List all subcommands
30+
31+
GLOBAL FLAGS:
32+
-c, --config string The path to the config file
33+
-D, --debug Enable debug mode
34+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
35+
-p, --profile string The config profile to use
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
DNS tasks management.
4+
5+
USAGE:
6+
scw dns task <command>
7+
8+
AVAILABLE COMMANDS:
9+
list List DNS tasks
10+
11+
FLAGS:
12+
-h, --help help for task
13+
--list-sub-commands List all subcommands
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use
20+
21+
Use "scw dns task [command] --help" for more information about a command.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ USAGE:
88
AVAILABLE COMMANDS:
99
certificate TLS certificate management
1010
record DNS records management
11+
task DNS tasks management
1112
tsig-key Transaction SIGnature key management
1213
version DNS zones version management
1314
zone DNS Zones management

internal/namespaces/domain/v2beta1/custom.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func GetCommands() *core.Commands {
4444
dnsRecordAddCommand(),
4545
dnsRecordSetCommand(),
4646
dnsRecordDeleteCommand(),
47+
dnsTask(),
48+
dnsTaskListCommand(),
4749
))
4850

4951
cmds.MustFind("dns", "zone", "import").ArgSpecs.GetByName("bind-source.content").CanLoadFile = true
@@ -56,6 +58,10 @@ func GetCommands() *core.Commands {
5658
domain.SSLCertificateStatus(""),
5759
human.EnumMarshalFunc(certificateStatusMarshalSpecs),
5860
)
61+
human.RegisterMarshalerFunc(
62+
domain.TaskStatus(""),
63+
human.EnumMarshalFunc(taskStatusMarshalSpecs),
64+
)
5965

6066
return cmds
6167
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package domain
2+
3+
import (
4+
"context"
5+
"reflect"
6+
7+
"github.com/fatih/color"
8+
"github.com/scaleway/scaleway-cli/v2/core"
9+
"github.com/scaleway/scaleway-cli/v2/core/human"
10+
domain "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
12+
)
13+
14+
//
15+
// Marshalers
16+
//
17+
18+
var (
19+
taskStatusMarshalSpecs = human.EnumMarshalSpecs{
20+
domain.TaskStatusSuccess: &human.EnumMarshalSpec{Attribute: color.FgGreen},
21+
domain.TaskStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed},
22+
domain.TaskStatusPending: &human.EnumMarshalSpec{Attribute: color.FgBlue},
23+
domain.TaskStatusNew: &human.EnumMarshalSpec{Attribute: color.FgCyan},
24+
domain.TaskStatusWaitingPayment: &human.EnumMarshalSpec{Attribute: color.FgYellow},
25+
}
26+
)
27+
28+
//
29+
// Commands
30+
//
31+
32+
func dnsTask() *core.Command {
33+
return &core.Command{
34+
Short: `DNS tasks management`,
35+
Long: `DNS tasks management.`,
36+
Namespace: "dns",
37+
Resource: "task",
38+
}
39+
}
40+
41+
func dnsTaskListCommand() *core.Command {
42+
return &core.Command{
43+
Short: `List DNS tasks`,
44+
Long: `Retrieve a list of tasks for domain operations (creation, transfer, renewal, etc.).
45+
This is useful for tracking operations and retrieving task IDs needed for Terraform imports.`,
46+
Namespace: "dns",
47+
Resource: "task",
48+
Verb: "list",
49+
ArgsType: reflect.TypeOf(domain.RegistrarAPIListTasksRequest{}),
50+
ArgSpecs: core.ArgSpecs{
51+
core.ProjectIDArgSpec(),
52+
{
53+
Name: "organization-id",
54+
Short: `Organization ID to filter on`,
55+
Required: false,
56+
Deprecated: false,
57+
Positional: false,
58+
},
59+
{
60+
Name: "domain",
61+
Short: `Domain name to filter on`,
62+
Required: false,
63+
Deprecated: false,
64+
Positional: false,
65+
},
66+
{
67+
Name: "types.{index}",
68+
Short: `Task types to filter on`,
69+
Required: false,
70+
Deprecated: false,
71+
Positional: false,
72+
EnumValues: []string{
73+
"unknown",
74+
"create_domain",
75+
"create_external_domain",
76+
"renew_domain",
77+
"transfer_domain",
78+
"trade_domain",
79+
"lock_domain_transfer",
80+
"unlock_domain_transfer",
81+
"enable_dnssec",
82+
"disable_dnssec",
83+
"update_domain",
84+
"update_contact",
85+
"delete_domain",
86+
"cancel_task",
87+
"generate_ssl_certificate",
88+
"renew_ssl_certificate",
89+
"send_message",
90+
"delete_domain_expired",
91+
"delete_external_domain",
92+
"create_host",
93+
"update_host",
94+
"delete_host",
95+
"move_project",
96+
"transfer_online_domain",
97+
},
98+
},
99+
{
100+
Name: "statuses.{index}",
101+
Short: `Task statuses to filter on`,
102+
Required: false,
103+
Deprecated: false,
104+
Positional: false,
105+
EnumValues: []string{
106+
"unavailable",
107+
"new",
108+
"waiting_payment",
109+
"pending",
110+
"success",
111+
"error",
112+
},
113+
},
114+
{
115+
Name: "order-by",
116+
Short: `Sort order of the returned tasks`,
117+
Required: false,
118+
Deprecated: false,
119+
Positional: false,
120+
Default: core.DefaultValueSetter("domain_desc"),
121+
EnumValues: []string{
122+
"domain_desc",
123+
"domain_asc",
124+
},
125+
},
126+
},
127+
Run: func(ctx context.Context, args any) (i any, e error) {
128+
request := args.(*domain.RegistrarAPIListTasksRequest)
129+
130+
client := core.ExtractClient(ctx)
131+
api := domain.NewRegistrarAPI(client)
132+
opts := []scw.RequestOption{scw.WithAllPages()}
133+
resp, err := api.ListTasks(request, opts...)
134+
if err != nil {
135+
return nil, err
136+
}
137+
138+
return resp.Tasks, nil
139+
},
140+
View: &core.View{Fields: []*core.ViewField{
141+
{
142+
FieldName: "ID",
143+
},
144+
{
145+
FieldName: "Domain",
146+
},
147+
{
148+
FieldName: "Type",
149+
},
150+
{
151+
FieldName: "Status",
152+
},
153+
{
154+
FieldName: "StartedAt",
155+
},
156+
{
157+
FieldName: "UpdatedAt",
158+
},
159+
{
160+
FieldName: "Message",
161+
},
162+
{
163+
FieldName: "ProjectID",
164+
},
165+
}},
166+
Examples: []*core.Example{
167+
{
168+
Short: "List all tasks",
169+
ArgsJSON: `{}`,
170+
},
171+
{
172+
Short: "List tasks for a specific domain",
173+
ArgsJSON: `{"domain": "example.com"}`,
174+
},
175+
{
176+
Short: "List tasks with create_domain type",
177+
ArgsJSON: `{"types": ["create_domain"]}`,
178+
},
179+
},
180+
}
181+
}

0 commit comments

Comments
 (0)