Skip to content

Commit 8b928cb

Browse files
author
Yago Carlos Fernandez Gou
committed
Use new SDK hierarchy
1 parent 72e503b commit 8b928cb

File tree

31 files changed

+244
-203
lines changed

31 files changed

+244
-203
lines changed

internal/cmd/beta/intake/create/create.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
20-
"github.com/stackitcloud/stackit-sdk-go/services/intake/wait"
19+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
20+
"github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi/wait"
2121
)
2222

2323
const (
@@ -112,7 +112,7 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
112112
// Wait for async operation, if async mode not enabled
113113
if !model.Async {
114114
err := spinner.Run(p.Printer, "Creating STACKIT Intake instance", func() error {
115-
_, err = wait.CreateOrUpdateIntakeWaitHandler(ctx, apiClient, model.ProjectId, model.Region, resp.GetId()).WaitWithContext(ctx)
115+
_, err = wait.CreateOrUpdateIntakeWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, resp.GetId()).WaitWithContext(ctx)
116116
return err
117117
})
118118
if err != nil {
@@ -184,19 +184,19 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
184184
}
185185

186186
func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIClient) intake.ApiCreateIntakeRequest {
187-
req := apiClient.CreateIntake(ctx, model.ProjectId, model.Region)
187+
req := apiClient.DefaultAPI.CreateIntake(ctx, model.ProjectId, model.Region)
188188

189189
// Build catalog authentication
190190
var catalogAuth *intake.CatalogAuth
191191
if model.CatalogAuthType != nil {
192192
authType := intake.CatalogAuthType(*model.CatalogAuthType)
193193
catalogAuth = &intake.CatalogAuth{
194-
Type: &authType,
194+
Type: authType,
195195
}
196196
if *model.CatalogAuthType == "dremio" {
197197
catalogAuth.Dremio = &intake.DremioAuth{
198-
TokenEndpoint: model.DremioTokenEndpoint,
199-
PersonalAccessToken: model.DremioToken,
198+
TokenEndpoint: utils.PtrString(model.DremioTokenEndpoint),
199+
PersonalAccessToken: utils.PtrString(model.DremioToken),
200200
}
201201
}
202202
}
@@ -208,22 +208,22 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC
208208

209209
// Build catalog
210210
catalogPayload := intake.IntakeCatalog{
211-
Uri: model.CatalogURI,
212-
Warehouse: model.CatalogWarehouse,
211+
Uri: utils.PtrString(model.CatalogURI),
212+
Warehouse: utils.PtrString(model.CatalogWarehouse),
213213
Namespace: model.CatalogNamespace,
214214
TableName: model.CatalogTableName,
215215
Partitioning: partitioning,
216-
PartitionBy: model.CatalogPartitionBy,
216+
PartitionBy: utils.PtrValue(model.CatalogPartitionBy),
217217
Auth: catalogAuth,
218218
}
219219

220220
// Build main payload
221221
payload := intake.CreateIntakePayload{
222-
DisplayName: model.DisplayName,
223-
IntakeRunnerId: model.RunnerId,
222+
DisplayName: utils.PtrString(model.DisplayName),
223+
IntakeRunnerId: utils.PtrString(model.RunnerId),
224224
Description: model.Description,
225-
Labels: model.Labels,
226-
Catalog: &catalogPayload,
225+
Labels: utils.PtrValue(model.Labels),
226+
Catalog: catalogPayload,
227227
}
228228
req = req.CreateIntakePayload(payload)
229229

@@ -241,7 +241,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp
241241
if model.Async {
242242
operationState = "Triggered creation of"
243243
}
244-
p.Outputf("%s Intake for project %q. Intake ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id))
244+
p.Outputf("%s Intake for project %q. Intake ID: %s\n", operationState, projectLabel, resp.Id)
245245
return nil
246246
})
247247
}

internal/cmd/beta/intake/create/create_test.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
16-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
16+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1717
)
1818

