diff --git a/go.mod b/go.mod index c00bae78b..628cc018c 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v0.17.0 github.com/stackitcloud/stackit-sdk-go/services/logme v0.20.2 github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.20.1 - github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.11.1 + github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.0.0 github.com/stackitcloud/stackit-sdk-go/services/observability v0.2.1 github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.20.1 github.com/stackitcloud/stackit-sdk-go/services/redis v0.20.1 diff --git a/go.sum b/go.sum index 75b404731..389b7e76d 100644 --- a/go.sum +++ b/go.sum @@ -136,6 +136,8 @@ github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.17.0 h1:SXNkKaAsG github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.17.0/go.mod h1:5hMtm08NrL+QcgKl94zUDrY7VEzKRcvCJOEOvENBxqc= github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.11.1 h1:Df3fTAHaVgyiiyp9LyTTQI8jXSVeGo49eW5ya4AATCY= github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.11.1/go.mod h1:V2LEHKyTaaiEBi9L3v62mNQ7xyJSred4OK+himLJOZQ= +github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.0.0 h1:/0n2zcH1nMw2noroGhz0fgu2YqtNo9v3AsVhXMRtmtw= +github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.0.0/go.mod h1:0XumGX33DT6ItyD8yMlogSPWvpIuoqN7RZBrpUBPX+k= github.com/stackitcloud/stackit-sdk-go/services/observability v0.2.1 h1:sIz4wJIz6/9Eh6nSoi2sQ+Ef53iOrFsqLKIp2oRkmgo= github.com/stackitcloud/stackit-sdk-go/services/observability v0.2.1/go.mod h1:okcRTrNDTI3d7MQcYJMliK0qoXeLq0b1wvZuEqgJIWE= github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.19.1 h1:hwRkCCUSWMhKTc7fLakL89V6+9xkxsFQlRthVmrvi1U= diff --git a/internal/cmd/object-storage/bucket/create/create.go b/internal/cmd/object-storage/bucket/create/create.go index 9e030b954..99f5f6003 100644 --- a/internal/cmd/object-storage/bucket/create/create.go +++ b/internal/cmd/object-storage/bucket/create/create.go @@ -62,7 +62,7 @@ func NewCmd(p *print.Printer) *cobra.Command { } // Check if the project is enabled before trying to create - enabled, err := utils.ProjectEnabled(ctx, apiClient, model.ProjectId) + enabled, err := utils.ProjectEnabled(ctx, apiClient, model.ProjectId, model.Region) if err != nil { return fmt.Errorf("check if Object Storage is enabled: %w", err) } @@ -83,7 +83,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if !model.Async { s := spinner.New(p) s.Start("Creating bucket") - _, err = wait.CreateBucketWaitHandler(ctx, apiClient, model.ProjectId, model.BucketName).WaitWithContext(ctx) + _, err = wait.CreateBucketWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for Object Storage bucket creation: %w", err) } @@ -122,7 +122,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.BucketName) + req := apiClient.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 1e53ed260..42a2bf0a5 100644 --- a/internal/cmd/object-storage/bucket/create/create_test.go +++ b/internal/cmd/object-storage/bucket/create/create_test.go @@ -14,12 +14,14 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" var testBucketName = "my-bucket" func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -35,6 +37,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -47,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, BucketName: testBucketName, } @@ -57,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateBucketRequest)) objectstorage.ApiCreateBucketRequest { - request := testClient.CreateBucket(testCtx, testProjectId, testBucketName) + request := testClient.CreateBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/bucket/delete/delete.go b/internal/cmd/object-storage/bucket/delete/delete.go index 359fcef99..1c6edbf90 100644 --- a/internal/cmd/object-storage/bucket/delete/delete.go +++ b/internal/cmd/object-storage/bucket/delete/delete.go @@ -69,7 +69,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if !model.Async { s := spinner.New(p) s.Start("Deleting bucket") - _, err = wait.DeleteBucketWaitHandler(ctx, apiClient, model.ProjectId, model.BucketName).WaitWithContext(ctx) + _, err = wait.DeleteBucketWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BucketName).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait for Object Storage bucket deletion: %w", err) } @@ -113,6 +113,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.BucketName) + req := apiClient.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 1379397ea..be5bd0028 100644 --- a/internal/cmd/object-storage/bucket/delete/delete_test.go +++ b/internal/cmd/object-storage/bucket/delete/delete_test.go @@ -14,12 +14,14 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" var testBucketName = "my-bucket" func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -35,6 +37,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -47,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, BucketName: testBucketName, } @@ -57,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteBucketRequest)) objectstorage.ApiDeleteBucketRequest { - request := testClient.DeleteBucket(testCtx, testProjectId, testBucketName) + request := testClient.DeleteBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/bucket/describe/describe.go b/internal/cmd/object-storage/bucket/describe/describe.go index f23a2fc85..3f57cc001 100644 --- a/internal/cmd/object-storage/bucket/describe/describe.go +++ b/internal/cmd/object-storage/bucket/describe/describe.go @@ -93,7 +93,7 @@ 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.BucketName) + req := apiClient.GetBucket(ctx, model.ProjectId, model.Region, model.BucketName) return req } diff --git a/internal/cmd/object-storage/bucket/describe/describe_test.go b/internal/cmd/object-storage/bucket/describe/describe_test.go index 8ba16b48f..ec6702dae 100644 --- a/internal/cmd/object-storage/bucket/describe/describe_test.go +++ b/internal/cmd/object-storage/bucket/describe/describe_test.go @@ -14,12 +14,14 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" var testBucketName = "my-bucket" func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -35,6 +37,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -47,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, BucketName: testBucketName, } @@ -57,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiGetBucketRequest)) objectstorage.ApiGetBucketRequest { - request := testClient.GetBucket(testCtx, testProjectId, testBucketName) + request := testClient.GetBucket(testCtx, testProjectId, testRegion, testBucketName) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/bucket/list/list.go b/internal/cmd/object-storage/bucket/list/list.go index d9409ff45..e454b6b3c 100644 --- a/internal/cmd/object-storage/bucket/list/list.go +++ b/internal/cmd/object-storage/bucket/list/list.go @@ -125,7 +125,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListBucketsRequest { - req := apiClient.ListBuckets(ctx, model.ProjectId) + req := apiClient.ListBuckets(ctx, model.ProjectId, model.Region) return req } diff --git a/internal/cmd/object-storage/bucket/list/list_test.go b/internal/cmd/object-storage/bucket/list/list_test.go index 35d34ab64..8f4d655bb 100644 --- a/internal/cmd/object-storage/bucket/list/list_test.go +++ b/internal/cmd/object-storage/bucket/list/list_test.go @@ -16,17 +16,20 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, limitFlag: "10", + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -39,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, Limit: utils.Ptr(int64(10)), } @@ -49,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListBucketsRequest)) objectstorage.ApiListBucketsRequest { - request := testClient.ListBuckets(testCtx, testProjectId) + request := testClient.ListBuckets(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/credentials-group/create/create.go b/internal/cmd/object-storage/credentials-group/create/create.go index 9a611b5b3..954fc6192 100644 --- a/internal/cmd/object-storage/credentials-group/create/create.go +++ b/internal/cmd/object-storage/credentials-group/create/create.go @@ -105,7 +105,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateCredentialsGroupRequest { - req := apiClient.CreateCredentialsGroup(ctx, model.ProjectId) + req := apiClient.CreateCredentialsGroup(ctx, model.ProjectId, model.Region) req = req.CreateCredentialsGroupPayload(objectstorage.CreateCredentialsGroupPayload{ DisplayName: utils.Ptr(model.CredentialsGroupName), }) 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 88c212867..f7b1a447b 100644 --- a/internal/cmd/object-storage/credentials-group/create/create_test.go +++ b/internal/cmd/object-storage/credentials-group/create/create_test.go @@ -15,6 +15,7 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} @@ -22,11 +23,13 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() var testCredentialsGroupName = "test-name" +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, credentialsGroupNameFlag: testCredentialsGroupName, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -39,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, CredentialsGroupName: testCredentialsGroupName, } @@ -59,7 +63,7 @@ func fixturePayload(mods ...func(payload *objectstorage.CreateCredentialsGroupPa } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateCredentialsGroupRequest)) objectstorage.ApiCreateCredentialsGroupRequest { - request := testClient.CreateCredentialsGroup(testCtx, testProjectId) + request := testClient.CreateCredentialsGroup(testCtx, testProjectId, testRegion) request = request.CreateCredentialsGroupPayload(fixturePayload()) for _, mod := range mods { mod(&request) diff --git a/internal/cmd/object-storage/credentials-group/delete/delete.go b/internal/cmd/object-storage/credentials-group/delete/delete.go index 4f64600fb..27dda8460 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete.go @@ -50,7 +50,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -104,6 +104,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.CredentialsGroupId) + req := apiClient.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 4630501a0..1711bd33c 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete_test.go @@ -14,6 +14,7 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} @@ -21,6 +22,7 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() +var testRegion = "eu01" func fixtureArgValues(mods ...func(argValues []string)) []string { argValues := []string{ @@ -35,6 +37,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -47,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, CredentialsGroupId: testCredentialsGroupId, } @@ -57,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteCredentialsGroupRequest)) objectstorage.ApiDeleteCredentialsGroupRequest { - request := testClient.DeleteCredentialsGroup(testCtx, testProjectId, testCredentialsGroupId) + request := testClient.DeleteCredentialsGroup(testCtx, testProjectId, testRegion, testCredentialsGroupId) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/credentials-group/list/list.go b/internal/cmd/object-storage/credentials-group/list/list.go index 7f2962c23..8379df54a 100644 --- a/internal/cmd/object-storage/credentials-group/list/list.go +++ b/internal/cmd/object-storage/credentials-group/list/list.go @@ -117,7 +117,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListCredentialsGroupsRequest { - req := apiClient.ListCredentialsGroups(ctx, model.ProjectId) + req := apiClient.ListCredentialsGroups(ctx, model.ProjectId, model.Region) return req } 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 43cd2e46a..7c9580330 100644 --- a/internal/cmd/object-storage/credentials-group/list/list_test.go +++ b/internal/cmd/object-storage/credentials-group/list/list_test.go @@ -15,17 +15,20 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, limitFlag: "10", + regionFlag: "eu01", } for _, mod := range mods { mod(flagValues) @@ -38,6 +41,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, Limit: utils.Ptr(int64(10)), } @@ -48,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListCredentialsGroupsRequest)) objectstorage.ApiListCredentialsGroupsRequest { - request := testClient.ListCredentialsGroups(testCtx, testProjectId) + request := testClient.ListCredentialsGroups(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/credentials/create/create.go b/internal/cmd/object-storage/credentials/create/create.go index 1e659cdb7..c4e819827 100644 --- a/internal/cmd/object-storage/credentials/create/create.go +++ b/internal/cmd/object-storage/credentials/create/create.go @@ -60,7 +60,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -129,7 +129,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateAccessKeyRequest { - req := apiClient.CreateAccessKey(ctx, model.ProjectId) + req := apiClient.CreateAccessKey(ctx, model.ProjectId, model.Region) req = req.CredentialsGroup(model.CredentialsGroupId) req = req.CreateAccessKeyPayload(objectstorage.CreateAccessKeyPayload{ Expires: model.ExpireDate, diff --git a/internal/cmd/object-storage/credentials/create/create_test.go b/internal/cmd/object-storage/credentials/create/create_test.go index 41e19eddd..c26ddf0ee 100644 --- a/internal/cmd/object-storage/credentials/create/create_test.go +++ b/internal/cmd/object-storage/credentials/create/create_test.go @@ -16,6 +16,7 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} @@ -24,12 +25,14 @@ var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() var testExpirationDate = "2024-01-01T00:00:00Z" +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, credentialsGroupIdFlag: testCredentialsGroupId, expireDateFlag: testExpirationDate, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -47,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, ExpireDate: utils.Ptr(testExpirationDate), CredentialsGroupId: testCredentialsGroupId, @@ -72,7 +76,7 @@ func fixturePayload(mods ...func(payload *objectstorage.CreateAccessKeyPayload)) } func fixtureRequest(mods ...func(request *objectstorage.ApiCreateAccessKeyRequest)) objectstorage.ApiCreateAccessKeyRequest { - request := testClient.CreateAccessKey(testCtx, testProjectId) + request := testClient.CreateAccessKey(testCtx, testProjectId, testRegion) request = request.CreateAccessKeyPayload(fixturePayload()) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { diff --git a/internal/cmd/object-storage/credentials/delete/delete.go b/internal/cmd/object-storage/credentials/delete/delete.go index a1baaf529..ed7fedb5e 100644 --- a/internal/cmd/object-storage/credentials/delete/delete.go +++ b/internal/cmd/object-storage/credentials/delete/delete.go @@ -51,13 +51,13 @@ func NewCmd(p *print.Printer) *cobra.Command { return err } - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId } - credentialsLabel, err := objectStorageUtils.GetCredentialsName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.CredentialsId) + credentialsLabel, err := objectStorageUtils.GetCredentialsName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.CredentialsId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get credentials name: %v", err) credentialsLabel = model.CredentialsId @@ -120,7 +120,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.CredentialsId) + req := apiClient.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 146a52fee..09ee7d04b 100644 --- a/internal/cmd/object-storage/credentials/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials/delete/delete_test.go @@ -14,6 +14,7 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} @@ -22,6 +23,7 @@ var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() var testCredentialsId = "keyID" +var testRegion = "eu01" func fixtureArgValues(mods ...func(argValues []string)) []string { argValues := []string{ @@ -37,6 +39,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st flagValues := map[string]string{ projectIdFlag: testProjectId, credentialsGroupIdFlag: testCredentialsGroupId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -49,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, CredentialsGroupId: testCredentialsGroupId, CredentialsId: testCredentialsId, @@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDeleteAccessKeyRequest)) objectstorage.ApiDeleteAccessKeyRequest { - request := testClient.DeleteAccessKey(testCtx, testProjectId, testCredentialsId) + request := testClient.DeleteAccessKey(testCtx, testProjectId, testRegion, testCredentialsId) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { mod(&request) diff --git a/internal/cmd/object-storage/credentials/list/list.go b/internal/cmd/object-storage/credentials/list/list.go index 237d74c61..1e5c7ebba 100644 --- a/internal/cmd/object-storage/credentials/list/list.go +++ b/internal/cmd/object-storage/credentials/list/list.go @@ -69,7 +69,7 @@ func NewCmd(p *print.Printer) *cobra.Command { } credentials := *resp.AccessKeys if len(credentials) == 0 { - credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId) + credentialsGroupLabel, err := objectStorageUtils.GetCredentialsGroupName(ctx, apiClient, model.ProjectId, model.CredentialsGroupId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get credentials group name: %v", err) credentialsGroupLabel = model.CredentialsGroupId @@ -131,7 +131,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiListAccessKeysRequest { - req := apiClient.ListAccessKeys(ctx, model.ProjectId) + req := apiClient.ListAccessKeys(ctx, model.ProjectId, model.Region) req = req.CredentialsGroup(model.CredentialsGroupId) return req } diff --git a/internal/cmd/object-storage/credentials/list/list_test.go b/internal/cmd/object-storage/credentials/list/list_test.go index 27845efa5..b778e5dc1 100644 --- a/internal/cmd/object-storage/credentials/list/list_test.go +++ b/internal/cmd/object-storage/credentials/list/list_test.go @@ -15,6 +15,7 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} @@ -22,12 +23,14 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() var testCredentialsGroupId = uuid.NewString() +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, credentialsGroupIdFlag: testCredentialsGroupId, limitFlag: "10", + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -40,6 +43,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, CredentialsGroupId: testCredentialsGroupId, Limit: utils.Ptr(int64(10)), @@ -51,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiListAccessKeysRequest)) objectstorage.ApiListAccessKeysRequest { - request := testClient.ListAccessKeys(testCtx, testProjectId) + request := testClient.ListAccessKeys(testCtx, testProjectId, testRegion) request = request.CredentialsGroup(testCredentialsGroupId) for _, mod := range mods { mod(&request) diff --git a/internal/cmd/object-storage/disable/disable.go b/internal/cmd/object-storage/disable/disable.go index 40303b8da..56e6f940d 100644 --- a/internal/cmd/object-storage/disable/disable.go +++ b/internal/cmd/object-storage/disable/disable.go @@ -99,6 +99,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiDisableServiceRequest { - req := apiClient.DisableService(ctx, model.ProjectId) + req := apiClient.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 969b92b71..cb65e8961 100644 --- a/internal/cmd/object-storage/disable/disable_test.go +++ b/internal/cmd/object-storage/disable/disable_test.go @@ -15,16 +15,19 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, } for _, mod := range mods { @@ -46,7 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiDisableServiceRequest)) objectstorage.ApiDisableServiceRequest { - request := testClient.DisableService(testCtx, testProjectId) + request := testClient.DisableService(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } diff --git a/internal/cmd/object-storage/enable/enable.go b/internal/cmd/object-storage/enable/enable.go index 52bbec6f9..cec0d6e7d 100644 --- a/internal/cmd/object-storage/enable/enable.go +++ b/internal/cmd/object-storage/enable/enable.go @@ -99,6 +99,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiEnableServiceRequest { - req := apiClient.EnableService(ctx, model.ProjectId) + req := apiClient.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 3fbca13d1..562bb6907 100644 --- a/internal/cmd/object-storage/enable/enable_test.go +++ b/internal/cmd/object-storage/enable/enable_test.go @@ -15,16 +15,19 @@ import ( ) var projectIdFlag = globalflags.ProjectIdFlag +var regionFlag = globalflags.RegionFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &objectstorage.APIClient{} var testProjectId = uuid.NewString() +var testRegion = "eu01" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ projectIdFlag: testProjectId, + regionFlag: testRegion, } for _, mod := range mods { mod(flagValues) @@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, + Region: testRegion, }, } for _, mod := range mods { @@ -46,7 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *objectstorage.ApiEnableServiceRequest)) objectstorage.ApiEnableServiceRequest { - request := testClient.EnableService(testCtx, testProjectId) + request := testClient.EnableService(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } diff --git a/internal/pkg/services/object-storage/utils/utils.go b/internal/pkg/services/object-storage/utils/utils.go index e596eb203..bd23d0854 100644 --- a/internal/pkg/services/object-storage/utils/utils.go +++ b/internal/pkg/services/object-storage/utils/utils.go @@ -10,13 +10,13 @@ import ( ) type ObjectStorageClient interface { - GetServiceStatusExecute(ctx context.Context, projectId string) (*objectstorage.ProjectStatus, error) - ListCredentialsGroupsExecute(ctx context.Context, projectId string) (*objectstorage.ListCredentialsGroupsResponse, error) - ListAccessKeys(ctx context.Context, projectId string) objectstorage.ApiListAccessKeysRequest + 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 string) (bool, error) { - _, err := apiClient.GetServiceStatusExecute(ctx, projectId) +func ProjectEnabled(ctx context.Context, apiClient ObjectStorageClient, projectId, region string) (bool, error) { + _, err := apiClient.GetServiceStatusExecute(ctx, projectId, region) 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 +30,8 @@ func ProjectEnabled(ctx context.Context, apiClient ObjectStorageClient, projectI return true, nil } -func GetCredentialsGroupName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId string) (string, error) { - resp, err := apiClient.ListCredentialsGroupsExecute(ctx, projectId) +func GetCredentialsGroupName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId, region string) (string, error) { + resp, err := apiClient.ListCredentialsGroupsExecute(ctx, projectId, region) if err != nil { return "", fmt.Errorf("list Object Storage credentials groups: %w", err) } @@ -50,8 +50,8 @@ func GetCredentialsGroupName(ctx context.Context, apiClient ObjectStorageClient, return "", fmt.Errorf("could not find Object Storage credentials group name") } -func GetCredentialsName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId, keyId string) (string, error) { - req := apiClient.ListAccessKeys(ctx, projectId) +func GetCredentialsName(ctx context.Context, apiClient ObjectStorageClient, projectId, credentialsGroupId, keyId, region string) (string, error) { + req := apiClient.ListAccessKeys(ctx, projectId, region) req = req.CredentialsGroup(credentialsGroupId) resp, err := req.Execute() diff --git a/internal/pkg/services/object-storage/utils/utils_test.go b/internal/pkg/services/object-storage/utils/utils_test.go index c2dc0bb61..65b176172 100644 --- a/internal/pkg/services/object-storage/utils/utils_test.go +++ b/internal/pkg/services/object-storage/utils/utils_test.go @@ -20,6 +20,7 @@ var ( testProjectId = uuid.NewString() testCredentialsGroupId = uuid.NewString() testCredentialsId = "credentialsID" //nolint:gosec // linter false positive + testRegion = "eu01" ) const ( @@ -35,7 +36,7 @@ type objectStorageClientMocked struct { listAccessKeysReq objectstorage.ApiListAccessKeysRequest } -func (m *objectStorageClientMocked) GetServiceStatusExecute(_ context.Context, _ string) (*objectstorage.ProjectStatus, error) { +func (m *objectStorageClientMocked) GetServiceStatusExecute(_ context.Context, _, _ string) (*objectstorage.ProjectStatus, error) { if m.getServiceStatusFails { return nil, fmt.Errorf("could not get service status") } @@ -45,14 +46,14 @@ func (m *objectStorageClientMocked) GetServiceStatusExecute(_ context.Context, _ return &objectstorage.ProjectStatus{}, nil } -func (m *objectStorageClientMocked) ListCredentialsGroupsExecute(_ context.Context, _ string) (*objectstorage.ListCredentialsGroupsResponse, error) { +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 (m *objectStorageClientMocked) ListAccessKeys(_ context.Context, _ string) objectstorage.ApiListAccessKeysRequest { +func (m *objectStorageClientMocked) ListAccessKeys(_ context.Context, _, _ string) objectstorage.ApiListAccessKeysRequest { return m.listAccessKeysReq } @@ -89,7 +90,7 @@ func TestProjectEnabled(t *testing.T) { getServiceStatusFails: tt.getProjectFails, } - output, err := ProjectEnabled(context.Background(), client, testProjectId) + output, err := ProjectEnabled(context.Background(), client, testProjectId, testRegion) if tt.isValid && err != nil { fmt.Printf("failed on valid input: %v", err) @@ -202,7 +203,7 @@ func TestGetCredentialsGroupName(t *testing.T) { listCredentialsGroupsResp: tt.listCredentialsGroupsResp, } - output, err := GetCredentialsGroupName(context.Background(), client, testProjectId, testCredentialsGroupId) + output, err := GetCredentialsGroupName(context.Background(), client, testProjectId, testCredentialsGroupId, testRegion) if tt.isValid && err != nil { t.Errorf("failed on valid input") @@ -341,7 +342,7 @@ func TestGetCredentialsName(t *testing.T) { t.Fatalf("Failed to initialize client: %v", err) } - output, err := GetCredentialsName(context.Background(), client, testProjectId, testCredentialsGroupId, testCredentialsId) + output, err := GetCredentialsName(context.Background(), client, testProjectId, testCredentialsGroupId, testCredentialsId, testRegion) if tt.isValid && err != nil { t.Errorf("failed on valid input")