Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(users): user feedback messages improvements #1045

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/users/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ func DeleteUser(ctx context.Context, app, addonUUID, username string) error {
if err != nil {
return errors.Wrapf(ctx, err, "delete given user from database %v", username)
}
io.Statusf("User %v has been deleted\n", username)
return nil
}
21 changes: 12 additions & 9 deletions db/users/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ func UpdateUser(ctx context.Context, app, addonUUID, username string) error {
if err != nil {
return errors.Wrap(ctx, err, "get Scalingo client")
}

l, err := c.DatabaseListUsers(ctx, app, addonUUID)
if err != nil {
return errors.Wrap(ctx, err, "list the database's users")
}

// Check if the user exists
var userExists bool
for _, user := range l {
if user.Name == username {
userExists = true
// Check if the userParam exists and is not protected
var user *scalingo.DatabaseUser
for _, u := range l {
if u.Name == username {
user = &u
break
}
}
if !userExists {
if user == nil {
return errors.New(ctx, fmt.Sprintf("User \"%s\" does not exist", username))
}
if user.Protected {
return errors.New(ctx, fmt.Sprintf("User \"%s\" is protected", username))
}

password, confirmedPassword, err := askForPasswordWithRetry(ctx, 3)
if err != nil {
Expand All @@ -61,12 +64,12 @@ func UpdateUser(ctx context.Context, app, addonUUID, username string) error {
confirmedPassword = password
}

user := scalingo.DatabaseUpdateUserParam{
userUpdateParam := scalingo.DatabaseUpdateUserParam{
DatabaseID: addonUUID,
Password: password,
PasswordConfirmation: confirmedPassword,
}
databaseUsers, err := c.DatabaseUpdateUser(ctx, app, addonUUID, username, user)
databaseUsers, err := c.DatabaseUpdateUser(ctx, app, addonUUID, username, userUpdateParam)
if err != nil {
return errors.Wrap(ctx, err, "update password of the given database user")
}
Expand Down
2 changes: 1 addition & 1 deletion db/users/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var (
SupportedAddons = []string{"PostgreSQL", "InfluxDB", "MongoDB", "MySQL"}
ErrDatabaseNotSupportUserManagement = stdErrors.New("Error: DBMS does not support user management")
ErrDatabaseNotSupportUserManagement = stdErrors.New("Error: Addon does not support user management")
)

func doesDatabaseHandleUserManagement(ctx context.Context, app, addonUUID string) (bool, error) {
Expand Down