Skip to content

Commit 96d51c4

Browse files
authored
chore(logs): sdk migration (#1444)
relates to STACKITCLI-367
1 parent 1e4db53 commit 96d51c4

34 files changed

Lines changed: 272 additions & 260 deletions

docs/stackit_logs_access-token_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ stackit logs access-token create [flags]
3030
--display-name string Display name for the access token
3131
-h, --help Help for "stackit logs access-token create"
3232
--instance-id string ID of the Logs instance
33-
--lifetime int Lifetime of the access token in days [1 - 180]
33+
--lifetime int32 Lifetime of the access token in days [1 - 180]
3434
--permissions strings Permissions of the access token ["read" "write"]
3535
```
3636

docs/stackit_logs_instance_create.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ stackit logs instance create [flags]
2626
### Options
2727

2828
```
29-
--acl strings Access control list
30-
--description string Description
31-
--display-name string Display name
32-
-h, --help Help for "stackit logs instance create"
33-
--retention-days int The days for how long the logs should be stored before being cleaned up
29+
--acl strings Access control list
30+
--description string Description
31+
--display-name string Display name
32+
-h, --help Help for "stackit logs instance create"
33+
--retention-days int32 The days for how long the logs should be stored before being cleaned up
3434
```
3535

3636
### Options inherited from parent commands

docs/stackit_logs_instance_update.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ stackit logs instance update INSTANCE_ID [flags]
2626
### Options
2727

2828
```
29-
--acl strings Access control list
30-
--description string Description
31-
--display-name string Display name
32-
-h, --help Help for "stackit logs instance update"
33-
--retention-days int The days for how long the logs should be stored before being cleaned up
29+
--acl strings Access control list
30+
--description string Description
31+
--display-name string Display name
32+
-h, --help Help for "stackit logs instance update"
33+
--retention-days int32 The days for how long the logs should be stored before being cleaned up
3434
```
3535

3636
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0
2525
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.13.0
2626
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1
27-
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
27+
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0
2828
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0
2929
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0
3030
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0 h1:1dvL7tX9
614614
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0/go.mod h1:+Ld3dn648I+YKcBV3fEkYpDSr3fel421+LurJGywSBs=
615615
github.com/stackitcloud/stackit-sdk-go/services/logme v1.0.1 h1:iteL61eMMPWT6872nF4Ko/tBU1IXemvS++XR09pj6NA=
616616
github.com/stackitcloud/stackit-sdk-go/services/logme v1.0.1/go.mod h1:JDOOYaGgcBts2x52nKPRMFgSZe7qqOFmfz1xIXCQgRY=
617-
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 h1:vr4atxFRT+EL+DqONMT5R44f7AzEMbePa9U7PEE0THU=
618-
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2/go.mod h1:CAPsiTX7osAImfrG5RnIjaJ/Iz3QpoBKuH2fS346wuQ=
617+
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0 h1:g7zpfQFFq3UhAWrMK9rPaZY6dLMAuMJf5g6+r7VRTXc=
618+
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0/go.mod h1:tvRejL8w5KpGBbLFPQ+dXOJURgZ3OMbZmwxlKQrGMuA=
619619
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0 h1:LFIH1wAp633ZAJw/7H3F4nq1DZe0Qu3rlDeXhobZEZA=
620620
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0/go.mod h1:joa89Y1dyn0j22FstRcIKfW2ada3FDxNfttxSvq27uY=
621621
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0 h1:SVd3WMmLAE0Jxk2SaRuM85DTOOXHycyMpZGx9vzqNkI=

internal/cmd/logs/access_token/create/create.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
99

10-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
10+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -35,7 +35,7 @@ type inputModel struct {
3535
InstanceId string
3636
Description *string
3737
DisplayName string
38-
Lifetime *int64
38+
Lifetime *int32
3939
Permissions []string
4040
}
4141

@@ -80,7 +80,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8080
projectLabel = model.ProjectId
8181
}
8282

83-
instanceLabel, err := logsUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId)
83+
instanceLabel, err := logsUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
8484
if err != nil {
8585
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
8686
instanceLabel = model.InstanceId
@@ -110,7 +110,7 @@ func configureFlags(cmd *cobra.Command) {
110110
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the Logs instance")
111111
cmd.Flags().String(displayNameFlag, "", "Display name for the access token")
112112
cmd.Flags().String(descriptionFlag, "", "Description of the access token")
113-
cmd.Flags().Int64(lifetimeFlag, 0, "Lifetime of the access token in days [1 - 180]")
113+
cmd.Flags().Int32(lifetimeFlag, 0, "Lifetime of the access token in days [1 - 180]")
114114
cmd.Flags().StringSlice(permissionsFlag, []string{}, `Permissions of the access token ["read" "write"]`)
115115

116116
err := flags.MarkFlagsRequired(cmd, instanceIdFlag, displayNameFlag, permissionsFlag)
@@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
128128
DisplayName: flags.FlagToStringValue(p, cmd, displayNameFlag),
129129
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
130130
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
131-
Lifetime: flags.FlagToInt64Pointer(p, cmd, lifetimeFlag),
131+
Lifetime: flags.FlagToInt32Pointer(p, cmd, lifetimeFlag),
132132
Permissions: flags.FlagToStringSliceValue(p, cmd, permissionsFlag),
133133
}
134134

@@ -137,13 +137,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
137137
}
138138

139139
func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiCreateAccessTokenRequest {
140-
req := apiClient.CreateAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId)
141-
140+
req := apiClient.DefaultAPI.CreateAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId)
142141
return req.CreateAccessTokenPayload(logs.CreateAccessTokenPayload{
143142
Description: model.Description,
144-
DisplayName: &model.DisplayName,
143+
DisplayName: model.DisplayName,
145144
Lifetime: model.Lifetime,
146-
Permissions: &model.Permissions,
145+
Permissions: utils.Map(model.Permissions, func(t string) logs.PermissionsInner {
146+
return logs.PermissionsInner(t)
147+
}),
147148
})
148149
}
149150

@@ -152,7 +153,7 @@ func outputResult(p *print.Printer, outputFormat, instanceLabel string, accessTo
152153
return fmt.Errorf("access token cannot be nil")
153154
}
154155
return p.OutputResult(outputFormat, accessToken, func() error {
155-
p.Outputf("Created access token for Logs instance %q.\n\nID: %s\nToken: %s\n", instanceLabel, utils.PtrValue(accessToken.Id), utils.PtrValue(accessToken.AccessToken))
156+
p.Outputf("Created access token for Logs instance %q.\n\nID: %s\nToken: %s\n", instanceLabel, accessToken.Id, utils.PtrValue(accessToken.AccessToken))
156157
return nil
157158
})
158159
}

internal/cmd/logs/access_token/create/create_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
15+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
1616
)
1717

1818
const (
@@ -26,7 +26,7 @@ type testCtxKey struct{}
2626

2727
var (
2828
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
29-
testClient = &logs.APIClient{}
29+
testClient = &logs.APIClient{DefaultAPI: &logs.DefaultAPIService{}}
3030
testProjectId = uuid.NewString()
3131
testInstanceId = uuid.NewString()
3232
)
@@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5959
InstanceId: testInstanceId,
6060
Description: utils.Ptr(testDescription),
6161
DisplayName: testDisplayName,
62-
Lifetime: utils.Ptr(int64(0)),
62+
Lifetime: utils.Ptr(int32(0)),
6363
Permissions: []string{
6464
"read",
6565
"write",
@@ -72,7 +72,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
7272
}
7373

7474
func fixtureRequest(mods ...func(request *logs.ApiCreateAccessTokenRequest)) logs.ApiCreateAccessTokenRequest {
75-
request := testClient.CreateAccessToken(testCtx, testProjectId, testRegion, testInstanceId)
75+
request := testClient.DefaultAPI.CreateAccessToken(testCtx, testProjectId, testRegion, testInstanceId)
7676
request = request.CreateAccessTokenPayload(fixturePayload())
7777
for _, mod := range mods {
7878
mod(&request)
@@ -82,13 +82,13 @@ func fixtureRequest(mods ...func(request *logs.ApiCreateAccessTokenRequest)) log
8282

8383
func fixturePayload(mods ...func(payload *logs.CreateAccessTokenPayload)) logs.CreateAccessTokenPayload {
8484
payload := logs.CreateAccessTokenPayload{
85-
DisplayName: utils.Ptr(testDisplayName),
85+
DisplayName: testDisplayName,
8686
Description: utils.Ptr(testDescription),
87-
Lifetime: utils.Ptr(int64(0)),
88-
Permissions: utils.Ptr([]string{
89-
"read",
90-
"write",
91-
}),
87+
Lifetime: utils.Ptr(int32(0)),
88+
Permissions: []logs.PermissionsInner{
89+
logs.PERMISSIONSINNER_READ,
90+
logs.PERMISSIONSINNER_WRITE,
91+
},
9292
}
9393
for _, mod := range mods {
9494
mod(&payload)
@@ -215,7 +215,7 @@ func TestBuildRequest(t *testing.T) {
215215

216216
diff := cmp.Diff(tt.expectedRequest, request,
217217
cmp.AllowUnexported(tt.expectedRequest),
218-
cmpopts.EquateComparable(testCtx),
218+
cmpopts.EquateComparable(testCtx, logs.DefaultAPIService{}),
219219
)
220220
if diff != "" {
221221
t.Fatalf("Data does not match: %s", diff)
@@ -240,16 +240,16 @@ func TestOutputResult(t *testing.T) {
240240
args: args{
241241
instanceLabel: "",
242242
accessToken: utils.Ptr(logs.AccessToken{
243-
Id: utils.Ptr(uuid.NewString()),
244-
Permissions: utils.Ptr([]string{
245-
"read",
246-
"write",
247-
}),
248-
DisplayName: utils.Ptr("Token"),
243+
Id: uuid.NewString(),
244+
Permissions: []logs.PermissionsInner{
245+
logs.PERMISSIONSINNER_READ,
246+
logs.PERMISSIONSINNER_WRITE,
247+
},
248+
DisplayName: "Token",
249249
AccessToken: utils.Ptr("Secret access token"),
250-
Creator: utils.Ptr(uuid.NewString()),
251-
Expires: utils.Ptr(false),
252-
Status: utils.Ptr(logs.ACCESSTOKENSTATUS_ACTIVE),
250+
Creator: uuid.NewString(),
251+
Expires: false,
252+
Status: logs.ACCESSTOKENSTATUS_ACTIVE,
253253
}),
254254
},
255255
wantErr: false,

internal/cmd/logs/access_token/delete/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
7+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
88

99
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1010
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
@@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5858
}
5959

6060
// Get the display name for confirmation
61-
accessTokenLabel, err := logUtils.GetAccessTokenName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
61+
accessTokenLabel, err := logUtils.GetAccessTokenName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
6262
if err != nil {
6363
params.Printer.Debug(print.ErrorLevel, "get access token: %v", err)
6464
}
@@ -113,5 +113,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
113113
}
114114

115115
func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiDeleteAccessTokenRequest {
116-
return apiClient.DeleteAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
116+
return apiClient.DefaultAPI.DeleteAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
117117
}

internal/cmd/logs/access_token/delete/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
13+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
1414
)
1515

1616
const (
@@ -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()
@@ -69,7 +69,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6969
}
7070

7171
func fixtureRequest(mods ...func(request *logs.ApiDeleteAccessTokenRequest)) logs.ApiDeleteAccessTokenRequest {
72-
request := testClient.DeleteAccessToken(testCtx, testProjectId, testRegion, testInstanceId, testAccessTokenId)
72+
request := testClient.DefaultAPI.DeleteAccessToken(testCtx, testProjectId, testRegion, testInstanceId, testAccessTokenId)
7373
for _, mod := range mods {
7474
mod(&request)
7575
}
@@ -197,7 +197,7 @@ func TestBuildRequest(t *testing.T) {
197197

198198
diff := cmp.Diff(request, tt.expectedRequest,
199199
cmp.AllowUnexported(tt.expectedRequest),
200-
cmpopts.EquateComparable(testCtx),
200+
cmpopts.EquateComparable(testCtx, logs.DefaultAPIService{}),
201201
)
202202
if diff != "" {
203203
t.Fatalf("Data does not match: %s", diff)

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
7+
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
}

0 commit comments

Comments
 (0)