Skip to content

Commit 9598563

Browse files
committed
chore(logs): refactor access token delete all
1 parent 8e40ee0 commit 9598563

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

internal/cmd/logs/access_token/delete_all/delete_all.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import (
77
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
88

99
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
10-
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
11-
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
12-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
13-
1410
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1511
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1613
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1714
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1815
"github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/client"
1916
logUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/utils"
17+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
2018

2119
"github.com/spf13/cobra"
2220
)
@@ -55,7 +53,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5553
return err
5654
}
5755

58-
instanceLabel, err := logUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId)
56+
instanceLabel, err := logUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
5957
if err != nil {
6058
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6159
instanceLabel = model.InstanceId
@@ -77,7 +75,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7775
return fmt.Errorf("delete all access token: nil result")
7876
}
7977

80-
params.Printer.Outputf("Deleted %d access token(s)\n", len(utils.PtrValue(items.Tokens)))
78+
params.Printer.Outputf("Deleted %d access token(s)\n", len(items.Tokens))
8179
return nil
8280
},
8381
}
@@ -108,5 +106,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
108106
}
109107

110108
func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiDeleteAllAccessTokensRequest {
111-
return apiClient.DeleteAllAccessTokens(ctx, model.ProjectId, model.Region, model.InstanceId)
109+
return apiClient.DefaultAPI.DeleteAllAccessTokens(ctx, model.ProjectId, model.Region, model.InstanceId)
112110
}

internal/cmd/logs/access_token/delete_all/delete_all_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type testCtxKey struct{}
2121

2222
var (
2323
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
24-
testClient = &logs.APIClient{}
24+
testClient = &logs.APIClient{DefaultAPI: &logs.DefaultAPIService{}}
2525

2626
testProjectId = uuid.NewString()
2727
testInstanceId = uuid.NewString()
@@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5757
}
5858

5959
func fixtureRequest(mods ...func(request *logs.ApiDeleteAllAccessTokensRequest)) logs.ApiDeleteAllAccessTokensRequest {
60-
request := testClient.DeleteAllAccessTokens(testCtx, testProjectId, testRegion, testInstanceId)
60+
request := testClient.DefaultAPI.DeleteAllAccessTokens(testCtx, testProjectId, testRegion, testInstanceId)
6161
for _, mod := range mods {
6262
mod(&request)
6363
}
@@ -153,7 +153,7 @@ func TestBuildRequest(t *testing.T) {
153153

154154
diff := cmp.Diff(request, tt.expectedRequest,
155155
cmp.AllowUnexported(tt.expectedRequest),
156-
cmpopts.EquateComparable(testCtx),
156+
cmpopts.EquateComparable(testCtx, tt.expectedRequest),
157157
)
158158
if diff != "" {
159159
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)