diff --git a/cmd/scw/testdata/test-all-usage-dns-task-list-usage.golden b/cmd/scw/testdata/test-all-usage-dns-task-list-usage.golden new file mode 100644 index 0000000000..022f5abd75 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-dns-task-list-usage.golden @@ -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 diff --git a/cmd/scw/testdata/test-all-usage-dns-task-usage.golden b/cmd/scw/testdata/test-all-usage-dns-task-usage.golden new file mode 100644 index 0000000000..a35474a4bf --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-dns-task-usage.golden @@ -0,0 +1,21 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +DNS tasks management. + +USAGE: + scw dns task + +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. diff --git a/cmd/scw/testdata/test-all-usage-dns-usage.golden b/cmd/scw/testdata/test-all-usage-dns-usage.golden index 963d0f064c..50d9a26104 100644 --- a/cmd/scw/testdata/test-all-usage-dns-usage.golden +++ b/cmd/scw/testdata/test-all-usage-dns-usage.golden @@ -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 diff --git a/docs/commands/dns.md b/docs/commands/dns.md index 83b93fcc9c..30cd85f7d7 100644 --- a/docs/commands/dns.md +++ b/docs/commands/dns.md @@ -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) @@ -435,6 +437,56 @@ scw dns record update-nameservers [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`
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. diff --git a/internal/namespaces/domain/v2beta1/custom.go b/internal/namespaces/domain/v2beta1/custom.go index a757a839e0..3bb0ab9260 100644 --- a/internal/namespaces/domain/v2beta1/custom.go +++ b/internal/namespaces/domain/v2beta1/custom.go @@ -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 @@ -56,6 +58,10 @@ func GetCommands() *core.Commands { domain.SSLCertificateStatus(""), human.EnumMarshalFunc(certificateStatusMarshalSpecs), ) + human.RegisterMarshalerFunc( + domain.TaskStatus(""), + human.EnumMarshalFunc(taskStatusMarshalSpecs), + ) return cmds } diff --git a/internal/namespaces/domain/v2beta1/custom_task.go b/internal/namespaces/domain/v2beta1/custom_task.go new file mode 100644 index 0000000000..3e32653700 --- /dev/null +++ b/internal/namespaces/domain/v2beta1/custom_task.go @@ -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"]}`, + }, + }, + } +}