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

Add ACL GETUSER Command Initial Implementation #959

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kevinmichaelbowersox
Copy link
Member

This PR provides the implementation of the ACL GETUSER command which is used to obtain ACL rules for a specified user. The change is accompanied by tests for the command.

The changeset includes:

  • ACL GETUSER command implementation
  • Unit Tests and ACL Test
  • Documentation

This resolves #958 where further details can be found.

Additionally a few instances of unnecessary whitespace were cleaned up.

/// Returns flags for the <see cref="User"/>.
/// </summary>
/// <returns>A <see cref="List{T}"/> of <see cref="string"/> representing flags for the user.</returns>
public List<string> GetFlags()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why allocate here? It's just switching between two constants.

/// <returns>A <see cref="List{T}"/> of <see cref="string"/> representing password hashes for the user.</returns>
public List<string> GetPasswordHashes()
{
return _passwordHashes.Select(hash => $"#{hash}").ToList();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not thread safe, _passwordHashes is mutable.

Also, there's no need to allocate here, we're just prepending a # so that can be done while writing the response out.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you onboard with making this field accessible to clients to avoid the allocations?

Copy link
Contributor

Choose a reason for hiding this comment

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

Given the thread safety concerns, I don't think exposing the field is appropriate.

while (!RespWriteUtils.TryWriteArrayLength(6, ref dcurr, dend))
SendAndReset();

var flags = user.GetFlags();
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 broadly this will run into issues if the user is modified while the command is running.

GetFlags(), GetPasswordHashes(), and GetEnabledCommandsDescription() won't necessarily return consistent results.

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 see that enabledCommands has a copy method. What are your thoughts on returning a copy of the commands back to the client to avoid any issues with modifications?

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 some variant of "one method (that internally takes appropriate) locks, and copies the relevant data into the return"-is the only path forward.

I'd be tempted to try and fit things into Span's created by the caller to avoid allocations (or rent some arrays, or something), so the there's some flexibility in the implementation.

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.

Add Support for ACL GETUSER Command
2 participants