Skip to content

Commit a9f8e43

Browse files
authored
chore(git): migrate to new SDK structure (#1435)
relates to STACKITCLI-363
1 parent 8ceb3c7 commit a9f8e43

17 files changed

Lines changed: 103 additions & 120 deletions

File tree

docs/stackit_git_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ stackit git instance [flags]
3333
* [stackit git instance create](./stackit_git_instance_create.md) - Creates STACKIT Git instance
3434
* [stackit git instance delete](./stackit_git_instance_delete.md) - Deletes STACKIT Git instance
3535
* [stackit git instance describe](./stackit_git_instance_describe.md) - Describes STACKIT Git instance
36-
* [stackit git instance list](./stackit_git_instance_list.md) - Lists all instances of STACKIT Git.
36+
* [stackit git instance list](./stackit_git_instance_list.md) - Lists all instances of STACKIT Git
3737

docs/stackit_git_instance_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## stackit git instance list
22

3-
Lists all instances of STACKIT Git.
3+
Lists all instances of STACKIT Git
44

55
### Synopsis
66

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0
2222
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6
2323
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3
24-
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3
24+
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0
2525
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0
2626
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1
2727
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 h1:GBRb49x5Nax/oQQaa
606606
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6/go.mod h1:IX9iL3MigDZUmzwswTJMfYvyi118KAHrFMfjJUy5NYk=
607607
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 h1:TxChb2qbO82JiQEBYClSSD5HZxqKeKJ6dIvkEUCJmbs=
608608
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3/go.mod h1:KVWvQHb7CQLD9DzA4Np3WmakiCCsrHaCXvFEnOQ7nPk=
609-
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3 h1:VIjkSofZz9utOOkBdNZCIb07P/JdKc1kHV1P8Rq9dLc=
610-
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3/go.mod h1:EJk1Ss9GTel2NPIu/w3+x9XcQcEd2k3ibea5aQDzVhQ=
609+
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0 h1:VZBneGprCmHqckcSMPs3puBlK8rBpLMtYKmBktwdoVE=
610+
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0/go.mod h1:YZEL+gaK+ELn5E9VtK8yvz5RcmCBH+JkRpf6YbNVSbM=
611611
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0 h1:H4V3H8qSKOaOalIrf4nAPDHhXnHYGs6SDGuK8Zj41Zo=
612612
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0/go.mod h1:Ts06id0KejUlQWbpR+/rm+tKng6QkTuFV1VQTPJ4dA4=
613613
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1 h1:7ZSrwps/zI41rl+xYkG4osld8cyAwssyl/UZ/Iu/F2g=
@@ -654,8 +654,6 @@ github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0 h1:JWAFnskRbNKT8x62pZ
654654
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0/go.mod h1:jMlBoXqrPNX5nXbo6oT7exalqilw1jiLPoIp4Cn0CdI=
655655
github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0 h1:QoKyQPe8FqDqJLNgE5uRlZ/y1c1GUxjV1DDLu5QEBD8=
656656
github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0/go.mod h1:KhVYCR58wETqdI7Quwhe3OR3BhB2T/b7DzaMsfDnr8g=
657-
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3 h1:AQrcr+qeIuZob+3TT2q1L4WOPtpsu5SEpkTnOUHDqfE=
658-
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3/go.mod h1:8BBGC69WFXWWmKgzSjgE4HvsI7pEgO0RN2cASwuPJ18=
659657
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0 h1:PwjQeupEnXxhu+uWCUzO/hUfL4yqNblOcZbP2jvaQtU=
660658
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0/go.mod h1:AiUoMAqQcOlMgDtkVJlqI7P/VGD5xjN3dYjERGnwN/M=
661659
github.com/stbenjam/no-sprintf-host-port v0.3.1 h1:AyX7+dxI4IdLBPtDbsGAyqiTSLpCP9hWRrXQDU4Cm/g=

internal/cmd/git/flavor/list/list.go

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

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/git"
10+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -18,7 +18,6 @@ import (
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
1919
"github.com/stackitcloud/stackit-cli/internal/pkg/services/git/client"
2020
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
21-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2221
)
2322

2423
type inputModel struct {
@@ -110,7 +109,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
110109
}
111110

112111
func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClient) git.ApiListFlavorsRequest {
113-
return apiClient.ListFlavors(ctx, model.ProjectId)
112+
return apiClient.DefaultAPI.ListFlavors(ctx, model.ProjectId)
114113
}
115114