1919
// Define a unique key for the context to avoid collisions
@@ -40,7 +40,9 @@ var (
4040
// testCtx dummy context for testing purposes
4141
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
4242
// testClient mock API client
43-
testClient = &intake.APIClient{}
43+
testClient = &intake.APIClient{
44+
DefaultAPI: &intake.DefaultAPIService{},
45+
}
4446
testProjectId = uuid.NewString()
4547
testRunnerId = uuid.NewString()
4648

@@ -106,22 +108,22 @@ func fixtureCreatePayload(mods ...func(payload *intake.CreateIntakePayload)) int
106108
authType := intake.CatalogAuthType(testCatalogAuthType)
107109
testPartitioningType := intake.PartitioningType(testCatalogPartitioning)
108110
payload := intake.CreateIntakePayload{
109-
DisplayName: utils.Ptr(testDisplayName),
110-
IntakeRunnerId: utils.Ptr(testRunnerId),
111+
DisplayName: testDisplayName,
112+
IntakeRunnerId: testRunnerId,
111113
Description: utils.Ptr(testDescription),
112-
Labels: utils.Ptr(testLabels),
113-
Catalog: &intake.IntakeCatalog{
114-
Uri: utils.Ptr(testCatalogURI),
115-
Warehouse: utils.Ptr(testCatalogWarehouse),
114+
Labels: testLabels,
115+
Catalog: intake.IntakeCatalog{
116+
Uri: testCatalogURI,
117+
Warehouse: testCatalogWarehouse,
116118
Namespace: utils.Ptr(testCatalogNamespace),
117119
TableName: utils.Ptr(testCatalogTableName),
118120
Partitioning: &testPartitioningType,
119-
PartitionBy: utils.Ptr(testCatalogPartitionBy),
121+
PartitionBy: testCatalogPartitionBy,
120122
Auth: &intake.CatalogAuth{
121-
Type: &authType,
123+
Type: authType,
122124
Dremio: &intake.DremioAuth{
123-
TokenEndpoint: utils.Ptr(testDremioTokenEndpoint),
124-
PersonalAccessToken: utils.Ptr(testDremioToken),
125+
TokenEndpoint: testDremioTokenEndpoint,
126+
PersonalAccessToken: testDremioToken,
125127
},
126128
},
127129
},
@@ -134,7 +136,7 @@ func fixtureCreatePayload(mods ...func(payload *intake.CreateIntakePayload)) int
134136

135137
// fixtureRequest generates an API request for tests
136138
func fixtureRequest(mods ...func(request *intake.ApiCreateIntakeRequest)) intake.ApiCreateIntakeRequest {
137-
request := testClient.CreateIntake(testCtx, testProjectId, testRegion)
139+
request := testClient.DefaultAPI.CreateIntake(testCtx, testProjectId, testRegion)
138140
request = request.CreateIntakePayload(fixtureCreatePayload())
139141
for _, mod := range mods {
140142
mod(&request)
@@ -268,7 +270,7 @@ func TestBuildRequest(t *testing.T) {
268270
expectedRequest: fixtureRequest(func(request *intake.ApiCreateIntakeRequest) {
269271
*request = (*request).CreateIntakePayload(fixtureCreatePayload(func(payload *intake.CreateIntakePayload) {
270272
authType := intake.CatalogAuthType("none")
271-
payload.Catalog.Auth.Type = &authType
273+
payload.Catalog.Auth.Type = authType
272274
payload.Catalog.Auth.Dremio = nil
273275
}))
274276
}),
@@ -281,6 +283,7 @@ func TestBuildRequest(t *testing.T) {
281283
diff := cmp.Diff(request, tt.expectedRequest,
282284
cmp.AllowUnexported(tt.expectedRequest),
283285
cmpopts.EquateComparable(testCtx),
286+
cmpopts.EquateComparable(testClient.DefaultAPI),
284287
)
285288
if diff != "" {
286289
t.Fatalf("Data does not match: %s", diff)
@@ -305,7 +308,7 @@ func TestOutputResult(t *testing.T) {
305308
args: args{
306309
model: fixtureInputModel(),
307310
projectLabel: "my-project",
308-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
311+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
309312
},
310313
wantErr: false,
311314
},
@@ -316,7 +319,7 @@ func TestOutputResult(t *testing.T) {
316319
model.Async = true
317320
}),
318321
projectLabel: "my-project",
319-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
322+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
320323
},
321324
wantErr: false,
322325
},
@@ -326,7 +329,7 @@ func TestOutputResult(t *testing.T) {
326329
model: fixtureInputModel(func(model *inputModel) {
327330
model.OutputFormat = print.JSONOutputFormat
328331
}),
329-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
332+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
330333
},
331334
wantErr: false,
332335
},

internal/cmd/beta/intake/delete/delete.go

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

77
"github.com/spf13/cobra"
8-
"github.com/stackitcloud/stackit-sdk-go/services/intake/wait"
8+
"github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi/wait"
99

1010
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1111
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -16,7 +16,7 @@ import (
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
19+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
2020
)
2121

2222
const (
@@ -69,7 +69,7 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
6969
// Wait for async operation, if async mode not enabled
7070
if !model.Async {
7171
err := spinner.Run(p.Printer, "Deleting STACKIT Intake instance", func() error {
72-
_, err = wait.DeleteIntakeWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.IntakeId).WaitWithContext(ctx)
72+
_, err = wait.DeleteIntakeWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.IntakeId).WaitWithContext(ctx)
7373
return err
7474
})
7575
if err != nil {
@@ -109,6 +109,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
109109

110110
// buildRequest creates the API request to delete an Intake
111111
func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIClient) intake.ApiDeleteIntakeRequest {
112-
req := apiClient.DeleteIntake(ctx, model.ProjectId, model.Region, model.IntakeId)
112+
req := apiClient.DefaultAPI.DeleteIntake(ctx, model.ProjectId, model.Region, model.IntakeId)
113113
return req
114114
}

internal/cmd/beta/intake/delete/delete_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/google/uuid"
1010
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
12-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
12+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1313
)
1414

1515
// Define a unique key for the context to avoid collisions
@@ -23,7 +23,9 @@ var (
2323
// testCtx is a dummy context for testing purposes
2424
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2525
// testClient is a mock API client
26-
testClient = &intake.APIClient{}
26+
testClient = &intake.APIClient{
27+
DefaultAPI: &intake.DefaultAPIService{},
28+
}
2729
testProjectId = uuid.NewString()
2830
testIntakeId = uuid.NewString()
2931
)
@@ -69,7 +71,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6971

7072
// fixtureRequest generates an API request for tests
7173
func fixtureRequest(mods ...func(request *intake.ApiDeleteIntakeRequest)) intake.ApiDeleteIntakeRequest {
72-
request := testClient.DeleteIntake(testCtx, testProjectId, testRegion, testIntakeId)
74+
request := testClient.DefaultAPI.DeleteIntake(testCtx, testProjectId, testRegion, testIntakeId)
7375
for _, mod := range mods {
7476
mod(&request)
7577
}
@@ -146,6 +148,7 @@ func TestBuildRequest(t *testing.T) {
146148
diff := cmp.Diff(request, tt.expectedRequest,
147149
cmp.AllowUnexported(tt.expectedRequest),
148150
cmpopts.EquateComparable(testCtx),
151+
cmpopts.EquateComparable(testClient.DefaultAPI),
149152
)
150153
if diff != "" {
151154
t.Fatalf("Data does not match: %s", diff)

internal/cmd/beta/intake/describe/describe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77

88
"github.com/spf13/cobra"
9-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
9+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1010

1111
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1212
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -86,7 +86,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8686
}
8787

8888
func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIClient) intake.ApiGetIntakeRequest {
89-
req := apiClient.GetIntake(ctx, model.ProjectId, model.Region, model.IntakeId)
89+
req := apiClient.DefaultAPI.GetIntake(ctx, model.ProjectId, model.Region, model.IntakeId)
9090
return req
9191
}
9292

@@ -131,8 +131,8 @@ func outputResult(p *print.Printer, outputFormat string, intk *intake.IntakeResp
131131
table.AddRow("Catalog Table Name", tableName)
132132
}
133133
table.AddRow("Catalog Partitioning", catalog.GetPartitioning())
134-
if partitionBy := catalog.GetPartitionBy(); partitionBy != nil && len(*partitionBy) > 0 {
135-
table.AddRow("Catalog Partition By", strings.Join(*partitionBy, ", "))
134+
if partitionBy := catalog.GetPartitionBy(); partitionBy != nil && len(partitionBy) > 0 {
135+
table.AddRow("Catalog Partition By", strings.Join(partitionBy, ", "))
136136
}
137137

138138
err := table.Display(p)

internal/cmd/beta/intake/describe/describe_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
14-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
14+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1515
)
1616

1717
type testCtxKey struct{}
@@ -21,8 +21,10 @@ const (
2121
)
2222

2323
var (
24-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25-
testClient = &intake.APIClient{}
24+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25+
testClient = &intake.APIClient{
26+
DefaultAPI: &intake.DefaultAPIService{},
27+
}
2628
testProjectId = uuid.NewString()
2729
testIntakeId = uuid.NewString()
2830
)
@@ -64,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6466
}
6567

6668
func fixtureRequest(mods ...func(request *intake.ApiGetIntakeRequest)) intake.ApiGetIntakeRequest {
67-
request := testClient.GetIntake(testCtx, testProjectId, testRegion, testIntakeId)
69+
request := testClient.DefaultAPI.GetIntake(testCtx, testProjectId, testRegion, testIntakeId)
6870
for _, mod := range mods {
6971
mod(&request)
7072
}
@@ -141,6 +143,7 @@ func TestBuildRequest(t *testing.T) {
141143
diff := cmp.Diff(request, tt.expectedRequest,
142144
cmp.AllowUnexported(tt.expectedRequest),
143145
cmpopts.EquateComparable(testCtx),
146+
cmpopts.EquateComparable(testClient.DefaultAPI),
144147
)
145148
if diff != "" {
146149
t.Fatalf("Data does not match: %s", diff)
@@ -161,17 +164,17 @@ func TestOutputResult(t *testing.T) {
161164
}{
162165
{
163166
name: "default output",
164-
args: args{outputFormat: "default", intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
167+
args: args{outputFormat: "default", intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
165168
wantErr: false,
166169
},
167170
{
168171
name: "json output",
169-
args: args{outputFormat: print.JSONOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
172+
args: args{outputFormat: print.JSONOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
170173
wantErr: false,
171174
},
172175
{
173176
name: "yaml output",
174-
args: args{outputFormat: print.YAMLOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
177+
args: args{outputFormat: print.YAMLOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
175178
wantErr: false,
176179
},
177180
{

internal/cmd/beta/intake/list/list.go

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

77
"github.com/spf13/cobra"
8-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
8+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
99

1010
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1111
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -119,7 +119,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
119119

120120
// buildRequest creates the API request to list Intakes
121121
func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIClient) intake.ApiListIntakesRequest {
122-
req := apiClient.ListIntakes(ctx, model.ProjectId, model.Region)
122+
req := apiClient.DefaultAPI.ListIntakes(ctx, model.ProjectId, model.Region)
123123
return req
124124
}
125125

0 commit comments

Comments
 (0)