Skip to content

Commit ac06109

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

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

internal/cmd/logs/access_token/delete_all_expired/delete_all_expired.go

Lines changed: 6 additions & 8 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 expired access token: nil result")
7876
}
7977

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

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

internal/cmd/logs/access_token/delete_all_expired/delete_all_expired_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.ApiDeleteAllExpiredAccessTokensRequest)) logs.ApiDeleteAllExpiredAccessTokensRequest {
60-
request := testClient.DeleteAllExpiredAccessTokens(testCtx, testProjectId, testRegion, testInstanceId)
60+
request := testClient.DefaultAPI.DeleteAllExpiredAccessTokens(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)