Skip to content

Commit 1763f3a

Browse files
author
Yago Carlos Fernandez Gou
committed
Use new SDK hierarchy
# Conflicts: # internal/cmd/beta/intake/create/create.go # internal/cmd/beta/intake/create/create_test.go # internal/cmd/beta/intake/delete/delete.go # internal/cmd/beta/intake/delete/delete_test.go # internal/cmd/beta/intake/describe/describe_test.go # internal/cmd/beta/intake/list/list_test.go # internal/cmd/beta/intake/runner/create/create_test.go # internal/cmd/beta/intake/runner/delete/delete.go # internal/cmd/beta/intake/runner/delete/delete_test.go # internal/cmd/beta/intake/runner/describe/describe_test.go # internal/cmd/beta/intake/runner/list/list.go # internal/cmd/beta/intake/runner/list/list_test.go # internal/cmd/beta/intake/runner/update/update.go # internal/cmd/beta/intake/runner/update/update_test.go # internal/cmd/beta/intake/update/update_test.go # internal/cmd/beta/intake/user/create/create.go # internal/cmd/beta/intake/user/create/create_test.go # internal/cmd/beta/intake/user/delete/delete.go # internal/cmd/beta/intake/user/delete/delete_test.go # internal/cmd/beta/intake/user/describe/describe.go # internal/cmd/beta/intake/user/describe/describe_test.go # internal/cmd/beta/intake/user/list/list.go # internal/cmd/beta/intake/user/list/list_test.go # internal/cmd/beta/intake/user/update/update.go # internal/cmd/beta/intake/user/update/update_test.go # internal/pkg/services/intake/client/client.go
1 parent 83cf194 commit 1763f3a

File tree

31 files changed

+244
-229
lines changed

31 files changed

+244
-229
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import (
55
"fmt"
66

77
"github.com/spf13/cobra"
8-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
9-
"github.com/stackitcloud/stackit-sdk-go/services/intake/wait"
10-
118
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
129
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1310
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -19,6 +16,8 @@ import (
1916
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
2017
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
2118
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
20+
"github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi/wait"
2221
)
2322

2423
const (
@@ -113,7 +112,7 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
113112
// Wait for async operation, if async mode not enabled
114113
if !model.Async {
115114
err := spinner.Run(p.Printer, "Creating STACKIT Intake instance", func() error {
116-
_, 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)
117116
return err
118117
})
119118
if err != nil {
@@ -185,19 +184,19 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
185184
}
186185

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

190189
// Build catalog authentication
191190
var catalogAuth *intake.CatalogAuth
192191
if model.CatalogAuthType != nil {
193192
authType := intake.CatalogAuthType(*model.CatalogAuthType)
194193
catalogAuth = &intake.CatalogAuth{
195-
Type: &authType,
194+
Type: authType,
196195
}
197196
if *model.CatalogAuthType == "dremio" {
198197
catalogAuth.Dremio = &intake.DremioAuth{
199-
TokenEndpoint: model.DremioTokenEndpoint,
200-
PersonalAccessToken: model.DremioToken,
198+
TokenEndpoint: utils.PtrString(model.DremioTokenEndpoint),
199+
PersonalAccessToken: utils.PtrString(model.DremioToken),
201200
}
202201
}
203202
}
@@ -209,22 +208,22 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC
209208

210209
// Build catalog
211210
catalogPayload := intake.IntakeCatalog{
212-
Uri: model.CatalogURI,
213-
Warehouse: model.CatalogWarehouse,
211+
Uri: utils.PtrString(model.CatalogURI),
212+
Warehouse: utils.PtrString(model.CatalogWarehouse),
214213
Namespace: model.CatalogNamespace,
215214
TableName: model.CatalogTableName,
216215
Partitioning: partitioning,
217-
PartitionBy: model.CatalogPartitionBy,
216+
PartitionBy: utils.PtrValue(model.CatalogPartitionBy),
218217
Auth: catalogAuth,
219218
}
220219

221220
// Build main payload
222221
payload := intake.CreateIntakePayload{
223-
DisplayName: model.DisplayName,
224-
IntakeRunnerId: model.RunnerId,
222+
DisplayName: utils.PtrString(model.DisplayName),
223+
IntakeRunnerId: utils.PtrString(model.RunnerId),
225224
Description: model.Description,
226-
Labels: model.Labels,
227-
Catalog: &catalogPayload,
225+
Labels: utils.PtrValue(model.Labels),
226+
Catalog: catalogPayload,
228227
}
229228
req = req.CreateIntakePayload(payload)
230229

@@ -242,7 +241,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp
242241
if model.Async {
243242
operationState = "Triggered creation of"
244243
}
245-
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)
246245
return nil
247246
})
248247
}

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import (
88
"github.com/google/go-cmp/cmp/cmpopts"
99
"github.com/google/uuid"
1010
"github.com/spf13/cobra"
11-
"github.com/stackitcloud/stackit-sdk-go/services/intake"
12-
1311
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1412
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1513
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1614
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1715
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
16+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1817
)
1918

