Skip to content

Commit de6cdc3

Browse files
committed
Remove deprecated commands
1 parent 4dffe7b commit de6cdc3

File tree

4 files changed

+11
-628
lines changed

4 files changed

+11
-628
lines changed
Lines changed: 6 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,33 @@
11
package describe
22

33
import (
4-
"context"
5-
"encoding/json"
64
"fmt"
75

8-
"github.com/goccy/go-yaml"
6+
"github.com/spf13/cobra"
97
"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"
138
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
14-
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
15-
skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils"
16-
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
17-
18-
"github.com/spf13/cobra"
19-
"github.com/stackitcloud/stackit-sdk-go/services/ske"
209
)
2110

2211
const (
2312
clusterNameArg = "CLUSTER_NAME"
2413
)
2514

26-
type inputModel struct {
27-
*globalflags.GlobalFlagModel
28-
ClusterName string
29-
}
30-
31-
func NewCmd(p *print.Printer) *cobra.Command {
15+
func NewCmd(_ *print.Printer) *cobra.Command {
3216
cmd := &cobra.Command{
3317
Use: fmt.Sprintf("describe %s", clusterNameArg),
3418
Short: "Shows details of the credentials associated to a SKE cluster",
3519
Long: "Shows details of the credentials associated to a STACKIT Kubernetes Engine (SKE) cluster",
36-
Args: args.SingleArg(clusterNameArg, nil),
20+
Args: args.NoArgs,
3721
Deprecated: fmt.Sprintf("%s\n%s\n%s\n%s\n",
38-
"and will be removed in a future release.",
22+
"and was removed.",
3923
"Please use the following command to obtain a kubeconfig file instead:",
4024
" $ stackit ske kubeconfig create CLUSTER_NAME",
4125
"For more information, visit: https://docs.stackit.cloud/stackit/en/how-to-rotate-ske-credentials-200016334.html",
4226
),
43-
Example: examples.Build(
44-
examples.NewExample(
45-
`Get details of the credentials associated to the SKE cluster with name "my-cluster"`,
46-
"$ stackit ske credentials describe my-cluster"),
47-
examples.NewExample(
48-
`Get details of the credentials associated to the SKE cluster with name "my-cluster" in JSON format`,
49-
"$ stackit ske credentials describe my-cluster --output-format json"),
50-
),
51-
RunE: func(cmd *cobra.Command, args []string) error {
52-
ctx := context.Background()
53-
model, err := parseInput(p, cmd, args)
54-
if err != nil {
55-
return err
56-
}
57-
58-
// Configure API client
59-
apiClient, err := client.ConfigureClient(p)
60-
if err != nil {
61-
return err
62-
}
6327

64-
// Check if SKE is enabled for this project
65-
enabled, err := skeUtils.ProjectEnabled(ctx, apiClient, model.ProjectId)
66-
if err != nil {
67-
return err
68-
}
69-
if !enabled {
70-
return fmt.Errorf("SKE isn't enabled for this project, please run 'stackit ske enable'")
71-
}
72-
73-
// Call API
74-
req := buildRequest(ctx, model, apiClient)
75-
resp, err := req.Execute()
76-
if err != nil {
77-
return fmt.Errorf("get SKE credentials: %w", err)
78-
}
79-
80-
return outputResult(p, model.OutputFormat, resp)
28+
RunE: func(_ *cobra.Command, _ []string) error {
29+
return nil
8130
},
8231
}
8332
return cmd
8433
}
85-
86-
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
87-
clusterName := inputArgs[0]
88-
89-
globalFlags := globalflags.Parse(p, cmd)
90-
if globalFlags.ProjectId == "" {
91-
return nil, &errors.ProjectIdError{}
92-
}
93-
94-
model := inputModel{
95-
GlobalFlagModel: globalFlags,
96-
ClusterName: clusterName,
97-
}
98-
99-
if p.IsVerbosityDebug() {
100-
modelStr, err := print.BuildDebugStrFromInputModel(model)
101-
if err != nil {
102-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
103-
} else {
104-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
105-
}
106-
}
107-
108-
return &model, nil
109-
}
110-
111-
func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiGetCredentialsRequest {
112-
req := apiClient.GetCredentials(ctx, model.ProjectId, model.ClusterName) //nolint:staticcheck //command will be removed in a later update
113-
return req
114-
}
115-
116-
func outputResult(p *print.Printer, outputFormat string, credentials *ske.Credentials) error {
117-
switch outputFormat {
118-
case print.JSONOutputFormat:
119-
details, err := json.MarshalIndent(credentials, "", " ")
120-
if err != nil {
121-
return fmt.Errorf("marshal SKE credentials: %w", err)
122-
}
123-
p.Outputln(string(details))
124-
125-
return nil
126-
case print.YAMLOutputFormat:
127-
details, err := yaml.MarshalWithOptions(credentials, yaml.IndentSequence(true))
128-
if err != nil {
129-
return fmt.Errorf("marshal SKE credentials: %w", err)
130-
}
131-
p.Outputln(string(details))
132-
133-
return nil
134-
default:
135-
table := tables.NewTable()
136-
table.AddRow("SERVER", *credentials.Server)
137-
table.AddSeparator()
138-
table.AddRow("TOKEN", *credentials.Token)
139-
err := table.Display(p)
140-
if err != nil {
141-
return fmt.Errorf("render table: %w", err)
142-
}
143-
144-
return nil
145-
}
146-
}

internal/cmd/ske/credentials/describe/describe_test.go

Lines changed: 0 additions & 206 deletions
This file was deleted.

0 commit comments

Comments
 (0)