From 28b1c79a36fdfe2f27b29dd09ad05bb61a6a726d Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Wed, 25 Mar 2026 13:44:42 +0100 Subject: [PATCH] chore(objectstorage): migrate to new SDK structure relates to STACKITCLI-369 --- go.mod | 4 +- go.sum | 8 +- .../object-storage/bucket/create/create.go | 10 +- .../bucket/create/create_test.go | 8 +- .../object-storage/bucket/delete/delete.go | 8 +- .../bucket/delete/delete_test.go | 8 +- .../bucket/describe/describe.go | 23 ++- .../bucket/describe/describe_test.go | 16 +- .../cmd/object-storage/bucket/list/list.go | 13 +- .../object-storage/bucket/list/list_test.go | 8 +- .../credentials-group/create/create.go | 24 ++- .../credentials-group/create/create_test.go | 22 +-- .../credentials-group/delete/delete.go | 6 +- .../credentials-group/delete/delete_test.go | 8 +- .../credentials-group/list/list.go | 11 +- .../credentials-group/list/list_test.go | 8 +- .../credentials/create/create.go | 15 +- .../credentials/create/create_test.go | 8 +- .../credentials/delete/delete.go | 8 +- .../credentials/delete/delete_test.go | 8 +- .../object-storage/credentials/list/list.go | 14 +- .../credentials/list/list_test.go | 8 +- .../cmd/object-storage/disable/disable.go | 4 +- .../object-storage/disable/disable_test.go | 8 +- internal/cmd/object-storage/enable/enable.go | 4 +- .../cmd/object-storage/enable/enable_test.go | 8 +- .../services/object-storage/client/client.go | 4 +- .../services/object-storage/utils/utils.go | 30 ++- .../object-storage/utils/utils_test.go | 184 +++++++----------- 29 files changed, 217 insertions(+), 271 deletions(-) diff --git a/go.mod b/go.mod index 3eeeb67c5..8d49310e1 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 - github.com/stackitcloud/stackit-sdk-go/core v0.22.0 + github.com/stackitcloud/stackit-sdk-go/core v0.23.0 github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0 @@ -269,7 +269,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.8.0 github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.6 github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6 - github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.4.5 + github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0 github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 diff --git a/go.sum b/go.sum index 9f1896727..ad605a10d 100644 --- a/go.sum +++ b/go.sum @@ -596,8 +596,8 @@ github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YEwQ0= github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I= -github.com/stackitcloud/stackit-sdk-go/core v0.22.0 h1:6rViz7GnNwXSh51Lur5xuDzO8EWSZfN9J0HvEkBKq6c= -github.com/stackitcloud/stackit-sdk-go/core v0.22.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= +github.com/stackitcloud/stackit-sdk-go/core v0.23.0 h1:zPrOhf3Xe47rKRs1fg/AqKYUiJJRYjdcv+3qsS50mEs= +github.com/stackitcloud/stackit-sdk-go/core v0.23.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 h1:V9+885qkSv621rZZatg1YE5ENM1ElALxQDJsh+hDIUg= github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8= github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8= @@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6 h1:Y/byRjX2u/OZl github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6/go.mod h1:sY66ZgCgBc1mScPV95ek5WtUEGYizdP1RMsGaqbdbhw= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8 h1:S7t4wcT6SN8ZzdoY8d6VbF903zFpGjzqrU0FN27rJPg= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8/go.mod h1:CdrhFUsBO7/iJleCc2yQjDChIbG6YaxKNBQRNCjgcF4= -github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.4.5 h1:4gpvB6t7d2lLjInoTxcvjL9jCpBl5EDfYe5yUtR1MvA= -github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.4.5/go.mod h1:Bdcd59sRySyhfSUCy+5BNkp5w9PECmrywdvt+ORMKnI= +github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0 h1:UxnbsKm6PQV8Gudw/EhySaEh9q1xSaTG8mzJz1EvhnE= +github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0/go.mod h1:RFL4h6JZvpsyFYbdJ3+eINEkletzJQTfrPdd+yPT/fU= github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 h1:LGwCvvST0fwUgZ6bOxYIfu45qqTgv421ZS07UhKjZL8= github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0/go.mod h1:9KdrXC5JS30Ay3mR0adb3vNdhca+qxiy/cPF5P4wehQ= github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6 h1:oTVx1+O177Ojn8OvXIOUbRSwtx7L59jhxDPrZEQFOfQ= diff --git a/internal/cmd/object-storage/bucket/create/create.go b/internal/cmd/object-storage/bucket/create/create.go index 9b8aae9a3..b0a387572 100644 --- a/internal/cmd/object-storage/bucket/create/create.go +++ b/internal/cmd/object-storage/bucket/create/create.go @@ -16,8 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/wait" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api/wait" ) const ( @@ -60,7 +60,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Check if the project is enabled before trying to create - enabled, err := utils.ProjectEnabled(ctx, apiClient, model.ProjectId, model.Region) + enabled, err := utils.ProjectEnabled(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region) if err != nil { return fmt.Errorf("check if Object Storage is enabled: %w", err) } @@ -81,7 +81,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Creating bucket") - _, err = wait.CreateBucketWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) + _, err = wait.CreateBucketWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for Object Storage bucket creation: %w", err) } @@ -112,7 +112,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateBucketRequest { - req := apiClient.CreateBucket(ctx, model.ProjectId, model.Region, model.BucketName) + req := apiClient.DefaultAPI.CreateBucket(ctx, model.ProjectId, model.Region, model.BucketName) return req } diff --git a/internal/cmd/object-storage/bucket/create/create_test.go b/internal/cmd/object-storage/bucket/create/create_test.go index da4fcb9cf..905677814 100644 --- a/internal/cmd/object-storage/bucket/create/create_test.go +++ b/internal/cmd/object-storage/bucket/create/create_test.go @@ -13,13 +13,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const ( @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateBucketRequest)) objectstorage.ApiCreateBucketRequest { - request := testClient.CreateBucket(testCtx, testProjectId, testRegion, testBucketName) + request := testClient.DefaultAPI.CreateBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/bucket/delete/delete.go b/internal/cmd/object-storage/bucket/delete/delete.go index c06e88718..99a82da85 100644 --- a/internal/cmd/object-storage/bucket/delete/delete.go +++ b/internal/cmd/object-storage/bucket/delete/delete.go @@ -15,8 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/wait" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api/wait" ) const ( @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { s := spinner.New(params.Printer) s.Start("Deleting bucket") - _, err = wait.DeleteBucketWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) + _, err = wait.DeleteBucketWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for Object Storage bucket deletion: %w", err) } @@ -105,6 +105,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiDeleteBucketRequest { - req := apiClient.DeleteBucket(ctx, model.ProjectId, model.Region, model.BucketName) + req := apiClient.DefaultAPI.DeleteBucket(ctx, model.ProjectId, model.Region, model.BucketName) return req } diff --git a/internal/cmd/object-storage/bucket/delete/delete_test.go b/internal/cmd/object-storage/bucket/delete/delete_test.go index 829c374cf..2bc6f06be 100644 --- a/internal/cmd/object-storage/bucket/delete/delete_test.go +++ b/internal/cmd/object-storage/bucket/delete/delete_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const ( @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteBucketRequest)) objectstorage.ApiDeleteBucketRequest { - request := testClient.DeleteBucket(testCtx, testProjectId, testRegion, testBucketName) + request := testClient.DefaultAPI.DeleteBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } @@ -158,7 +158,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/bucket/describe/describe.go b/internal/cmd/object-storage/bucket/describe/describe.go index a2a3ceedb..de374c8d8 100644 --- a/internal/cmd/object-storage/bucket/describe/describe.go +++ b/internal/cmd/object-storage/bucket/describe/describe.go @@ -13,10 +13,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -61,7 +60,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("read Object Storage bucket: %w", err) } - return outputResult(params.Printer, model.OutputFormat, resp.Bucket) + return outputResult(params.Printer, model.OutputFormat, resp) }, } return cmd @@ -85,24 +84,24 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiGetBucketRequest { - req := apiClient.GetBucket(ctx, model.ProjectId, model.Region, model.BucketName) + req := apiClient.DefaultAPI.GetBucket(ctx, model.ProjectId, model.Region, model.BucketName) return req } -func outputResult(p *print.Printer, outputFormat string, bucket *objectstorage.Bucket) error { - if bucket == nil { - return fmt.Errorf("bucket is empty") +func outputResult(p *print.Printer, outputFormat string, resp *objectstorage.GetBucketResponse) error { + if resp == nil { + return fmt.Errorf("response is nil") } - return p.OutputResult(outputFormat, bucket, func() error { + return p.OutputResult(outputFormat, resp.Bucket, func() error { table := tables.NewTable() - table.AddRow("Name", utils.PtrString(bucket.Name)) + table.AddRow("Name", resp.Bucket.Name) table.AddSeparator() - table.AddRow("Region", utils.PtrString(bucket.Region)) + table.AddRow("Region", resp.Bucket.Region) table.AddSeparator() - table.AddRow("URL (Path Style)", utils.PtrString(bucket.UrlPathStyle)) + table.AddRow("URL (Path Style)", resp.Bucket.UrlPathStyle) table.AddSeparator() - table.AddRow("URL (Virtual Hosted Style)", utils.PtrString(bucket.UrlVirtualHostedStyle)) + table.AddRow("URL (Virtual Hosted Style)", resp.Bucket.UrlVirtualHostedStyle) table.AddSeparator() err := table.Display(p) if err != nil { diff --git a/internal/cmd/object-storage/bucket/describe/describe_test.go b/internal/cmd/object-storage/bucket/describe/describe_test.go index 106844ed2..86deeef89 100644 --- a/internal/cmd/object-storage/bucket/describe/describe_test.go +++ b/internal/cmd/object-storage/bucket/describe/describe_test.go @@ -13,13 +13,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const ( @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiGetBucketRequest)) objectstorage.ApiGetBucketRequest { - request := testClient.GetBucket(testCtx, testProjectId, testRegion, testBucketName) + request := testClient.DefaultAPI.GetBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -174,7 +174,7 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { type args struct { outputFormat string - bucket *objectstorage.Bucket + resp *objectstorage.GetBucketResponse } tests := []struct { name string @@ -187,9 +187,9 @@ func TestOutputResult(t *testing.T) { wantErr: true, }, { - name: "set empty bucket", + name: "set empty response", args: args{ - bucket: &objectstorage.Bucket{}, + resp: &objectstorage.GetBucketResponse{}, }, wantErr: false, }, @@ -198,7 +198,7 @@ func TestOutputResult(t *testing.T) { p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(p, tt.args.outputFormat, tt.args.bucket); (err != nil) != tt.wantErr { + if err := outputResult(p, tt.args.outputFormat, tt.args.resp); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/object-storage/bucket/list/list.go b/internal/cmd/object-storage/bucket/list/list.go index ff01c60d6..e26c926e5 100644 --- a/internal/cmd/object-storage/bucket/list/list.go +++ b/internal/cmd/object-storage/bucket/list/list.go @@ -16,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -114,7 +113,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListBucketsRequest { - req := apiClient.ListBuckets(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListBuckets(ctx, model.ProjectId, model.Region) return req } @@ -134,10 +133,10 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, buckets [ for i := range buckets { bucket := buckets[i] table.AddRow( - utils.PtrString(bucket.Name), - utils.PtrString(bucket.Region), - utils.PtrString(bucket.UrlPathStyle), - utils.PtrString(bucket.UrlVirtualHostedStyle), + bucket.Name, + bucket.Region, + bucket.UrlPathStyle, + bucket.UrlVirtualHostedStyle, ) } err := table.Display(p) diff --git a/internal/cmd/object-storage/bucket/list/list_test.go b/internal/cmd/object-storage/bucket/list/list_test.go index 47be7605e..c2916bfb3 100644 --- a/internal/cmd/object-storage/bucket/list/list_test.go +++ b/internal/cmd/object-storage/bucket/list/list_test.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() var testRegion = "eu01" @@ -52,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListBucketsRequest)) objectstorage.ApiListBucketsRequest { - request := testClient.ListBuckets(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListBuckets(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -140,7 +140,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/credentials-group/create/create.go b/internal/cmd/object-storage/credentials-group/create/create.go index 9150b98fe..1b6651444 100644 --- a/internal/cmd/object-storage/credentials-group/create/create.go +++ b/internal/cmd/object-storage/credentials-group/create/create.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -13,10 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - - "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -95,24 +93,24 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateCredentialsGroupRequest { - req := apiClient.CreateCredentialsGroup(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateCredentialsGroup(ctx, model.ProjectId, model.Region) req = req.CreateCredentialsGroupPayload(objectstorage.CreateCredentialsGroupPayload{ - DisplayName: utils.Ptr(model.CredentialsGroupName), + DisplayName: model.CredentialsGroupName, }) return req } func outputResult(p *print.Printer, outputFormat string, resp *objectstorage.CreateCredentialsGroupResponse) error { - if resp == nil || resp.CredentialsGroup == nil { - return fmt.Errorf("create createndials group response is empty") - } - return p.OutputResult(outputFormat, resp, func() error { + if resp == nil { + return fmt.Errorf("create credentials group response is empty") + } + p.Outputf("Created credentials group %q. Credentials group ID: %s\n\n", - utils.PtrString(resp.CredentialsGroup.DisplayName), - utils.PtrString(resp.CredentialsGroup.CredentialsGroupId), + resp.CredentialsGroup.DisplayName, + resp.CredentialsGroup.CredentialsGroupId, ) - p.Outputf("URN: %s\n", utils.PtrString(resp.CredentialsGroup.Urn)) + p.Outputf("URN: %s\n", resp.CredentialsGroup.Urn) return nil }) } diff --git a/internal/cmd/object-storage/credentials-group/create/create_test.go b/internal/cmd/object-storage/credentials-group/create/create_test.go index 2823fc5da..1b3fc9216 100644 --- a/internal/cmd/object-storage/credentials-group/create/create_test.go +++ b/internal/cmd/object-storage/credentials-group/create/create_test.go @@ -6,21 +6,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" + "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const ( @@ -57,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { func fixturePayload(mods ...func(payload *objectstorage.CreateCredentialsGroupPayload)) objectstorage.CreateCredentialsGroupPayload { payload := objectstorage.CreateCredentialsGroupPayload{ - DisplayName: utils.Ptr(testCredentialsGroupName), + DisplayName: testCredentialsGroupName, } for _, mod := range mods { mod(&payload) @@ -66,7 +64,7 @@ func fixturePayload(mods ...func(payload *objectstorage.CreateCredentialsGroupPa } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateCredentialsGroupRequest)) objectstorage.ApiCreateCredentialsGroupRequest { - request := testClient.CreateCredentialsGroup(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateCredentialsGroup(testCtx, testProjectId, testRegion) request = request.CreateCredentialsGroupPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -148,7 +146,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -178,13 +176,13 @@ func TestOutputResult(t *testing.T) { args: args{ createCredentialsGroupResponse: &objectstorage.CreateCredentialsGroupResponse{}, }, - wantErr: true, + wantErr: false, }, { name: "set create credentials group response", args: args{ createCredentialsGroupResponse: &objectstorage.CreateCredentialsGroupResponse{ - CredentialsGroup: &objectstorage.CredentialsGroup{}, + CredentialsGroup: objectstorage.CredentialsGroup{}, }, }, wantErr: false, diff --git a/internal/cmd/object-storage/credentials-group/delete/delete.go b/internal/cmd/object-storage/credentials-group/delete/delete.go index 79daa26b3..ac14221e1 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete.go @@ -16,7 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -52,7 +52,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { params.Printer.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -96,6 +96,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiDeleteCredentialsGroupRequest { - req := apiClient.DeleteCredentialsGroup(ctx, model.ProjectId, model.Region, model.CredentialsGroupId) + req := apiClient.DefaultAPI.DeleteCredentialsGroup(ctx, model.ProjectId, model.Region, model.CredentialsGroupId) return req } diff --git a/internal/cmd/object-storage/credentials-group/delete/delete_test.go b/internal/cmd/object-storage/credentials-group/delete/delete_test.go index 9be471b32..e2c2e33d1 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteCredentialsGroupRequest)) objectstorage.ApiDeleteCredentialsGroupRequest { - request := testClient.DeleteCredentialsGroup(testCtx, testProjectId, testRegion, testCredentialsGroupId) + request := testClient.DefaultAPI.DeleteCredentialsGroup(testCtx, testProjectId, testRegion, testCredentialsGroupId) for _, mod := range mods { mod(&request) } @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/credentials-group/list/list.go b/internal/cmd/object-storage/credentials-group/list/list.go index f422ad6d3..153a9b25f 100644 --- a/internal/cmd/object-storage/credentials-group/list/list.go +++ b/internal/cmd/object-storage/credentials-group/list/list.go @@ -15,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -105,7 +104,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListCredentialsGroupsRequest { - req := apiClient.ListCredentialsGroups(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListCredentialsGroups(ctx, model.ProjectId, model.Region) return req } @@ -121,9 +120,9 @@ func outputResult(p *print.Printer, outputFormat string, credentialsGroups []obj for i := range credentialsGroups { c := credentialsGroups[i] table.AddRow( - utils.PtrString(c.CredentialsGroupId), - utils.PtrString(c.DisplayName), - utils.PtrString(c.Urn), + c.CredentialsGroupId, + c.DisplayName, + c.Urn, ) } err := table.Display(p) diff --git a/internal/cmd/object-storage/credentials-group/list/list_test.go b/internal/cmd/object-storage/credentials-group/list/list_test.go index cbbbb1a89..520a0e011 100644 --- a/internal/cmd/object-storage/credentials-group/list/list_test.go +++ b/internal/cmd/object-storage/credentials-group/list/list_test.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const testRegion = "eu01" @@ -53,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListCredentialsGroupsRequest)) objectstorage.ApiListCredentialsGroupsRequest { - request := testClient.ListCredentialsGroups(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListCredentialsGroups(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -141,7 +141,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/credentials/create/create.go b/internal/cmd/object-storage/credentials/create/create.go index c970dcb21..4f4861b8f 100644 --- a/internal/cmd/object-storage/credentials/create/create.go +++ b/internal/cmd/object-storage/credentials/create/create.go @@ -16,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -60,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { params.Printer.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -119,7 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateAccessKeyRequest { - req := apiClient.CreateAccessKey(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateAccessKey(ctx, model.ProjectId, model.Region) req = req.CredentialsGroup(model.CredentialsGroupId) req = req.CreateAccessKeyPayload(objectstorage.CreateAccessKeyPayload{ Expires: model.ExpireDate, @@ -134,13 +133,13 @@ func outputResult(p *print.Printer, outputFormat, credentialsGroupLabel string, return p.OutputResult(outputFormat, resp, func() error { expireDate := "Never" - if resp.Expires != nil && resp.Expires.IsSet() && *resp.Expires.Get() != "" { + if resp.Expires.IsSet() && *resp.Expires.Get() != "" { expireDate = *resp.Expires.Get() } - p.Outputf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, utils.PtrString(resp.KeyId)) - p.Outputf("Access Key ID: %s\n", utils.PtrString(resp.AccessKey)) - p.Outputf("Secret Access Key: %s\n", utils.PtrString(resp.SecretAccessKey)) + p.Outputf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, resp.KeyId) + p.Outputf("Access Key ID: %s\n", resp.AccessKey) + p.Outputf("Secret Access Key: %s\n", resp.SecretAccessKey) p.Outputf("Expire Date: %s\n", expireDate) return nil diff --git a/internal/cmd/object-storage/credentials/create/create_test.go b/internal/cmd/object-storage/credentials/create/create_test.go index 46f0e2e18..c960ddd49 100644 --- a/internal/cmd/object-storage/credentials/create/create_test.go +++ b/internal/cmd/object-storage/credentials/create/create_test.go @@ -15,13 +15,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() @@ -79,7 +79,7 @@ func fixturePayload(mods ...func(payload *objectstorage.CreateAccessKeyPayload)) } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateAccessKeyRequest)) objectstorage.ApiCreateAccessKeyRequest { - request := testClient.CreateAccessKey(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateAccessKey(testCtx, testProjectId, testRegion) request = request.CreateAccessKeyPayload(fixturePayload()) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { @@ -207,7 +207,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/credentials/delete/delete.go b/internal/cmd/object-storage/credentials/delete/delete.go index 84a3b363b..99307dca1 100644 --- a/internal/cmd/object-storage/credentials/delete/delete.go +++ b/internal/cmd/object-storage/credentials/delete/delete.go @@ -15,7 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -53,13 +53,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { params.Printer.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId } - credentialsLabel, err := objectStorageUtils.GetCredentialsName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.CredentialsId, model.Region) + credentialsLabel, err := objectStorageUtils.GetCredentialsName(ctx, apiClient.DefaultAPI, model.ProjectId, model.CredentialsGroupId, model.CredentialsId, model.Region) if err != nil { params.Printer.Debug(print.ErrorLevel, "get credentials name: %v", err) credentialsLabel = model.CredentialsId @@ -112,7 +112,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiDeleteAccessKeyRequest { - req := apiClient.DeleteAccessKey(ctx, model.ProjectId, model.Region, model.CredentialsId) + req := apiClient.DefaultAPI.DeleteAccessKey(ctx, model.ProjectId, model.Region, model.CredentialsId) req = req.CredentialsGroup(model.CredentialsGroupId) return req } diff --git a/internal/cmd/object-storage/credentials/delete/delete_test.go b/internal/cmd/object-storage/credentials/delete/delete_test.go index 699d36bcf..12be8797a 100644 --- a/internal/cmd/object-storage/credentials/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials/delete/delete_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteAccessKeyRequest)) objectstorage.ApiDeleteAccessKeyRequest { - request := testClient.DeleteAccessKey(testCtx, testProjectId, testRegion, testCredentialsId) + request := testClient.DefaultAPI.DeleteAccessKey(testCtx, testProjectId, testRegion, testCredentialsId) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { mod(&request) @@ -183,7 +183,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/credentials/list/list.go b/internal/cmd/object-storage/credentials/list/list.go index f1ef8c155..73aa91dca 100644 --- a/internal/cmd/object-storage/credentials/list/list.go +++ b/internal/cmd/object-storage/credentials/list/list.go @@ -16,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) const ( @@ -69,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } credentials := resp.GetAccessKeys() - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { params.Printer.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -119,7 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListAccessKeysRequest { - req := apiClient.ListAccessKeys(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListAccessKeys(ctx, model.ProjectId, model.Region) req = req.CredentialsGroup(model.CredentialsGroupId) return req } @@ -136,8 +135,11 @@ func outputResult(p *print.Printer, outputFormat, credentialsGroupLabel string, for i := range credentials { c := credentials[i] - expiresAt := utils.PtrStringDefault(c.Expires, "Never") - table.AddRow(utils.PtrString(c.KeyId), utils.PtrString(c.DisplayName), expiresAt) + expiresAt := "Never" + if c.Expires != "" { + expiresAt = c.Expires + } + table.AddRow(c.KeyId, c.DisplayName, expiresAt) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/object-storage/credentials/list/list_test.go b/internal/cmd/object-storage/credentials/list/list_test.go index ba6967c84..b950ac36a 100644 --- a/internal/cmd/object-storage/credentials/list/list_test.go +++ b/internal/cmd/object-storage/credentials/list/list_test.go @@ -14,13 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() var testRegion = "eu01" @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListAccessKeysRequest)) objectstorage.ApiListAccessKeysRequest { - request := testClient.ListAccessKeys(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListAccessKeys(testCtx, testProjectId, testRegion) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { mod(&request) @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/disable/disable.go b/internal/cmd/object-storage/disable/disable.go index e7b0f501b..22eba8a93 100644 --- a/internal/cmd/object-storage/disable/disable.go +++ b/internal/cmd/object-storage/disable/disable.go @@ -15,7 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type inputModel struct { @@ -91,6 +91,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiDisableServiceRequest { - req := apiClient.DisableService(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.DisableService(ctx, model.ProjectId, model.Region) return req } diff --git a/internal/cmd/object-storage/disable/disable_test.go b/internal/cmd/object-storage/disable/disable_test.go index 8820b8cc3..9f6ce3322 100644 --- a/internal/cmd/object-storage/disable/disable_test.go +++ b/internal/cmd/object-storage/disable/disable_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const testRegion = "eu01" @@ -47,7 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDisableServiceRequest)) objectstorage.ApiDisableServiceRequest { - request := testClient.DisableService(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.DisableService(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -121,7 +121,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/object-storage/enable/enable.go b/internal/cmd/object-storage/enable/enable.go index bd5304493..0018d56d9 100644 --- a/internal/cmd/object-storage/enable/enable.go +++ b/internal/cmd/object-storage/enable/enable.go @@ -15,7 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type inputModel struct { @@ -91,6 +91,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiEnableServiceRequest { - req := apiClient.EnableService(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.EnableService(ctx, model.ProjectId, model.Region) return req } diff --git a/internal/cmd/object-storage/enable/enable_test.go b/internal/cmd/object-storage/enable/enable_test.go index db8c35d3f..936b2d0f9 100644 --- a/internal/cmd/object-storage/enable/enable_test.go +++ b/internal/cmd/object-storage/enable/enable_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &objectstorage.APIClient{} +var testClient = &objectstorage.APIClient{DefaultAPI: &objectstorage.DefaultAPIService{}} var testProjectId = uuid.NewString() const testRegion = "eu01" @@ -47,7 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiEnableServiceRequest)) objectstorage.ApiEnableServiceRequest { - request := testClient.EnableService(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.EnableService(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -121,7 +121,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, objectstorage.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/pkg/services/object-storage/client/client.go b/internal/pkg/services/object-storage/client/client.go index 82b2447f8..81e5dbe95 100644 --- a/internal/pkg/services/object-storage/client/client.go +++ b/internal/pkg/services/object-storage/client/client.go @@ -6,9 +6,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/viper" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) func ConfigureClient(p *print.Printer, cliVersion string) (*objectstorage.APIClient, error) { - return genericclient.ConfigureClientGeneric(p, cliVersion, viper.GetString(config.ObjectStorageCustomEndpointKey), true, genericclient.CreateApiClient[*objectstorage.APIClient](objectstorage.NewAPIClient)) + return genericclient.ConfigureClientGeneric(p, cliVersion, viper.GetString(config.ObjectStorageCustomEndpointKey), false, genericclient.CreateApiClient[*objectstorage.APIClient](objectstorage.NewAPIClient)) } diff --git a/internal/pkg/services/object-storage/utils/utils.go b/internal/pkg/services/object-storage/utils/utils.go index bd23d0854..a122cb1ef 100644 --- a/internal/pkg/services/object-storage/utils/utils.go +++ b/internal/pkg/services/object-storage/utils/utils.go @@ -6,17 +6,11 @@ import ( "net/http" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) -type ObjectStorageClient interface { - GetServiceStatusExecute(ctx context.Context, projectId, region string) (*objectstorage.ProjectStatus, error) - ListCredentialsGroupsExecute(ctx context.Context, projectId, region string) (*objectstorage.ListCredentialsGroupsResponse, error) - ListAccessKeys(ctx context.Context, projectId, region string) objectstorage.ApiListAccessKeysRequest -} - -func ProjectEnabled(ctx context.Context, apiClient ObjectStorageClient, projectId, region string) (bool, error) { - _, err := apiClient.GetServiceStatusExecute(ctx, projectId, region) +func ProjectEnabled(ctx context.Context, apiClient objectstorage.DefaultAPI, projectId, region string) (bool, error) { + _, err := apiClient.GetServiceStatus(ctx, projectId, region).Execute() if err != nil { oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped if !ok { @@ -30,8 +24,8 @@ func ProjectEnabled(ctx context.Context, apiClient ObjectStorageClient, projectI return true, nil } -func GetCredentialsGroupName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId, region string) (string, error) { - resp, err := apiClient.ListCredentialsGroupsExecute(ctx, projectId, region) +func GetCredentialsGroupName(ctx context.Context, apiClient objectstorage.DefaultAPI, projectId, credentialsGroupId, region string) (string, error) { + resp, err := apiClient.ListCredentialsGroups(ctx, projectId, region).Execute() if err != nil { return "", fmt.Errorf("list Object Storage credentials groups: %w", err) } @@ -41,16 +35,16 @@ func GetCredentialsGroupName(ctx context.Context, apiClient ObjectStorageClient, return "", fmt.Errorf("nil Object Storage credentials group list: %w", err) } - for _, group := range *credentialsGroups { - if group.CredentialsGroupId != nil && *group.CredentialsGroupId == credentialsGroupId && group.DisplayName != nil && *group.DisplayName != "" { - return *group.DisplayName, nil + for _, group := range credentialsGroups { + if group.CredentialsGroupId == credentialsGroupId && group.DisplayName != "" { + return group.DisplayName, nil } } return "", fmt.Errorf("could not find Object Storage credentials group name") } -func GetCredentialsName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId, keyId, region string) (string, error) { +func GetCredentialsName(ctx context.Context, apiClient objectstorage.DefaultAPI, projectId, credentialsGroupId, keyId, region string) (string, error) { req := apiClient.ListAccessKeys(ctx, projectId, region) req = req.CredentialsGroup(credentialsGroupId) resp, err := req.Execute() @@ -64,9 +58,9 @@ func GetCredentialsName(ctx context.Context, apiClient ObjectStorageClient, proj return "", fmt.Errorf("nil Object Storage credentials list") } - for _, credential := range *credentials { - if credential.KeyId != nil && *credential.KeyId == keyId && credential.DisplayName != nil && *credential.DisplayName != "" { - return *credential.DisplayName, nil + for _, credential := range credentials { + if credential.KeyId == keyId && credential.DisplayName != "" { + return credential.DisplayName, nil } } diff --git a/internal/pkg/services/object-storage/utils/utils_test.go b/internal/pkg/services/object-storage/utils/utils_test.go index 65b176172..16c9c6c1b 100644 --- a/internal/pkg/services/object-storage/utils/utils_test.go +++ b/internal/pkg/services/object-storage/utils/utils_test.go @@ -2,59 +2,68 @@ package utils import ( "context" - "encoding/json" "fmt" "net/http" - "net/http/httptest" "testing" "github.com/google/uuid" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" + objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api" ) var ( testProjectId = uuid.NewString() testCredentialsGroupId = uuid.NewString() - testCredentialsId = "credentialsID" //nolint:gosec // linter false positive - testRegion = "eu01" ) const ( testCredentialsGroupName = "testGroup" testCredentialsName = "testCredential" + testCredentialsId = "credentialsID" //nolint:gosec // linter false positive + testRegion = "eu01" ) -type objectStorageClientMocked struct { - serviceDisabled bool - getServiceStatusFails bool +type mockSettings struct { + serviceDisabled bool + getServiceStatusFails bool + listCredentialsGroupsFails bool listCredentialsGroupsResp *objectstorage.ListCredentialsGroupsResponse - listAccessKeysReq objectstorage.ApiListAccessKeysRequest -} -func (m *objectStorageClientMocked) GetServiceStatusExecute(_ context.Context, _, _ string) (*objectstorage.ProjectStatus, error) { - if m.getServiceStatusFails { - return nil, fmt.Errorf("could not get service status") - } - if m.serviceDisabled { - return nil, &oapierror.GenericOpenAPIError{StatusCode: 404} - } - return &objectstorage.ProjectStatus{}, nil + listAccessKeysFails bool + listAccessKeysResp *objectstorage.ListAccessKeysResponse } -func (m *objectStorageClientMocked) ListCredentialsGroupsExecute(_ context.Context, _, _ string) (*objectstorage.ListCredentialsGroupsResponse, error) { - if m.listCredentialsGroupsFails { - return nil, fmt.Errorf("could not list credentials groups") - } - return m.listCredentialsGroupsResp, nil -} +func newAPIMock(settings *mockSettings) objectstorage.DefaultAPI { + return &objectstorage.DefaultAPIServiceMock{ + GetServiceStatusExecuteMock: utils.Ptr(func(_ objectstorage.ApiGetServiceStatusRequest) (*objectstorage.ProjectStatus, error) { + if settings.getServiceStatusFails { + return nil, fmt.Errorf("could not get service status") + } -func (m *objectStorageClientMocked) ListAccessKeys(_ context.Context, _, _ string) objectstorage.ApiListAccessKeysRequest { - return m.listAccessKeysReq + if settings.serviceDisabled { + return nil, &oapierror.GenericOpenAPIError{StatusCode: http.StatusNotFound} + } + + return &objectstorage.ProjectStatus{}, nil + }), + ListCredentialsGroupsExecuteMock: utils.Ptr(func(_ objectstorage.ApiListCredentialsGroupsRequest) (*objectstorage.ListCredentialsGroupsResponse, error) { + if settings.listCredentialsGroupsFails { + return nil, fmt.Errorf("could not list credentials groups") + } + + return settings.listCredentialsGroupsResp, nil + }), + ListAccessKeysExecuteMock: utils.Ptr(func(_ objectstorage.ApiListAccessKeysRequest) (*objectstorage.ListAccessKeysResponse, error) { + if settings.listAccessKeysFails { + return nil, &oapierror.GenericOpenAPIError{StatusCode: http.StatusBadGateway} + } + + return settings.listAccessKeysResp, nil + }), + } } func TestProjectEnabled(t *testing.T) { @@ -85,10 +94,10 @@ func TestProjectEnabled(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &objectStorageClientMocked{ + client := newAPIMock(&mockSettings{ serviceDisabled: tt.serviceDisabled, getServiceStatusFails: tt.getProjectFails, - } + }) output, err := ProjectEnabled(context.Background(), client, testProjectId, testRegion) @@ -120,10 +129,10 @@ func TestGetCredentialsGroupName(t *testing.T) { { description: "base", listCredentialsGroupsResp: &objectstorage.ListCredentialsGroupsResponse{ - CredentialsGroups: &[]objectstorage.CredentialsGroup{ + CredentialsGroups: []objectstorage.CredentialsGroup{ { - CredentialsGroupId: utils.Ptr(testCredentialsGroupId), - DisplayName: utils.Ptr(testCredentialsGroupName), + CredentialsGroupId: testCredentialsGroupId, + DisplayName: testCredentialsGroupName, }, }, }, @@ -138,14 +147,14 @@ func TestGetCredentialsGroupName(t *testing.T) { { description: "multiple credentials groups", listCredentialsGroupsResp: &objectstorage.ListCredentialsGroupsResponse{ - CredentialsGroups: &[]objectstorage.CredentialsGroup{ + CredentialsGroups: []objectstorage.CredentialsGroup{ { - CredentialsGroupId: utils.Ptr("test-UUID"), - DisplayName: utils.Ptr("test-name"), + CredentialsGroupId: "test-UUID", + DisplayName: "test-name", }, { - CredentialsGroupId: utils.Ptr(testCredentialsGroupId), - DisplayName: utils.Ptr(testCredentialsGroupName), + CredentialsGroupId: testCredentialsGroupId, + DisplayName: testCredentialsGroupName, }, }, }, @@ -160,23 +169,11 @@ func TestGetCredentialsGroupName(t *testing.T) { isValid: false, }, { - description: "nil credentials group id", - listCredentialsGroupsResp: &objectstorage.ListCredentialsGroupsResponse{ - CredentialsGroups: &[]objectstorage.CredentialsGroup{ - { - CredentialsGroupId: nil, - }, - }, - }, - isValid: false, - }, - { - description: "nil credentials group name", + description: "empty credentials group id", listCredentialsGroupsResp: &objectstorage.ListCredentialsGroupsResponse{ - CredentialsGroups: &[]objectstorage.CredentialsGroup{ + CredentialsGroups: []objectstorage.CredentialsGroup{ { - CredentialsGroupId: utils.Ptr(testCredentialsGroupId), - DisplayName: nil, + CredentialsGroupId: "", }, }, }, @@ -185,10 +182,10 @@ func TestGetCredentialsGroupName(t *testing.T) { { description: "empty credentials group name", listCredentialsGroupsResp: &objectstorage.ListCredentialsGroupsResponse{ - CredentialsGroups: &[]objectstorage.CredentialsGroup{ + CredentialsGroups: []objectstorage.CredentialsGroup{ { - CredentialsGroupId: utils.Ptr(testCredentialsGroupId), - DisplayName: utils.Ptr(""), + CredentialsGroupId: testCredentialsGroupId, + DisplayName: "", }, }, }, @@ -198,10 +195,10 @@ func TestGetCredentialsGroupName(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &objectStorageClientMocked{ + client := newAPIMock(&mockSettings{ listCredentialsGroupsFails: tt.listCredentialsGroupsFails, listCredentialsGroupsResp: tt.listCredentialsGroupsResp, - } + }) output, err := GetCredentialsGroupName(context.Background(), client, testProjectId, testCredentialsGroupId, testRegion) @@ -232,10 +229,10 @@ func TestGetCredentialsName(t *testing.T) { { description: "base", listAccessKeysResp: &objectstorage.ListAccessKeysResponse{ - AccessKeys: &[]objectstorage.AccessKey{ + AccessKeys: []objectstorage.AccessKey{ { - KeyId: utils.Ptr(testCredentialsId), - DisplayName: utils.Ptr(testCredentialsName), + KeyId: testCredentialsId, + DisplayName: testCredentialsName, }, }, }, @@ -250,14 +247,14 @@ func TestGetCredentialsName(t *testing.T) { { description: "multiple credentials", listAccessKeysResp: &objectstorage.ListAccessKeysResponse{ - AccessKeys: &[]objectstorage.AccessKey{ + AccessKeys: []objectstorage.AccessKey{ { - KeyId: utils.Ptr("test-UUID"), - DisplayName: utils.Ptr("test-name"), + KeyId: "test-UUID", + DisplayName: "test-name", }, { - KeyId: utils.Ptr(testCredentialsId), - DisplayName: utils.Ptr(testCredentialsName), + KeyId: testCredentialsId, + DisplayName: testCredentialsName, }, }, }, @@ -272,23 +269,11 @@ func TestGetCredentialsName(t *testing.T) { isValid: false, }, { - description: "nil credentials id", + description: "empty credentials id", listAccessKeysResp: &objectstorage.ListAccessKeysResponse{ - AccessKeys: &[]objectstorage.AccessKey{ + AccessKeys: []objectstorage.AccessKey{ { - KeyId: nil, - }, - }, - }, - isValid: false, - }, - { - description: "nil credentials name", - listAccessKeysResp: &objectstorage.ListAccessKeysResponse{ - AccessKeys: &[]objectstorage.AccessKey{ - { - KeyId: utils.Ptr(testCredentialsId), - DisplayName: nil, + KeyId: "", }, }, }, @@ -297,10 +282,10 @@ func TestGetCredentialsName(t *testing.T) { { description: "empty credentials name", listAccessKeysResp: &objectstorage.ListAccessKeysResponse{ - AccessKeys: &[]objectstorage.AccessKey{ + AccessKeys: []objectstorage.AccessKey{ { - KeyId: utils.Ptr(testCredentialsId), - DisplayName: utils.Ptr(""), + KeyId: testCredentialsId, + DisplayName: "", }, }, }, @@ -310,37 +295,10 @@ func TestGetCredentialsName(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - mockedRespBytes, err := json.Marshal(tt.listAccessKeysResp) - if err != nil { - t.Fatalf("Failed to marshal mocked response: %v", err) - } - - handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "application/json") - if tt.getCredentialsNameFails { - w.WriteHeader(http.StatusBadGateway) - w.Header().Set("Content-Type", "application/json") - _, err := w.Write([]byte("{\"message\": \"Something bad happened\"")) - if err != nil { - t.Errorf("Failed to write bad response: %v", err) - } - return - } - - _, err := w.Write(mockedRespBytes) - if err != nil { - t.Errorf("Failed to write response: %v", err) - } + client := newAPIMock(&mockSettings{ + listAccessKeysFails: tt.getCredentialsNameFails, + listAccessKeysResp: tt.listAccessKeysResp, }) - mockedServer := httptest.NewServer(handler) - defer mockedServer.Close() - client, err := objectstorage.NewAPIClient( - config.WithEndpoint(mockedServer.URL), - config.WithoutAuthentication(), - ) - if err != nil { - t.Fatalf("Failed to initialize client: %v", err) - } output, err := GetCredentialsName(context.Background(), client, testProjectId, testCredentialsGroupId, testCredentialsId, testRegion)