2019
// Define a unique key for the context to avoid collisions
@@ -41,7 +40,9 @@ var (
4140
// testCtx dummy context for testing purposes
4241
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
4342
// testClient mock API client
44-
testClient = &intake.APIClient{}
43+
testClient = &intake.APIClient{
44+
DefaultAPI: &intake.DefaultAPIService{},
45+
}
4546
testProjectId = uuid.NewString()
4647
testRunnerId = uuid.NewString()
4748

@@ -107,22 +108,22 @@ func fixtureCreatePayload(mods ...func(payload *intake.CreateIntakePayload)) int
107108
authType := intake.CatalogAuthType(testCatalogAuthType)
108109
testPartitioningType := intake.PartitioningType(testCatalogPartitioning)
109110
payload := intake.CreateIntakePayload{
110-
DisplayName: utils.Ptr(testDisplayName),
111-
IntakeRunnerId: utils.Ptr(testRunnerId),
111+
DisplayName: testDisplayName,
112+
IntakeRunnerId: testRunnerId,
112113
Description: utils.Ptr(testDescription),
113-
Labels: utils.Ptr(testLabels),
114-
Catalog: &intake.IntakeCatalog{
115-
Uri: utils.Ptr(testCatalogURI),
116-
Warehouse: utils.Ptr(testCatalogWarehouse),
114+
Labels: testLabels,
115+
Catalog: intake.IntakeCatalog{
116+
Uri: testCatalogURI,
117+
Warehouse: testCatalogWarehouse,
117118
Namespace: utils.Ptr(testCatalogNamespace),
118119
TableName: utils.Ptr(testCatalogTableName),
119120
Partitioning: &testPartitioningType,
120-
PartitionBy: utils.Ptr(testCatalogPartitionBy),
121+
PartitionBy: testCatalogPartitionBy,
121122
Auth: &intake.CatalogAuth{
122-
Type: &authType,
123+
Type: authType,
123124
Dremio: &intake.DremioAuth{
124-
TokenEndpoint: utils.Ptr(testDremioTokenEndpoint),
125-
PersonalAccessToken: utils.Ptr(testDremioToken),
125+
TokenEndpoint: testDremioTokenEndpoint,
126+
PersonalAccessToken: testDremioToken,
126127
},
127128
},
128129
},
@@ -135,7 +136,7 @@ func fixtureCreatePayload(mods ...func(payload *intake.CreateIntakePayload)) int
135136

136137
// fixtureRequest generates an API request for tests
137138
func fixtureRequest(mods ...func(request *intake.ApiCreateIntakeRequest)) intake.ApiCreateIntakeRequest {
138-
request := testClient.CreateIntake(testCtx, testProjectId, testRegion)
139+
request := testClient.DefaultAPI.CreateIntake(testCtx, testProjectId, testRegion)
139140
request = request.CreateIntakePayload(fixtureCreatePayload())
140141
for _, mod := range mods {
141142
mod(&request)
@@ -269,7 +270,7 @@ func TestBuildRequest(t *testing.T) {
269270
expectedRequest: fixtureRequest(func(request *intake.ApiCreateIntakeRequest) {
270271
*request = (*request).CreateIntakePayload(fixtureCreatePayload(func(payload *intake.CreateIntakePayload) {
271272
authType := intake.CatalogAuthType("none")
272-
payload.Catalog.Auth.Type = &authType
273+
payload.Catalog.Auth.Type = authType
273274
payload.Catalog.Auth.Dremio = nil
274275
}))
275276
}),
@@ -282,6 +283,7 @@ func TestBuildRequest(t *testing.T) {
282283
diff := cmp.Diff(request, tt.expectedRequest,
283284
cmp.AllowUnexported(tt.expectedRequest),
284285
cmpopts.EquateComparable(testCtx),
286+
cmpopts.EquateComparable(testClient.DefaultAPI),
285287
)
286288
if diff != "" {
287289
t.Fatalf("Data does not match: %s", diff)
@@ -306,7 +308,7 @@ func TestOutputResult(t *testing.T) {
306308
args: args{
307309
model: fixtureInputModel(),
308310
projectLabel: "my-project",
309-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
311+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
310312
},
311313
wantErr: false,
312314
},
@@ -317,7 +319,7 @@ func TestOutputResult(t *testing.T) {
317319
model.Async = true
318320
}),
319321
projectLabel: "my-project",
320-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
322+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
321323
},
322324
wantErr: false,
323325
},
@@ -327,7 +329,7 @@ func TestOutputResult(t *testing.T) {
327329
model: fixtureInputModel(func(model *inputModel) {
328330
model.OutputFormat = print.JSONOutputFormat
329331
}),
330-
resp: &intake.IntakeResponse{Id: utils.Ptr("intake-id-123")},
332+
resp: &intake.IntakeResponse{Id: "intake-id-123"},
331333
},
332334
wantErr: false,
333335
},

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

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

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

1210
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1311
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -18,6 +16,7 @@ import (
1816
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1917
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
2018
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
2120
)
2221

2322
const (
@@ -70,7 +69,7 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
7069
// Wait for async operation, if async mode not enabled
7170
if !model.Async {
7271
err := spinner.Run(p.Printer, "Deleting STACKIT Intake instance", func() error {
73-
_, 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)
7473
return err
7574
})
7675
if err != nil {
@@ -110,6 +109,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
110109

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

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ 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/intake"
11-
1210
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1311
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
12+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1413
)
1514

1615
// Define a unique key for the context to avoid collisions
@@ -24,7 +23,9 @@ var (
2423
// testCtx is a dummy context for testing purposes
2524
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2625
// testClient is a mock API client
27-
testClient = &intake.APIClient{}
26+
testClient = &intake.APIClient{
27+
DefaultAPI: &intake.DefaultAPIService{},
28+
}
2829
testProjectId = uuid.NewString()
2930
testIntakeId = uuid.NewString()
3031
)
@@ -70,7 +71,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
7071

7172
// fixtureRequest generates an API request for tests
7273
func fixtureRequest(mods ...func(request *intake.ApiDeleteIntakeRequest)) intake.ApiDeleteIntakeRequest {
73-
request := testClient.DeleteIntake(testCtx, testProjectId, testRegion, testIntakeId)
74+
request := testClient.DefaultAPI.DeleteIntake(testCtx, testProjectId, testRegion, testIntakeId)
7475
for _, mod := range mods {
7576
mod(&request)
7677
}
@@ -147,6 +148,7 @@ func TestBuildRequest(t *testing.T) {
147148
diff := cmp.Diff(request, tt.expectedRequest,
148149
cmp.AllowUnexported(tt.expectedRequest),
149150
cmpopts.EquateComparable(testCtx),
151+
cmpopts.EquateComparable(testClient.DefaultAPI),
150152
)
151153
if diff != "" {
152154
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ 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/intake"
11-
1210
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1311
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1412
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1513
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
14+
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
1615
)
1716

1817
type testCtxKey struct{}
@@ -22,8 +21,10 @@ const (
2221
)
2322

2423
var (
25-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
26-
testClient = &intake.APIClient{}
24+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25+
testClient = &intake.APIClient{
26+
DefaultAPI: &intake.DefaultAPIService{},
27+
}
2728
testProjectId = uuid.NewString()
2829
testIntakeId = uuid.NewString()
2930
)
@@ -65,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6566
}
6667

6768
func fixtureRequest(mods ...func(request *intake.ApiGetIntakeRequest)) intake.ApiGetIntakeRequest {
68-
request := testClient.GetIntake(testCtx, testProjectId, testRegion, testIntakeId)
69+
request := testClient.DefaultAPI.GetIntake(testCtx, testProjectId, testRegion, testIntakeId)
6970
for _, mod := range mods {
7071
mod(&request)
7172
}
@@ -142,6 +143,7 @@ func TestBuildRequest(t *testing.T) {
142143
diff := cmp.Diff(request, tt.expectedRequest,
143144
cmp.AllowUnexported(tt.expectedRequest),
144145
cmpopts.EquateComparable(testCtx),
146+
cmpopts.EquateComparable(testClient.DefaultAPI),
145147
)
146148
if diff != "" {
147149
t.Fatalf("Data does not match: %s", diff)
@@ -162,17 +164,17 @@ func TestOutputResult(t *testing.T) {
162164
}{
163165
{
164166
name: "default output",
165-
args: args{outputFormat: "default", intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
167+
args: args{outputFormat: "default", intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
166168
wantErr: false,
167169
},
168170
{
169171
name: "json output",
170-
args: args{outputFormat: print.JSONOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
172+
args: args{outputFormat: print.JSONOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
171173
wantErr: false,
172174
},
173175
{
174176
name: "yaml output",
175-
args: args{outputFormat: print.YAMLOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: &intake.IntakeCatalog{}}},
177+
args: args{outputFormat: print.YAMLOutputFormat, intakeResp: &intake.IntakeResponse{Catalog: intake.IntakeCatalog{}}},
176178
wantErr: false,
177179
},
178180
{

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)