Skip to content

Commit 925b578

Browse files
committed
chore(edge): fix review comments
relates to STACKITCLI-357
1 parent 6bff8a6 commit 925b578

7 files changed

Lines changed: 25 additions & 24 deletions

File tree

docs/stackit_beta_edge-cloud_token_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Creates a token for an Edge Cloud instance
66

77
Creates a token for a STACKIT Edge Cloud (STEC) instance.
88

9-
An expiration time can be set for the token. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is 3600(1h) seconds.
9+
An expiration time can be set for the token. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is 3600 seconds.
1010
Note: the format for the duration is <value><unit>, e.g. 30d for 30 days. You may not combine units.
1111

1212
```
@@ -26,7 +26,7 @@ stackit beta edge-cloud token create [flags]
2626
### Options
2727

2828
```
29-
-e, --expiration string Expiration time for the token, e.g. 5d. By default, the token is valid for 1h.
29+
-e, --expiration string Expiration time for the token, e.g. 5d. By default, the token is valid for 3600 seconds.
3030
-h, --help Help for "stackit beta edge-cloud token create"
3131
--instance-id string Edge Cloud instance ID
3232
```

internal/cmd/beta/edge/instance/create/create.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7474
}
7575

7676
// Call API
77-
req, err := buildRequest(ctx, model, apiClient)
78-
if err != nil {
79-
return err
80-
}
81-
resp, err := req.Execute()
77+
request := buildRequest(ctx, model, apiClient)
78+
79+
resp, err := request.Execute()
8280
if err != nil {
8381
return fmt.Errorf("create edge cloud instance: %w", err)
8482
}
@@ -131,16 +129,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
131129
return &model, nil
132130
}
133131

134-
func buildRequest(ctx context.Context, model *inputModel, apiClient *edge.APIClient) (req edge.ApiCreateInstanceRequest, err error) {
135-
req = apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId, model.Region)
132+
func buildRequest(ctx context.Context, model *inputModel, apiClient *edge.APIClient) edge.ApiCreateInstanceRequest {
133+
req := apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId, model.Region)
136134

137135
payload := edge.CreateInstancePayload{
138136
DisplayName: model.DisplayName,
139137
Description: model.Description,
140138
PlanId: model.PlanId,
141139
}
142140

143-
return req.CreateInstancePayload(payload), nil
141+
return req.CreateInstancePayload(payload)
144142
}
145143

146144
func outputResult(p *print.Printer, model *inputModel, projectLabel string, instance *edge.Instance) error {

internal/cmd/beta/edge/instance/create/create_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ func TestBuildRequest(t *testing.T) {
180180

181181
for _, tt := range tests {
182182
t.Run(tt.description, func(t *testing.T) {
183-
request, err := buildRequest(testCtx, tt.model, testClient)
184-
if err != nil {
185-
t.Fatalf("cannot create request: %v", err)
186-
}
183+
request := buildRequest(testCtx, tt.model, testClient)
187184

188185
diff := cmp.Diff(request, tt.expectedRequest,
189186
cmp.AllowUnexported(tt.expectedRequest, edge.DefaultAPIService{}),

internal/cmd/beta/edge/kubeconfig/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7676
`Create a kubeconfig for the Edge Cloud instance with instance ID "xxx". This will replace your current kubeconfig file.`,
7777
`$ stackit beta edge-cloud kubeconfig create --instance-id xxx --overwrite`),
7878
),
79-
RunE: func(cmd *cobra.Command, args []string) error {
79+
RunE: func(cmd *cobra.Command, _ []string) error {
8080
ctx := context.Background()
8181

82-
model, err := parseInput(params.Printer, cmd, args)
82+
model, err := parseInput(params.Printer, cmd)
8383
if err != nil {
8484
return err
8585
}
@@ -165,7 +165,7 @@ func configureFlags(cmd *cobra.Command) {
165165
}
166166

167167
// Parse user input (arguments and/or flags)
168-
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
168+
func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
169169
globalFlags := globalflags.Parse(p, cmd)
170170
if globalFlags.ProjectId == "" {
171171
return nil, &cliErr.ProjectIdError{}

internal/cmd/beta/edge/kubeconfig/create/create_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/google/go-cmp/cmp"
99
"github.com/google/go-cmp/cmp/cmpopts"
1010
"github.com/google/uuid"
11+
"github.com/spf13/cobra"
1112
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
1213

1314
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
@@ -224,7 +225,9 @@ func TestParseInput(t *testing.T) {
224225

225226
for _, tt := range tests {
226227
t.Run(tt.description, func(t *testing.T) {
227-
testutils.TestParseInput(t, NewCmd, parseInput, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
228+
testutils.TestParseInput(t, NewCmd, func(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
229+
return parseInput(p, cmd)
230+
}, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
228231
})
229232
}
230233
}

internal/cmd/beta/edge/token/create/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
4545
Short: "Creates a token for an Edge Cloud instance",
4646
Long: fmt.Sprintf("%s\n\n%s\n%s",
4747
"Creates a token for a STACKIT Edge Cloud (STEC) instance.",
48-
"An expiration time can be set for the token. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is 3600(1h) seconds.",
48+
fmt.Sprintf("An expiration time can be set for the token. The expiration time is set in seconds(s), minutes(m), hours(h), days(d) or months(M). Default is %d seconds.", expirationSecondsDefault),
4949
"Note: the format for the duration is <value><unit>, e.g. 30d for 30 days. You may not combine units."),
5050
Args: args.NoArgs,
5151
Example: examples.Build(
@@ -56,10 +56,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5656
`Create a token for the Edge Cloud instance with instance ID "xxx". The token will be valid for one day.`,
5757
`$ stackit beta edge-cloud token create --instance-id xxx --expiration 1d`),
5858
),
59-
RunE: func(cmd *cobra.Command, args []string) error {
59+
RunE: func(cmd *cobra.Command, _ []string) error {
6060
ctx := context.Background()
6161

62-
model, err := parseInput(params.Printer, cmd, args)
62+
model, err := parseInput(params.Printer, cmd)
6363
if err != nil {
6464
return err
6565
}
@@ -123,14 +123,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
123123

124124
func configureFlags(cmd *cobra.Command) {
125125
cmd.Flags().String(instanceIdFlag, "", "Edge Cloud instance ID")
126-
cmd.Flags().StringP(expirationFlag, "e", "", "Expiration time for the token, e.g. 5d. By default, the token is valid for 1h.")
126+
cmd.Flags().StringP(expirationFlag, "e", "", fmt.Sprintf("Expiration time for the token, e.g. 5d. By default, the token is valid for %d seconds.", expirationSecondsDefault))
127127

128128
err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
129129
cobra.CheckErr(err)
130130
}
131131

132132
// Parse user input (arguments and/or flags)
133-
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
133+
func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
134134
globalFlags := globalflags.Parse(p, cmd)
135135
if globalFlags.ProjectId == "" {
136136
return nil, &cliErr.ProjectIdError{}

internal/cmd/beta/edge/token/create/create_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/google/go-cmp/cmp/cmpopts"
99
"github.com/google/uuid"
10+
"github.com/spf13/cobra"
1011
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
1112

1213
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
@@ -157,7 +158,9 @@ func TestParseInput(t *testing.T) {
157158

158159
for _, tt := range tests {
159160
t.Run(tt.description, func(t *testing.T) {
160-
testutils.TestParseInput(t, NewCmd, parseInput, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
161+
testutils.TestParseInput(t, NewCmd, func(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
162+
return parseInput(p, cmd)
163+
}, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
161164
})
162165
}
163166
}

0 commit comments

Comments
 (0)