116115
func outputResult(p *print.Printer, outputFormat, projectLabel string, flavors []git.Flavor) error {
@@ -125,11 +124,11 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, flavors [
125124
for i := range flavors {
126125
flavor := (flavors)[i]
127126
table.AddRow(
128-
utils.PtrString(flavor.Id),
129-
utils.PtrString(flavor.Description),
130-
utils.PtrString(flavor.DisplayName),
131-
utils.PtrString(flavor.Availability),
132-
utils.PtrString(flavor.Sku),
127+
flavor.Id,
128+
flavor.Description,
129+
flavor.DisplayName,
130+
flavor.Availability,
131+
flavor.Sku,
133132
)
134133
}
135134
err := table.Display(p)

internal/cmd/git/flavor/list/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +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/stackitcloud/stackit-sdk-go/services/git"
11+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
1212

1313
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
@@ -19,7 +19,7 @@ import (
1919
type testCtxKey struct{}
2020

2121
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
22-
var testClient = &git.APIClient{}
22+
var testClient = &git.APIClient{DefaultAPI: &git.DefaultAPIService{}}
2323
var testProjectId = uuid.NewString()
2424

2525
const (
@@ -50,7 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5050
}
5151

5252
func fixtureRequest(mods ...func(request *git.ApiListFlavorsRequest)) git.ApiListFlavorsRequest {
53-
request := testClient.ListFlavors(testCtx, testProjectId)
53+
request := testClient.DefaultAPI.ListFlavors(testCtx, testProjectId)
5454
for _, mod := range mods {
5555
mod(&request)
5656
}
@@ -148,7 +148,7 @@ func TestBuildRequest(t *testing.T) {
148148
request := buildRequest(testCtx, tt.model, testClient)
149149

150150
diff := cmp.Diff(request, tt.expectedRequest,
151-
cmp.AllowUnexported(tt.expectedRequest),
151+
cmp.AllowUnexported(tt.expectedRequest, git.DefaultAPIService{}),
152152
cmpopts.EquateComparable(testCtx),
153153
)
154154
if diff != "" {

internal/cmd/git/instance/create/create.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"fmt"
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
89

910
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/git"
11-
"github.com/stackitcloud/stackit-sdk-go/services/git/wait"
11+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
12+
"github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi/wait"
1213

1314
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -82,8 +83,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8283

8384
// Wait for async operation, if async mode not enabled
8485
if !model.Async {
85-
err := spinner.Run(params.Printer, "Creating STACKIT git instance", func() error {
86-
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *result.Id).WaitWithContext(ctx)
86+
err := spinner.Run(params.Printer, "Creating STACKIT Git instance", func() error {
87+
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, result.Id).WaitWithContext(ctx)
8788
return err
8889
})
8990
if err != nil {
@@ -130,31 +131,28 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
130131
}
131132

132133
func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClient) git.ApiCreateInstanceRequest {
133-
return apiClient.CreateInstance(ctx, model.ProjectId).CreateInstancePayload(createPayload(model))
134+
return apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId).CreateInstancePayload(createPayload(model))
134135
}
135136

136137
func createPayload(model *inputModel) git.CreateInstancePayload {
137138
return git.CreateInstancePayload{
138-
Name: &model.Name,
139-
Flavor: git.CreateInstancePayloadGetFlavorAttributeType(&model.Flavor),
140-
Acl: &model.Acl,
139+
Name: model.Name,
140+
Flavor: utils.Ptr(git.CreateInstancePayloadFlavor(model.Flavor)),
141+
Acl: model.Acl,
141142
}
142143
}
143144

144145
func outputResult(p *print.Printer, outputFormat string, async bool, instanceName string, resp *git.Instance) error {
145146
if resp == nil {
146147
return fmt.Errorf("API resp is nil")
147148
}
148-
if resp.Id == nil {
149-
return fmt.Errorf("API resp is missing instance id")
150-
}
151149

152150
return p.OutputResult(outputFormat, resp, func() error {
153151
operationState := "Created"
154152
if async {
155153
operationState = "Triggered creation of"
156154
}
157-
p.Outputf("%s instance %q with id %s\n", operationState, instanceName, *resp.Id)
155+
p.Outputf("%s instance %q with id %s\n", operationState, instanceName, resp.Id)
158156
return nil
159157
})
160158
}

internal/cmd/git/instance/create/create_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +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/stackitcloud/stackit-sdk-go/services/git"
10+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
@@ -20,7 +20,7 @@ type testCtxKey struct{}
2020

2121
var (
2222
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
23-
testClient = &git.APIClient{}
23+
testClient = &git.APIClient{DefaultAPI: &git.DefaultAPIService{}}
2424
testProjectId = uuid.NewString()
2525

2626
testName = "test-instance"
@@ -57,9 +57,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5757

5858
func fixtureCreatePayload(mods ...func(payload *git.CreateInstancePayload)) (payload git.CreateInstancePayload) {
5959
payload = git.CreateInstancePayload{
60-
Name: &testName,
61-
Flavor: git.CreateInstancePayloadGetFlavorAttributeType(&testFlavor),
62-
Acl: &testAcl,
60+
Name: testName,
61+
Flavor: utils.Ptr(git.CreateInstancePayloadFlavor(testFlavor)),
62+
Acl: testAcl,
6363
}
6464
for _, mod := range mods {
6565
mod(&payload)
@@ -68,7 +68,7 @@ func fixtureCreatePayload(mods ...func(payload *git.CreateInstancePayload)) (pay
6868
}
6969

7070
func fixtureRequest(mods ...func(request *git.ApiCreateInstanceRequest)) git.ApiCreateInstanceRequest {
71-
request := testClient.CreateInstance(testCtx, testProjectId)
71+
request := testClient.DefaultAPI.CreateInstance(testCtx, testProjectId)
7272

7373
request = request.CreateInstancePayload(fixtureCreatePayload())
7474

@@ -151,8 +151,8 @@ func TestBuildRequest(t *testing.T) {
151151
model.Name = "new-name"
152152
}),
153153
expectedRequest: fixtureRequest(func(request *git.ApiCreateInstanceRequest) {
154-
*request = (*request).CreateInstancePayload(fixtureCreatePayload(func(payload *git.CreateInstancePayload) {
155-
payload.Name = utils.Ptr("new-name")
154+
*request = request.CreateInstancePayload(fixtureCreatePayload(func(payload *git.CreateInstancePayload) {
155+
payload.Name = "new-name"
156156
}))
157157
}),
158158
},
@@ -164,7 +164,7 @@ func TestBuildRequest(t *testing.T) {
164164
diff := cmp.Diff(request, tt.expectedRequest,
165165
cmp.AllowUnexported(tt.expectedRequest),
166166
cmpopts.EquateComparable(testCtx),
167-
cmp.AllowUnexported(git.NullableString{}),
167+
cmp.AllowUnexported(git.NullableString{}, git.DefaultAPIService{}),
168168
)
169169
if diff != "" {
170170
t.Fatalf("Data does not match: %s", diff)
@@ -201,7 +201,7 @@ func TestOutputResult(t *testing.T) {
201201
outputFormat: "",
202202
async: false,
203203
instanceName: "",
204-
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
204+
resp: &git.Instance{Id: uuid.NewString()},
205205
},
206206
wantErr: false,
207207
},
@@ -211,7 +211,7 @@ func TestOutputResult(t *testing.T) {
211211
outputFormat: print.JSONOutputFormat,
212212
async: true,
213213
instanceName: testName,
214-
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
214+
resp: &git.Instance{Id: uuid.NewString()},
215215
},
216216
wantErr: false,
217217
},

internal/cmd/git/instance/delete/delete.go

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

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/git"
11-
"github.com/stackitcloud/stackit-sdk-go/services/git/wait"
10+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
11+
"github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi/wait"
1212

1313
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5858
projectName = model.ProjectId
5959
}
6060

61-
instanceName, err := gitUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId)
61+
instanceName, err := gitUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId)
6262
if err != nil {
6363
params.Printer.Debug(print.ErrorLevel, "get stackit git intance name: %v", err)
6464
instanceName = model.InstanceId
@@ -82,8 +82,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8282

8383
// Wait for async operation, if async mode not enabled
8484
if !model.Async {
85-
err := spinner.Run(params.Printer, "Deleting STACKIT git instance", func() error {
86-
_, err = wait.DeleteGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx)
85+
err := spinner.Run(params.Printer, "Deleting STACKIT Git instance", func() error {
86+
_, err = wait.DeleteGitInstanceWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId).WaitWithContext(ctx)
8787
return err
8888
})
8989
if err != nil {
@@ -120,5 +120,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
120120
}
121121

122122
func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClient) git.ApiDeleteInstanceRequest {
123-
return apiClient.DeleteInstance(ctx, model.ProjectId, model.InstanceId)
123+
return apiClient.DefaultAPI.DeleteInstance(ctx, model.ProjectId, model.InstanceId)
124124
}

internal/cmd/git/instance/delete/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +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/stackitcloud/stackit-sdk-go/services/git"
10+
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1313

@@ -18,7 +18,7 @@ type testCtxKey struct{}
1818

1919
var (
2020
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
testClient = &git.APIClient{}
21+
testClient = &git.APIClient{DefaultAPI: &git.DefaultAPIService{}}
2222
testProjectId = uuid.NewString()
2323
testInstanceId = uuid.NewString()
2424
)
@@ -45,7 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4545
}
4646

4747
func fixtureRequest(mods ...func(request *git.ApiDeleteInstanceRequest)) git.ApiDeleteInstanceRequest {
48-
request := testClient.DeleteInstance(testCtx, testProjectId, testInstanceId)
48+
request := testClient.DefaultAPI.DeleteInstance(testCtx, testProjectId, testInstanceId)
4949
for _, mod := range mods {
5050
mod(&request)
5151
}
@@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) {
172172
t.Run(tt.description, func(t *testing.T) {
173173
request := buildRequest(testCtx, tt.model, testClient)
174174
diff := cmp.Diff(request, tt.expectedRequest,
175-
cmp.AllowUnexported(tt.expectedRequest),
175+
cmp.AllowUnexported(tt.expectedRequest, git.DefaultAPIService{}),
176176
cmpopts.EquateComparable(testCtx),
177177
)
178178
if diff != "" {

0 commit comments

Comments
 (0)