Skip to content

Commit

Permalink
fix(cmd): add list of databases to user managements cmd description
Browse files Browse the repository at this point in the history
  • Loading branch information
curzolapierre committed Nov 16, 2023
1 parent c1d2739 commit 3ea9edd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions cmd/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions db/users/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down

0 comments on commit 3ea9edd

Please sign in to comment.