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

feat(cmd): add database user password update #1036

Merged
merged 5 commits into from
Feb 23, 2024

Conversation

curzolapierre
Copy link
Member

@curzolapierre curzolapierre commented Feb 9, 2024

Examples

Max retry reached

➜ scalingo --app my-app --addon mysql database-users-update-password my_user
Password (Will be generated if left empty): 
Password Confirmation: 
 !     Password confirmation doesn't match. Remaining retries: 2
Password (Will be generated if left empty): 
Password Confirmation: 
 !     Password confirmation doesn't match. Remaining retries: 1
Password (Will be generated if left empty): 
Password Confirmation: 
 !     Password confirmation doesn't match. Too many retries

User does not exists

➜ scalingo --app my-app --addon mysql database-users-update-password user_does_not_exists
 !     An error occurred:
       User "user_does_not_exists" does not exist

It works after a retry

➜ scalingo --app my-app --addon mysql database-users-update-password my_user
Password (Will be generated if left empty): 
Password Confirmation: 
 !     Password confirmation doesn't match. Remaining retries: 2
Password (Will be generated if left empty): 
Password Confirmation: 
User "my_user" password updated.

It works generates a password

➜ scalingo --app my-app --addon mysql database-users-update-password my_user
Password (Will be generated if left empty): 
Password Confirmation: 
User "my_user" updated with password "this_is_a_generated_password".

Fixes #1034

@curzolapierre curzolapierre self-assigned this Feb 9, 2024
@curzolapierre curzolapierre changed the title fix(style): correct errorCtx variable feat(cmd): add database user password update Feb 12, 2024
@curzolapierre curzolapierre force-pushed the feat/1034/update_database_user_password branch 2 times, most recently from d5e057e to e50d2ea Compare February 20, 2024 17:22
Copy link

@curzolapierre curzolapierre marked this pull request as ready for review February 23, 2024 08:36
Copy link
Contributor

@ipfaze ipfaze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions otherwise LGTM

return nil
}

password, confirmedPassword, err := askForPassword(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: allow client to retry 3 times to set his own password

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep why not


isPasswordGenerated := false
if password == "" {
isPasswordGenerated = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: display a message that password will be generated because left empty or max retry attempts reached

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already handled by askForPassword or you're looking for something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message in askForPassword just say that if the client let it empty it will be generated but if he tries 3 times and fail, we will generate it for him without any message to inform him.
Do you see what I mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what you means.

But I'm not sure we want to change the behavior as it is what the API expects actually, empty password and confirmation to make it generate one: https://developers.scalingo.com/databases/users

I've updated the description of this PR with an example of generated password. It is more clear and/or ok for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, sorry misread your code 🙁

Copy link
Member Author

@curzolapierre curzolapierre Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem :)

cmd/databases.go Outdated
&addonFlag,
},
Description: CommandDescription{
Description: `Update a non-protected database user's password.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sentence may be misunderstood, like the "database is non-protected" when it's the user who is non-protected.

I suggest:

Suggested change
Description: `Update a non-protected database user's password.
Description: `Update password for unprotected database user.

WDYT?

@@ -10,14 +10,14 @@ import (
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-scalingo/v6"
scErrors "github.com/Scalingo/go-utils/errors/v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: thanks for handling this 🙏

@curzolapierre curzolapierre force-pushed the feat/1034/update_database_user_password branch from 7ca53ff to f18a31c Compare February 23, 2024 11:08
Copy link
Contributor

@ipfaze ipfaze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining suggestion otherwise LGTM 👍

Copy link
Contributor

@ipfaze ipfaze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍


isPasswordGenerated := false
if password == "" {
isPasswordGenerated = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, sorry misread your code 🙁

@curzolapierre curzolapierre merged commit 2b8d414 into master Feb 23, 2024
6 checks passed
@curzolapierre curzolapierre deleted the feat/1034/update_database_user_password branch February 23, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PG-SCRAM-MIGRATION | STORY-151] Update a database user password
3 participants