Skip to content

Commit faf7099

Browse files
authored
Improvements to curl and ske commands (#76)
* Improvements to curl * Add prompt for confirmation in SKE cluster update command * Review fix
1 parent 8d7da16 commit faf7099

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

docs/stackit_curl.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ stackit curl URL [flags]
1313
### Examples
1414

1515
```
16-
Make a GET request to http://locahost:8000
17-
$ stackit curl http://locahost:8000
16+
Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones
17+
$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones
1818
19-
Make a GET request to http://locahost:8000, write complete response (headers and body) to file "./output.txt"
20-
$ stackit curl http://locahost:8000 -include --output ./output.txt
19+
Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones, write complete response (headers and body) to file "./output.txt"
20+
$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -include --output ./output.txt
2121
22-
Make a POST request to http://locahost:8000 with payload from file "./payload.json"
23-
$ stackit curl http://locahost:8000 -X POST --data @./payload.json
22+
Create a new DNS zone for project with ID xxx via POST request to https://dns.api.stackit.cloud/v1/projects/xxx/zones with payload from file "./payload.json"
23+
$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -X POST --data @./payload.json
2424
25-
Make a POST request to http://locahost:8000 with header "Foo: Bar", fail if server returns error (such as 403 Forbidden)
26-
$ stackit curl http://locahost:8000 -X POST -H "Foo: Bar" --fail
25+
Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones, with header "Authorization: Bearer yyy", fail if server returns error (such as 403 Forbidden)
26+
$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -X POST -H "Authorization: Bearer yyy" --fail
2727
```
2828

2929
### Options

internal/cmd/curl/curl.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ func NewCmd() *cobra.Command {
5050
Long: "Executes an HTTP request to an endpoint, using the authentication provided by the CLI.",
5151
Example: examples.Build(
5252
examples.NewExample(
53-
"Make a GET request to http://locahost:8000",
54-
"$ stackit curl http://locahost:8000",
53+
"Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones",
54+
"$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones",
5555
),
5656
examples.NewExample(
57-
`Make a GET request to http://locahost:8000, write complete response (headers and body) to file "./output.txt"`,
58-
"$ stackit curl http://locahost:8000 -include --output ./output.txt",
57+
`Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones, write complete response (headers and body) to file "./output.txt"`,
58+
"$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -include --output ./output.txt",
5959
),
6060
examples.NewExample(
61-
`Make a POST request to http://locahost:8000 with payload from file "./payload.json"`,
62-
`$ stackit curl http://locahost:8000 -X POST --data @./payload.json`,
61+
`Create a new DNS zone for project with ID xxx via POST request to https://dns.api.stackit.cloud/v1/projects/xxx/zones with payload from file "./payload.json"`,
62+
`$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -X POST --data @./payload.json`,
6363
),
6464
examples.NewExample(
65-
`Make a POST request to http://locahost:8000 with header "Foo: Bar", fail if server returns error (such as 403 Forbidden)`,
66-
`$ stackit curl http://locahost:8000 -X POST -H "Foo: Bar" --fail`,
65+
`Get all the DNS zones for project with ID xxx via GET request to https://dns.api.stackit.cloud/v1/projects/xxx/zones, with header "Authorization: Bearer yyy", fail if server returns error (such as 403 Forbidden)`,
66+
`$ stackit curl https://dns.api.stackit.cloud/v1/projects/xxx/zones -X POST -H "Authorization: Bearer yyy" --fail`,
6767
),
6868
),
6969
Args: args.SingleArg(urlArg, validateURL),
@@ -122,7 +122,7 @@ func validateURL(value string) error {
122122
return fmt.Errorf("bad url")
123123
}
124124
if !strings.HasSuffix(urlHost, "stackit.cloud") {
125-
return fmt.Errorf("only urls belonging to STACKIT are permitted")
125+
return fmt.Errorf("only urls belonging to STACKIT are permitted, hostname must end in stackit.cloud")
126126
}
127127
return nil
128128
}

internal/cmd/ske/cluster/update/update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1112
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
@@ -67,6 +68,14 @@ func NewCmd() *cobra.Command {
6768
return err
6869
}
6970

71+
if !model.AssumeYes {
72+
prompt := fmt.Sprintf("Are you sure you want to update cluster %s?", model.ClusterName)
73+
err = confirm.PromptForConfirmation(cmd, prompt)
74+
if err != nil {
75+
return err
76+
}
77+
}
78+
7079
// Check if cluster exists
7180
exists, err := skeUtils.ClusterExists(ctx, apiClient, model.ProjectId, model.ClusterName)
7281
if err != nil {

0 commit comments

Comments
 (0)