From dd6e08b55bc901e00e7c0078b4dec30f62a62a3c Mon Sep 17 00:00:00 2001 From: Henrique Santos <118177985+hcsa73@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:27:44 +0000 Subject: [PATCH] Replace membership with authorization (#65) * Replace membership with authorization * Reorder fields --------- Co-authored-by: Henrique Santos --- docs/stackit_config_set.md | 2 +- docs/stackit_config_unset.md | 2 +- docs/stackit_mongodbflex_instance_create.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- internal/cmd/config/set/set.go | 10 +++++----- internal/cmd/config/unset/unset.go | 14 +++++++------- internal/cmd/organization/member/add/add.go | 10 +++++----- internal/cmd/organization/member/add/add_test.go | 12 ++++++------ internal/cmd/organization/member/list/list.go | 8 ++++---- .../cmd/organization/member/list/list_test.go | 8 ++++---- .../cmd/organization/member/remove/remove.go | 10 +++++----- .../organization/member/remove/remove_test.go | 16 ++++++++-------- internal/cmd/organization/role/list/list.go | 8 ++++---- internal/cmd/organization/role/list/list_test.go | 8 ++++---- internal/cmd/project/member/add/add.go | 10 +++++----- internal/cmd/project/member/add/add_test.go | 12 ++++++------ internal/cmd/project/member/list/list.go | 8 ++++---- internal/cmd/project/member/list/list_test.go | 8 ++++---- internal/cmd/project/member/remove/remove.go | 10 +++++----- .../cmd/project/member/remove/remove_test.go | 16 ++++++++-------- internal/cmd/project/role/list/list.go | 8 ++++---- internal/cmd/project/role/list/list_test.go | 8 ++++---- internal/pkg/config/config.go | 6 +++--- .../client/client.go | 10 +++++----- 25 files changed, 106 insertions(+), 106 deletions(-) rename internal/pkg/services/{membership => authorization}/client/client.go (70%) diff --git a/docs/stackit_config_set.md b/docs/stackit_config_set.md index 25ea63d7..81ea7e5d 100644 --- a/docs/stackit_config_set.md +++ b/docs/stackit_config_set.md @@ -29,11 +29,11 @@ stackit config set [flags] ### Options ``` + --authorization-custom-endpoint string Authorization custom endpoint --dns-custom-endpoint string DNS custom endpoint -h, --help Help for "stackit config set" --logme-custom-endpoint string LogMe custom endpoint --mariadb-custom-endpoint string MariaDB custom endpoint - --membership-custom-endpoint string Membership custom endpoint --mongodbflex-custom-endpoint string MongoDB Flex custom endpoint --opensearch-custom-endpoint string OpenSearch custom endpoint --postgresflex-custom-endpoint string PostgreSQL Flex custom endpoint diff --git a/docs/stackit_config_unset.md b/docs/stackit_config_unset.md index 9c4937be..c843842d 100644 --- a/docs/stackit_config_unset.md +++ b/docs/stackit_config_unset.md @@ -27,11 +27,11 @@ stackit config unset [flags] ``` --async Configuration option to run commands asynchronously + --authorization-custom-endpoint Authorization custom endpoint --dns-custom-endpoint DNS custom endpoint -h, --help Help for "stackit config unset" --logme-custom-endpoint LogMe custom endpoint --mariadb-custom-endpoint MariaDB custom endpoint - --membership-custom-endpoint Membership custom endpoint --mongodbflex-custom-endpoint MongoDB Flex custom endpoint --opensearch-custom-endpoint OpenSearch custom endpoint --output-format Output format diff --git a/docs/stackit_mongodbflex_instance_create.md b/docs/stackit_mongodbflex_instance_create.md index e8303cc0..716ac726 100644 --- a/docs/stackit_mongodbflex_instance_create.md +++ b/docs/stackit_mongodbflex_instance_create.md @@ -35,7 +35,7 @@ stackit mongodbflex instance create [flags] --ram int Amount of RAM (in GB) --storage-class string Storage class (default "premium-perf2-mongodb") --storage-size int Storage size (in GB) (default 10) - --type string Instance type, one of ["Replica" "Sharded" "Single"] (default "Replica") + --type string Instance type, one of ["Single" "Replica" "Sharded"] (default "Replica") --version string MongoDB version. Defaults to the latest version available ``` diff --git a/go.mod b/go.mod index 78e6516c..6f769bdb 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,8 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 github.com/stackitcloud/stackit-sdk-go/core v0.7.7 + github.com/stackitcloud/stackit-sdk-go/services/authorization v0.1.0 github.com/stackitcloud/stackit-sdk-go/services/dns v0.8.2 - github.com/stackitcloud/stackit-sdk-go/services/membership v0.3.4 github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.10.3 github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.9.2 github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.9.1 diff --git a/go.sum b/go.sum index 5b8162e5..90d39659 100644 --- a/go.sum +++ b/go.sum @@ -79,14 +79,14 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stackitcloud/stackit-sdk-go/core v0.7.7 h1:w1T8I2ERT5xPHXS+UV9maSseK8tyUJQjzS21hhRSWjU= github.com/stackitcloud/stackit-sdk-go/core v0.7.7/go.mod h1:nfC2Tbjd73Ivn8wEp3lvG/dmiXHgl6QX+HY2Ih3aGgw= +github.com/stackitcloud/stackit-sdk-go/services/authorization v0.1.0 h1:FkOaz7ZutvteismzVHsabddg5GLWvRCA9jEzWH1/V9Y= +github.com/stackitcloud/stackit-sdk-go/services/authorization v0.1.0/go.mod h1:n2iI0NZdawwkGt3nqm09l8kSJ3MGgLCCOWdVzanEPzA= github.com/stackitcloud/stackit-sdk-go/services/dns v0.8.2 h1:Wj3A+BAitSK74dRMxEGoKU1itEZmjwrAECT/CgsEJOQ= github.com/stackitcloud/stackit-sdk-go/services/dns v0.8.2/go.mod h1:RYRnST/3Kz5GmxMmFvsaYFblfZ/LMxw8r9DNfnRhX/4= github.com/stackitcloud/stackit-sdk-go/services/logme v0.10.0 h1:5+X0sKPdnLT/a1Jt73YphecQpPEOpd6TY6XdK0zGqP4= github.com/stackitcloud/stackit-sdk-go/services/logme v0.10.0/go.mod h1:e/I/8wJEqLdzdEgsGh7UbwbMMMNL5F1os25K+vQSzOc= github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0 h1:WxvySRZfkecOVjrpK3NiyqPL9YWKSpdBbIf55Y5HlNs= github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0/go.mod h1:GQ+UyuUOANO/kQOIhqLmMYRH34NbZShMrfmUY6hTSjo= -github.com/stackitcloud/stackit-sdk-go/services/membership v0.3.4 h1:0OT/UBP55/GPMm9Tks9Uhb+PvP/2zI6ZUySfh7px+kY= -github.com/stackitcloud/stackit-sdk-go/services/membership v0.3.4/go.mod h1:6ovfcQJ96ivkBpSI933lVl2a/SWprpVGoK6YNKycLps= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.10.3 h1:M7ALIg1tE8MFLLw9Um0iyvdBgIhl83tJ0sWRjP7YqMM= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.10.3/go.mod h1:LWfUBjGQWF3SZivQdUdAC/WxJkx8ImJKy5GFMV3tXHY= github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.9.2 h1:dwZ1NDD+AxTaZqAeR/0PY7yt32dbABhQH1Vsnt8A+hg= diff --git a/internal/cmd/config/set/set.go b/internal/cmd/config/set/set.go index 5089f453..8d9cd07b 100644 --- a/internal/cmd/config/set/set.go +++ b/internal/cmd/config/set/set.go @@ -18,10 +18,10 @@ import ( const ( sessionTimeLimitFlag = "session-time-limit" + authorizationCustomEndpointFlag = "authorization-custom-endpoint" dnsCustomEndpointFlag = "dns-custom-endpoint" logMeCustomEndpointFlag = "logme-custom-endpoint" mariaDBCustomEndpointFlag = "mariadb-custom-endpoint" - membershipCustomEndpointFlag = "membership-custom-endpoint" mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint" openSearchCustomEndpointFlag = "opensearch-custom-endpoint" postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint" @@ -90,10 +90,10 @@ func NewCmd() *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().String(sessionTimeLimitFlag, "", "Maximum time before authentication is required again. Can't be larger than 24h. Examples: 3h, 5h30m40s (BETA: currently values greater than 2h have no effect)") + cmd.Flags().String(authorizationCustomEndpointFlag, "", "Authorization custom endpoint") cmd.Flags().String(dnsCustomEndpointFlag, "", "DNS custom endpoint") cmd.Flags().String(logMeCustomEndpointFlag, "", "LogMe custom endpoint") cmd.Flags().String(mariaDBCustomEndpointFlag, "", "MariaDB custom endpoint") - cmd.Flags().String(membershipCustomEndpointFlag, "", "Membership custom endpoint") cmd.Flags().String(mongoDBFlexCustomEndpointFlag, "", "MongoDB Flex custom endpoint") cmd.Flags().String(openSearchCustomEndpointFlag, "", "OpenSearch custom endpoint") cmd.Flags().String(postgresFlexCustomEndpointFlag, "", "PostgreSQL Flex custom endpoint") @@ -103,14 +103,14 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().String(serviceAccountCustomEndpointFlag, "", "Service Account custom endpoint") cmd.Flags().String(skeCustomEndpointFlag, "", "SKE custom endpoint") - err := viper.BindPFlag(config.DNSCustomEndpointKey, cmd.Flags().Lookup(dnsCustomEndpointFlag)) + err := viper.BindPFlag(config.AuthorizationCustomEndpointKey, cmd.Flags().Lookup(authorizationCustomEndpointFlag)) + cobra.CheckErr(err) + err = viper.BindPFlag(config.DNSCustomEndpointKey, cmd.Flags().Lookup(dnsCustomEndpointFlag)) cobra.CheckErr(err) err = viper.BindPFlag(config.LogMeCustomEndpointKey, cmd.Flags().Lookup(logMeCustomEndpointFlag)) cobra.CheckErr(err) err = viper.BindPFlag(config.MariaDBCustomEndpointKey, cmd.Flags().Lookup(mariaDBCustomEndpointFlag)) cobra.CheckErr(err) - err = viper.BindPFlag(config.MembershipCustomEndpointKey, cmd.Flags().Lookup(membershipCustomEndpointFlag)) - cobra.CheckErr(err) err = viper.BindPFlag(config.MongoDBFlexCustomEndpointKey, cmd.Flags().Lookup(mongoDBFlexCustomEndpointFlag)) cobra.CheckErr(err) err = viper.BindPFlag(config.OpenSearchCustomEndpointKey, cmd.Flags().Lookup(openSearchCustomEndpointFlag)) diff --git a/internal/cmd/config/unset/unset.go b/internal/cmd/config/unset/unset.go index 9db675ad..fba728d2 100644 --- a/internal/cmd/config/unset/unset.go +++ b/internal/cmd/config/unset/unset.go @@ -18,10 +18,10 @@ const ( outputFormatFlag = globalflags.OutputFormatFlag projectIdFlag = globalflags.ProjectIdFlag + authorizationCustomEndpointFlag = "authorization-custom-endpoint" dnsCustomEndpointFlag = "dns-custom-endpoint" logMeCustomEndpointFlag = "logme-custom-endpoint" mariaDBCustomEndpointFlag = "mariadb-custom-endpoint" - membershipCustomEndpointFlag = "membership-custom-endpoint" mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint" openSearchCustomEndpointFlag = "opensearch-custom-endpoint" postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint" @@ -37,10 +37,10 @@ type inputModel struct { OutputFormat bool ProjectId bool + AuthorizationCustomEndpoint bool DNSCustomEndpoint bool LogMeCustomEndpoint bool MariaDBCustomEndpoint bool - MembershipCustomEndpoint bool MongoDBFlexCustomEndpoint bool OpenSearchCustomEndpoint bool PostgresFlexCustomEndpoint bool @@ -81,6 +81,9 @@ func NewCmd() *cobra.Command { viper.Set(config.ProjectIdKey, "") } + if model.AuthorizationCustomEndpoint { + viper.Set(config.AuthorizationCustomEndpointKey, "") + } if model.DNSCustomEndpoint { viper.Set(config.DNSCustomEndpointKey, "") } @@ -90,9 +93,6 @@ func NewCmd() *cobra.Command { if model.MariaDBCustomEndpoint { viper.Set(config.MariaDBCustomEndpointKey, "") } - if model.MembershipCustomEndpoint { - viper.Set(config.MembershipCustomEndpointKey, "") - } if model.MongoDBFlexCustomEndpoint { viper.Set(config.MongoDBFlexCustomEndpointKey, "") } @@ -134,10 +134,10 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().Bool(projectIdFlag, false, "Project ID") cmd.Flags().Bool(outputFormatFlag, false, "Output format") + cmd.Flags().Bool(authorizationCustomEndpointFlag, false, "Authorization custom endpoint") cmd.Flags().Bool(dnsCustomEndpointFlag, false, "DNS custom endpoint") cmd.Flags().Bool(logMeCustomEndpointFlag, false, "LogMe custom endpoint") cmd.Flags().Bool(mariaDBCustomEndpointFlag, false, "MariaDB custom endpoint") - cmd.Flags().Bool(membershipCustomEndpointFlag, false, "Membership custom endpoint") cmd.Flags().Bool(mongoDBFlexCustomEndpointFlag, false, "MongoDB Flex custom endpoint") cmd.Flags().Bool(openSearchCustomEndpointFlag, false, "OpenSearch custom endpoint") cmd.Flags().Bool(postgresFlexCustomEndpointFlag, false, "PostgreSQL Flex custom endpoint") @@ -154,10 +154,10 @@ func parseInput(cmd *cobra.Command) *inputModel { OutputFormat: flags.FlagToBoolValue(cmd, outputFormatFlag), ProjectId: flags.FlagToBoolValue(cmd, projectIdFlag), + AuthorizationCustomEndpoint: flags.FlagToBoolValue(cmd, authorizationCustomEndpointFlag), DNSCustomEndpoint: flags.FlagToBoolValue(cmd, dnsCustomEndpointFlag), LogMeCustomEndpoint: flags.FlagToBoolValue(cmd, logMeCustomEndpointFlag), MariaDBCustomEndpoint: flags.FlagToBoolValue(cmd, mariaDBCustomEndpointFlag), - MembershipCustomEndpoint: flags.FlagToBoolValue(cmd, membershipCustomEndpointFlag), MongoDBFlexCustomEndpoint: flags.FlagToBoolValue(cmd, mongoDBFlexCustomEndpointFlag), OpenSearchCustomEndpoint: flags.FlagToBoolValue(cmd, openSearchCustomEndpointFlag), PostgresFlexCustomEndpoint: flags.FlagToBoolValue(cmd, postgresFlexCustomEndpointFlag), diff --git a/internal/cmd/organization/member/add/add.go b/internal/cmd/organization/member/add/add.go index aa9a819b..d1290ccc 100644 --- a/internal/cmd/organization/member/add/add.go +++ b/internal/cmd/organization/member/add/add.go @@ -9,11 +9,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -107,10 +107,10 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiAddMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiAddMembersRequest { req := apiClient.AddMembers(ctx, *model.OrganizationId) - req = req.AddMembersPayload(membership.AddMembersPayload{ - Members: utils.Ptr([]membership.Member{ + req = req.AddMembersPayload(authorization.AddMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: utils.Ptr(model.Subject), Role: model.Role, diff --git a/internal/cmd/organization/member/add/add_test.go b/internal/cmd/organization/member/add/add_test.go index f43d558a..8bfb8c6c 100644 --- a/internal/cmd/organization/member/add/add_test.go +++ b/internal/cmd/organization/member/add/add_test.go @@ -9,13 +9,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testOrganizationID = "some-organization-id" var testSubject = "someone@domain.com" var testRole = "reader" @@ -54,10 +54,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiAddMembersRequest)) membership.ApiAddMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiAddMembersRequest)) authorization.ApiAddMembersRequest { request := testClient.AddMembers(testCtx, testOrganizationID) - request = request.AddMembersPayload(membership.AddMembersPayload{ - Members: utils.Ptr([]membership.Member{ + request = request.AddMembersPayload(authorization.AddMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, @@ -178,7 +178,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiAddMembersRequest + expectedRequest authorization.ApiAddMembersRequest }{ { description: "base", diff --git a/internal/cmd/organization/member/list/list.go b/internal/cmd/organization/member/list/list.go index e92be640..2cb6c0c7 100644 --- a/internal/cmd/organization/member/list/list.go +++ b/internal/cmd/organization/member/list/list.go @@ -11,11 +11,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -122,7 +122,7 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiListMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiListMembersRequest { req := apiClient.ListMembers(ctx, organizationResourceType, *model.OrganizationId) if model.Subject != nil { req = req.Subject(*model.Subject) @@ -130,7 +130,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *membership. return req } -func outputResult(cmd *cobra.Command, model *inputModel, members []membership.Member) error { +func outputResult(cmd *cobra.Command, model *inputModel, members []authorization.Member) error { sortFn := func(i, j int) bool { switch model.SortBy { case "subject": diff --git a/internal/cmd/organization/member/list/list_test.go b/internal/cmd/organization/member/list/list_test.go index 2f75b993..dd781933 100644 --- a/internal/cmd/organization/member/list/list_test.go +++ b/internal/cmd/organization/member/list/list_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testOrganizationID = "some-organization-id" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -43,7 +43,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiListMembersRequest)) membership.ApiListMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiListMembersRequest)) authorization.ApiListMembersRequest { request := testClient.ListMembers(testCtx, organizationResourceType, testOrganizationID) for _, mod := range mods { mod(&request) @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiListMembersRequest + expectedRequest authorization.ApiListMembersRequest }{ { description: "base", diff --git a/internal/cmd/organization/member/remove/remove.go b/internal/cmd/organization/member/remove/remove.go index a9fd9ef9..e76a23a2 100644 --- a/internal/cmd/organization/member/remove/remove.go +++ b/internal/cmd/organization/member/remove/remove.go @@ -9,11 +9,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -115,10 +115,10 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiRemoveMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiRemoveMembersRequest { req := apiClient.RemoveMembers(ctx, *model.OrganizationId) - payload := membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + payload := authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: utils.Ptr(model.Subject), Role: model.Role, diff --git a/internal/cmd/organization/member/remove/remove_test.go b/internal/cmd/organization/member/remove/remove_test.go index 2668844b..6ba7eff7 100644 --- a/internal/cmd/organization/member/remove/remove_test.go +++ b/internal/cmd/organization/member/remove/remove_test.go @@ -9,13 +9,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testOrganizationID = "some-organization-id" var testSubject = "someone@domain.com" var testRole = "reader" @@ -54,10 +54,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiRemoveMembersRequest)) membership.ApiRemoveMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiRemoveMembersRequest)) authorization.ApiRemoveMembersRequest { request := testClient.RemoveMembers(testCtx, testOrganizationID) - request = request.RemoveMembersPayload(membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + request = request.RemoveMembersPayload(authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, @@ -191,7 +191,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiRemoveMembersRequest + expectedRequest authorization.ApiRemoveMembersRequest }{ { description: "base", @@ -204,8 +204,8 @@ func TestBuildRequest(t *testing.T) { model.Force = true }), expectedRequest: testClient.RemoveMembers(testCtx, testOrganizationID). - RemoveMembersPayload(membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + RemoveMembersPayload(authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, diff --git a/internal/cmd/organization/role/list/list.go b/internal/cmd/organization/role/list/list.go index ba70047b..e9d12aab 100644 --- a/internal/cmd/organization/role/list/list.go +++ b/internal/cmd/organization/role/list/list.go @@ -10,11 +10,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -111,11 +111,11 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiListRolesRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiListRolesRequest { return apiClient.ListRoles(ctx, organizationResourceType, *model.OrganizationId) } -func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []membership.Role) error { +func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authorization.Role) error { switch outputFormat { case globalflags.JSONOutputFormat: // Show details diff --git a/internal/cmd/organization/role/list/list_test.go b/internal/cmd/organization/role/list/list_test.go index 7e836143..4e6ee570 100644 --- a/internal/cmd/organization/role/list/list_test.go +++ b/internal/cmd/organization/role/list/list_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testOrganizationID = "some-organization-id" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -42,7 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiListRolesRequest)) membership.ApiListRolesRequest { +func fixtureRequest(mods ...func(request *authorization.ApiListRolesRequest)) authorization.ApiListRolesRequest { request := testClient.ListRoles(testCtx, organizationResourceType, testOrganizationID) for _, mod := range mods { mod(&request) @@ -142,7 +142,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiListRolesRequest + expectedRequest authorization.ApiListRolesRequest }{ { description: "base", diff --git a/internal/cmd/project/member/add/add.go b/internal/cmd/project/member/add/add.go index 2ea62b86..b8c108d7 100644 --- a/internal/cmd/project/member/add/add.go +++ b/internal/cmd/project/member/add/add.go @@ -11,11 +11,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -113,10 +113,10 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiAddMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiAddMembersRequest { req := apiClient.AddMembers(ctx, model.GlobalFlagModel.ProjectId) - req = req.AddMembersPayload(membership.AddMembersPayload{ - Members: utils.Ptr([]membership.Member{ + req = req.AddMembersPayload(authorization.AddMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: utils.Ptr(model.Subject), Role: model.Role, diff --git a/internal/cmd/project/member/add/add_test.go b/internal/cmd/project/member/add/add_test.go index 12766045..36d78653 100644 --- a/internal/cmd/project/member/add/add_test.go +++ b/internal/cmd/project/member/add/add_test.go @@ -10,7 +10,7 @@ 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/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -18,7 +18,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testProjectId = uuid.NewString() var testSubject = "someone@domain.com" var testRole = "reader" @@ -58,10 +58,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiAddMembersRequest)) membership.ApiAddMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiAddMembersRequest)) authorization.ApiAddMembersRequest { request := testClient.AddMembers(testCtx, testProjectId) - request = request.AddMembersPayload(membership.AddMembersPayload{ - Members: utils.Ptr([]membership.Member{ + request = request.AddMembersPayload(authorization.AddMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, @@ -176,7 +176,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiAddMembersRequest + expectedRequest authorization.ApiAddMembersRequest }{ { description: "base", diff --git a/internal/cmd/project/member/list/list.go b/internal/cmd/project/member/list/list.go index 7a3094f7..a20bd7fc 100644 --- a/internal/cmd/project/member/list/list.go +++ b/internal/cmd/project/member/list/list.go @@ -12,11 +12,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -123,7 +123,7 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiListMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiListMembersRequest { req := apiClient.ListMembers(ctx, projectResourceType, model.GlobalFlagModel.ProjectId) if model.Subject != nil { req = req.Subject(*model.Subject) @@ -131,7 +131,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *membership. return req } -func outputResult(cmd *cobra.Command, model *inputModel, members []membership.Member) error { +func outputResult(cmd *cobra.Command, model *inputModel, members []authorization.Member) error { sortFn := func(i, j int) bool { switch model.SortBy { case "subject": diff --git a/internal/cmd/project/member/list/list_test.go b/internal/cmd/project/member/list/list_test.go index 3543a8df..eaf78bec 100644 --- a/internal/cmd/project/member/list/list_test.go +++ b/internal/cmd/project/member/list/list_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -19,7 +19,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -47,7 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiListMembersRequest)) membership.ApiListMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiListMembersRequest)) authorization.ApiListMembersRequest { request := testClient.ListMembers(testCtx, projectResourceType, testProjectId) for _, mod := range mods { mod(&request) @@ -176,7 +176,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiListMembersRequest + expectedRequest authorization.ApiListMembersRequest }{ { description: "base", diff --git a/internal/cmd/project/member/remove/remove.go b/internal/cmd/project/member/remove/remove.go index f1e57638..d0715923 100644 --- a/internal/cmd/project/member/remove/remove.go +++ b/internal/cmd/project/member/remove/remove.go @@ -11,11 +11,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -121,10 +121,10 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiRemoveMembersRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiRemoveMembersRequest { req := apiClient.RemoveMembers(ctx, model.GlobalFlagModel.ProjectId) - payload := membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + payload := authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: utils.Ptr(model.Subject), Role: model.Role, diff --git a/internal/cmd/project/member/remove/remove_test.go b/internal/cmd/project/member/remove/remove_test.go index 7facc3c7..76372e8a 100644 --- a/internal/cmd/project/member/remove/remove_test.go +++ b/internal/cmd/project/member/remove/remove_test.go @@ -10,7 +10,7 @@ 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/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -18,7 +18,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testProjectId = uuid.NewString() var testSubject = "someone@domain.com" var testRole = "reader" @@ -58,10 +58,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiRemoveMembersRequest)) membership.ApiRemoveMembersRequest { +func fixtureRequest(mods ...func(request *authorization.ApiRemoveMembersRequest)) authorization.ApiRemoveMembersRequest { request := testClient.RemoveMembers(testCtx, testProjectId) - request = request.RemoveMembersPayload(membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + request = request.RemoveMembersPayload(authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, @@ -189,7 +189,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiRemoveMembersRequest + expectedRequest authorization.ApiRemoveMembersRequest }{ { description: "base", @@ -202,8 +202,8 @@ func TestBuildRequest(t *testing.T) { model.Force = true }), expectedRequest: testClient.RemoveMembers(testCtx, testProjectId). - RemoveMembersPayload(membership.RemoveMembersPayload{ - Members: utils.Ptr([]membership.Member{ + RemoveMembersPayload(authorization.RemoveMembersPayload{ + Members: utils.Ptr([]authorization.Member{ { Subject: &testSubject, Role: &testRole, diff --git a/internal/cmd/project/role/list/list.go b/internal/cmd/project/role/list/list.go index b8330ec3..afb0f9f4 100644 --- a/internal/cmd/project/role/list/list.go +++ b/internal/cmd/project/role/list/list.go @@ -11,11 +11,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/membership/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) const ( @@ -112,11 +112,11 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) { }, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *membership.APIClient) membership.ApiListRolesRequest { +func buildRequest(ctx context.Context, model *inputModel, apiClient *authorization.APIClient) authorization.ApiListRolesRequest { return apiClient.ListRoles(ctx, projectResourceType, model.GlobalFlagModel.ProjectId) } -func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []membership.Role) error { +func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authorization.Role) error { switch outputFormat { case globalflags.JSONOutputFormat: // Show details diff --git a/internal/cmd/project/role/list/list_test.go b/internal/cmd/project/role/list/list_test.go index 1349ed86..6246fbac 100644 --- a/internal/cmd/project/role/list/list_test.go +++ b/internal/cmd/project/role/list/list_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) var projectIdFlag = globalflags.ProjectIdFlag @@ -19,7 +19,7 @@ var projectIdFlag = globalflags.ProjectIdFlag type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &membership.APIClient{} +var testClient = &authorization.APIClient{} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -46,7 +46,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *membership.ApiListRolesRequest)) membership.ApiListRolesRequest { +func fixtureRequest(mods ...func(request *authorization.ApiListRolesRequest)) authorization.ApiListRolesRequest { request := testClient.ListRoles(testCtx, projectResourceType, testProjectId) for _, mod := range mods { mod(&request) @@ -146,7 +146,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest membership.ApiListRolesRequest + expectedRequest authorization.ApiListRolesRequest }{ { description: "base", diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index a9f93e8d..0d287530 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -16,10 +16,10 @@ const ( ProjectIdKey = "project_id" SessionTimeLimitKey = "session_time_limit" + AuthorizationCustomEndpointKey = "authorization_custom_endpoint" DNSCustomEndpointKey = "dns_custom_endpoint" LogMeCustomEndpointKey = "logme_custom_endpoint" MariaDBCustomEndpointKey = "mariadb_custom_endpoint" - MembershipCustomEndpointKey = "membership_custom_endpoint" MongoDBFlexCustomEndpointKey = "mongodbflex_custom_endpoint" OpenSearchCustomEndpointKey = "opensearch_custom_endpoint" PostgresFlexCustomEndpointKey = "postgresflex_custom_endpoint" @@ -53,7 +53,7 @@ var ConfigKeys = []string{ OpenSearchCustomEndpointKey, PostgresFlexCustomEndpointKey, ResourceManagerEndpointKey, - MembershipCustomEndpointKey, + AuthorizationCustomEndpointKey, MongoDBFlexCustomEndpointKey, RabbitMQCustomEndpointKey, RedisCustomEndpointKey, @@ -124,7 +124,7 @@ func setConfigDefaults() { viper.SetDefault(ProjectIdKey, "") viper.SetDefault(SessionTimeLimitKey, SessionTimeLimitDefault) viper.SetDefault(DNSCustomEndpointKey, "") - viper.SetDefault(MembershipCustomEndpointKey, "") + viper.SetDefault(AuthorizationCustomEndpointKey, "") viper.SetDefault(MongoDBFlexCustomEndpointKey, "") viper.SetDefault(OpenSearchCustomEndpointKey, "") viper.SetDefault(PostgresFlexCustomEndpointKey, "") diff --git a/internal/pkg/services/membership/client/client.go b/internal/pkg/services/authorization/client/client.go similarity index 70% rename from internal/pkg/services/membership/client/client.go rename to internal/pkg/services/authorization/client/client.go index 37292eda..11e170a2 100644 --- a/internal/pkg/services/membership/client/client.go +++ b/internal/pkg/services/authorization/client/client.go @@ -8,12 +8,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/membership" + "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) -func ConfigureClient(cmd *cobra.Command) (*membership.APIClient, error) { +func ConfigureClient(cmd *cobra.Command) (*authorization.APIClient, error) { var err error - var apiClient *membership.APIClient + var apiClient *authorization.APIClient var cfgOptions []sdkConfig.ConfigurationOption authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) @@ -22,13 +22,13 @@ func ConfigureClient(cmd *cobra.Command) (*membership.APIClient, error) { } cfgOptions = append(cfgOptions, authCfgOption) - customEndpoint := viper.GetString(config.MembershipCustomEndpointKey) + customEndpoint := viper.GetString(config.AuthorizationCustomEndpointKey) if customEndpoint != "" { cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint)) } - apiClient, err = membership.NewAPIClient(cfgOptions...) + apiClient, err = authorization.NewAPIClient(cfgOptions...) if err != nil { return nil, &errors.AuthError{} }