|
| 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