From 3ea9eddac0e3b6480836353247d24233426185ae Mon Sep 17 00:00:00 2001 From: CURZOLA Pierre Date: Thu, 16 Nov 2023 17:37:11 +0100 Subject: [PATCH] fix(cmd): add list of databases to user managements cmd description --- cmd/databases.go | 12 +++++++++--- db/users/utils.go | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/databases.go b/cmd/databases.go index fc37c1a5e..98a714fb8 100644 --- a/cmd/databases.go +++ b/cmd/databases.go @@ -146,7 +146,9 @@ var ( Usage: "Print database's users", Flags: []cli.Flag{&appFlag, &addonFlag}, Description: CommandDescription{ - Description: "List the users of a database", + Description: `List the users of a database + +Only available on ` + fmt.Sprintf("%s", dbUsers.SupportedAddons), Examples: []string{ "scalingo --app myapp --addon addon-uuid database-list-users", }, @@ -172,7 +174,9 @@ var ( Usage: "Delete a database's user", Flags: []cli.Flag{&appFlag, &addonFlag}, Description: CommandDescription{ - Description: "Delete the given user of a database", + Description: `Delete the given user of a database + +Only available on ` + fmt.Sprintf("%s", dbUsers.SupportedAddons), Examples: []string{ "scalingo --app myapp --addon addon-uuid database-delete-user my_user", }, @@ -208,7 +212,9 @@ var ( &cli.BoolFlag{Name: "read-only", Usage: "Create a user with read-only rights"}, }, Description: CommandDescription{ - Description: "Create new database user", + Description: `Create new database user + +Only available on ` + fmt.Sprintf("%s", dbUsers.SupportedAddons), Examples: []string{ "scalingo --app myapp --addon addon-uuid database-create-user my_user", "scalingo --app myapp --addon addon-uuid database-create-user my_user --read-only", diff --git a/db/users/utils.go b/db/users/utils.go index 55cb53dac..b89d9fa32 100644 --- a/db/users/utils.go +++ b/db/users/utils.go @@ -9,10 +9,12 @@ import ( scErrors "github.com/Scalingo/go-utils/errors/v2" ) -var ErrDatabaseNotSupportUserManagement = errors.New("Error: DBMS does not support user management") +var ( + SupportedAddons = []string{"postgresql", "elasticsearch", "influxdb"} + ErrDatabaseNotSupportUserManagement = errors.New("Error: DBMS does not support user management") +) func doesDatabaseHandleUserManagement(ctx context.Context, app, addonUUID string) (bool, error) { - supportedAddons := []string{"postgresql", "elasticsearch", "influxdb"} addonsClient, err := config.ScalingoClient(ctx) if err != nil { return false, scErrors.Wrap(ctx, err, "get Scalingo client") @@ -23,7 +25,7 @@ func doesDatabaseHandleUserManagement(ctx context.Context, app, addonUUID string return false, scErrors.Wrap(ctx, err, "get the addon to check user management support") } - for _, supportedAddon := range supportedAddons { + for _, supportedAddon := range SupportedAddons { if strings.EqualFold(supportedAddon, addon.AddonProvider.Name) { return true, nil }