Skip to content

Commit 01b3089

Browse files
committed
feat(dns): Onboard move-zone commands
STACKITCLI-41
1 parent ad53d5b commit 01b3089

16 files changed

Lines changed: 1772 additions & 0 deletions

‎docs/stackit_dns_zone.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ stackit dns zone [flags]
3333
* [stackit dns zone clone](./stackit_dns_zone_clone.md) - Clones a DNS zone
3434
* [stackit dns zone create](./stackit_dns_zone_create.md) - Creates a DNS zone
3535
* [stackit dns zone delete](./stackit_dns_zone_delete.md) - Deletes a DNS zone
36+
* [stackit dns zone delete-move-code](./stackit_dns_zone_delete-move-code.md) - Deletes the move code of a DNS zone
3637
* [stackit dns zone describe](./stackit_dns_zone_describe.md) - Shows details of a DNS zone
38+
* [stackit dns zone generate-move-code](./stackit_dns_zone_generate-move-code.md) - Generates a move code for a DNS zone
3739
* [stackit dns zone list](./stackit_dns_zone_list.md) - Lists DNS zones
40+
* [stackit dns zone move](./stackit_dns_zone_move.md) - Moves a DNS zone to another project
3841
* [stackit dns zone update](./stackit_dns_zone_update.md) - Updates a DNS zone
42+
* [stackit dns zone validate-move-code](./stackit_dns_zone_validate-move-code.md) - Validates the move code of a DNS zone
3943

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit dns zone delete-move-code
2+
3+
Deletes the move code of a DNS zone
4+
5+
### Synopsis
6+
7+
Deletes (invalidates) the move code of a DNS zone, so it can no longer be used to move the zone to another project.
8+
9+
```
10+
stackit dns zone delete-move-code ZONE_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Delete the move code of a DNS zone with ID "xxx"
17+
$ stackit dns zone delete-move-code xxx
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit dns zone delete-move-code"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit dns zone](./stackit_dns_zone.md) - Provides functionality for DNS zones
40+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## stackit dns zone generate-move-code
2+
3+
Generates a move code for a DNS zone
4+
5+
### Synopsis
6+
7+
Generates a move code for a DNS zone, which is required to move the zone to another project.
8+
The code is only shown once upon creation, so make sure to save it. By default, the code is valid for 30 days.
9+
10+
```
11+
stackit dns zone generate-move-code ZONE_ID [flags]
12+
```
13+
14+
### Examples
15+
16+
```
17+
Generate a move code for a DNS zone with ID "xxx"
18+
$ stackit dns zone generate-move-code xxx
19+
20+
Generate a move code for a DNS zone with ID "xxx" that is valid for one hour
21+
$ stackit dns zone generate-move-code xxx --ttl 3600
22+
```
23+
24+
### Options
25+
26+
```
27+
-h, --help Help for "stackit dns zone generate-move-code"
28+
--ttl int32 Validity duration of the move code in seconds (min 1, max 2592000 / 30 days). If not set, the API default is used
29+
```
30+
31+
### Options inherited from parent commands
32+
33+
```
34+
-y, --assume-yes If set, skips all confirmation prompts
35+
--async If set, runs the command asynchronously
36+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
37+
-p, --project-id string Project ID
38+
--region string Target region for region-specific requests
39+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
40+
```
41+
42+
### SEE ALSO
43+
44+
* [stackit dns zone](./stackit_dns_zone.md) - Provides functionality for DNS zones
45+

‎docs/stackit_dns_zone_move.md‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## stackit dns zone move
2+
3+
Moves a DNS zone to another project
4+
5+
### Synopsis
6+
7+
Moves a DNS zone to another project.
8+
The API call this command makes is always performed against the destination project (--target-project-id). Moving requires an authorizing move code for the zone, which can be obtained in one of two ways:
9+
- Generated automatically by this command: omit --code. The configured project is then used to look up the zone and must be its current project.
10+
- Generated beforehand, by yourself or by whoever controls the zone's current project, via "stackit dns zone generate-move-code" (and optionally checked with "stackit dns zone validate-move-code"), then passed explicitly via --code.
11+
The configured project isn't used for the move itself in this case.
12+
13+
```
14+
stackit dns zone move [flags]
15+
```
16+
17+
### Examples
18+
19+
```
20+
Move a DNS zone with domain name "www.my-zone.com" to project "xxx", automatically generating a move code against the zone's current project
21+
$ stackit dns zone move --zone-domain-name www.my-zone.com --target-project-id xxx
22+
23+
Move a DNS zone with domain name "www.my-zone.com" from project "yyy" to project "xxx", automatically generating a move code. --project-id explicitly sets the source project, i.e. the zone's current project
24+
$ stackit dns zone move --project-id yyy --zone-domain-name www.my-zone.com --target-project-id xxx
25+
26+
Move a DNS zone with domain name "www.my-zone.com" to project "xxx" using a move code generated beforehand (e.g. via "stackit dns zone generate-move-code")
27+
$ stackit dns zone move --zone-domain-name www.my-zone.com --target-project-id xxx --code @./move-code.txt
28+
```
29+
30+
### Options
31+
32+
```
33+
--code secret Code. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported. If not set, a move code is generated automatically for the zone in the configured project, which must then be the zone's current project.
34+
-h, --help Help for "stackit dns zone move"
35+
--target-project-id string ID of the project the zone should be moved to
36+
--zone-domain-name string Domain name of the zone to move
37+
```
38+
39+
### Options inherited from parent commands
40+
41+
```
42+
-y, --assume-yes If set, skips all confirmation prompts
43+
--async If set, runs the command asynchronously
44+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
45+
-p, --project-id string Project ID
46+
--region string Target region for region-specific requests
47+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
48+
```
49+
50+
### SEE ALSO
51+
52+
* [stackit dns zone](./stackit_dns_zone.md) - Provides functionality for DNS zones
53+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit dns zone validate-move-code
2+
3+
Validates the move code of a DNS zone
4+
5+
### Synopsis
6+
7+
Validates the move code of a DNS zone. Checks that the provided code is valid, not expired, and belongs to the given zone.
8+
9+
```
10+
stackit dns zone validate-move-code ZONE_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Validate the move code stored in "move-code.txt" of a DNS zone with ID "xxx"
17+
$ stackit dns zone validate-move-code xxx --code @./move-code.txt
18+
19+
Validate a move code read from stdin for a DNS zone with ID "xxx"
20+
$ echo yyy | stackit dns zone validate-move-code xxx --code -
21+
```
22+
23+
### Options
24+
25+
```
26+
--code secret Code. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
27+
-h, --help Help for "stackit dns zone validate-move-code"
28+
```
29+
30+
### Options inherited from parent commands
31+
32+
```
33+
-y, --assume-yes If set, skips all confirmation prompts
34+
--async If set, runs the command asynchronously
35+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
36+
-p, --project-id string Project ID
37+
--region string Target region for region-specific requests
38+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
39+
```
40+
41+
### SEE ALSO
42+
43+
* [stackit dns zone](./stackit_dns_zone.md) - Provides functionality for DNS zones
44+
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package deletemovecode
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
15+
dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
17+
18+
"github.com/spf13/cobra"
19+
dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
20+
)
21+
22+
const (
23+
zoneIdArg = "ZONE_ID"
24+
)
25+
26+
type inputModel struct {
27+
*globalflags.GlobalFlagModel
28+
ZoneId string
29+
}
30+
31+
func NewCmd(params *types.CmdParams) *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: fmt.Sprintf("delete-move-code %s", zoneIdArg),
34+
Short: "Deletes the move code of a DNS zone",
35+
Long: "Deletes (invalidates) the move code of a DNS zone, so it can no longer be used to move the zone to another project.",
36+
Args: args.SingleArg(zoneIdArg, utils.ValidateUUID),
37+
Example: examples.Build(
38+
examples.NewExample(
39+
`Delete the move code of a DNS zone with ID "xxx"`,
40+
"$ stackit dns zone delete-move-code xxx"),
41+
),
42+
RunE: func(cmd *cobra.Command, args []string) error {
43+
ctx := context.Background()
44+
model, err := parseInput(params.Printer, cmd, args)
45+
if err != nil {
46+
return err
47+
}
48+
49+
// Configure API client
50+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
51+
if err != nil {
52+
return err
53+
}
54+
55+
zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId)
56+
if err != nil {
57+
params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err)
58+
zoneLabel = model.ZoneId
59+
}
60+
prompt := fmt.Sprintf("Are you sure you want to delete the move code of zone %q? (This cannot be undone)", zoneLabel)
61+
err = params.Printer.PromptForConfirmation(prompt)
62+
if err != nil {
63+
return err
64+
}
65+
66+
// Call API
67+
req := buildRequest(ctx, model, apiClient)
68+
resp, err := req.Execute()
69+
if err != nil {
70+
return fmt.Errorf("delete DNS zone move code: %w", err)
71+
}
72+
73+
return outputResult(params.Printer, model, zoneLabel, resp)
74+
},
75+
}
76+
return cmd
77+
}
78+
79+
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
80+
zoneId := inputArgs[0]
81+
globalFlags := globalflags.Parse(p, cmd)
82+
if globalFlags.ProjectId == "" {
83+
return nil, &errors.ProjectIdError{}
84+
}
85+
86+
model := inputModel{
87+
GlobalFlagModel: globalFlags,
88+
ZoneId: zoneId,
89+
}
90+
91+
p.DebugInputModel(model)
92+
return &model, nil
93+
}
94+
95+
func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiDeleteMoveCodeRequest {
96+
req := apiClient.DefaultAPI.DeleteMoveCode(ctx, model.ProjectId, model.ZoneId)
97+
return req
98+
}
99+
100+
func outputResult(p *print.Printer, model *inputModel, zoneLabel string, resp *dns.Message) error {
101+
if resp == nil {
102+
return fmt.Errorf("move code deletion response is empty")
103+
}
104+
105+
return p.OutputResult(model.OutputFormat, resp, func() error {
106+
p.Outputf("Deleted move code of zone %s\n", zoneLabel)
107+
return nil
108+
})
109+
}

0 commit comments

Comments
 (0)