-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add admin/superuser error handling and cleanup #8559
Conversation
- Added a defer function to clean up the admin user if an error occurs during creation. - Added tests for creating an admin user, verifying successful creation, attempting to create another admin user, deleting the admin user, creating an admin user without a secret access key, and re-adding the admin user. - Included a new test `TestAddAdminUser` to verify the behavior of the `AddAdminUser` function in various scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLDR: Thanks, LGTM!
I have two drawbacks here:
- This solution isn't bulletproof, as the process might die before executing the
defer
statement. That being said, it is probably good enough for the majority of cases. - I'd like to implement this suggested solution to re-validate the user intent with a special flag passed to the command.
It is orthogonal to this PR, so it's not a blocker (obviously), but I believe making the command more human-error-proof can be even more valuable than the rollback implemented in this PR.
But nonetheless, this PR is net-positive, so LGTM! Thanks for working on this
@@ -174,6 +174,12 @@ func AddAdminUser(ctx context.Context, authService auth.Service, user *model.Sup | |||
if err != nil { | |||
return nil, fmt.Errorf("create user - %w", err) | |||
} | |||
defer func() { | |||
// delete admin on any error to avoid partial setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace the comment with an informative log message (info/warn imo)
# This is the 1st commit message: StorageConfigList response changes # The commit message #2 will be skipped: # Fix newConfig # The commit message #3 will be skipped: # More fixes # The commit message #4 will be skipped: # More fixes # The commit message #5 will be skipped: # Add admin/superuser error handling and cleanup (#8559) # # * Add admin/superuser error handling and cleanup # # - Added a defer function to clean up the admin user if an error occurs during creation. # - Added tests for creating an admin user, verifying successful creation, attempting to create another admin user, deleting the admin user, creating an admin user without a secret access key, and re-adding the admin user. # - Included a new test `TestAddAdminUser` to verify the behavior of the `AddAdminUser` function in various scenarios. # # * Added a logger to log the error message and warn about deleting the user # The commit message #6 will be skipped: # Add StorageID to adapter GetStorageNamespaceInfo and ResolveNamespace (#8551) # # * Add StorageID to adapter metadata functions # # * Fix tests # # * Add error handling # # * Fix tests # # * Fix lint # # * Revert "Fix lint" # # This reverts commit 850f17b. # # * Revert "Fix tests" # # This reverts commit 7bf9acc. # # * Revert "Add error handling" # # This reverts commit 9d3f0a2. # # * Revert "Fix tests" # # This reverts commit a2a4ab5. # # * Revert "Add StorageID to adapter metadata functions" # # This reverts commit 06b32ee. # # * Add storageID to metadata functions # # * Fix tests # # * Fix tests # # * Remove storageID from BlockstoreMetadata
TestAddAdminUser
to verify the behavior of theAddAdminUser
function in various scenarios.Closes #8490