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

FEATURE: Option to add an username to the RedisBackend configuration #3347

Closed
wants to merge 1 commit into from

Conversation

vcg-development
Copy link

Redis has support for authentication which supplies an username+password combination. This PR extends the current RedisBackend so that an username can be supplied in addition to the password. The underlying library already the authentication, hence it simply needs to be configured and passed.

Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

Thanks! Some kind of test would be great… Then again, I am not sure we even test the password functionality. 🙄

@kdambekalns kdambekalns requested a review from robertlemke May 2, 2024 20:15
Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

👍 by 👀

@kdambekalns
Copy link
Member

Two more things that would be great:

  • bring this into Flow 8.4
  • document the username option in Neos.Flow/Documentation/TheDefinitiveGuide/PartIII/Caching.rst

@@ -535,7 +543,8 @@ private function getRedisClient(): \Redis
}
}

if ($this->password !== '' && !$redis->auth($this->password)) {
$credentials = array_values(array_filter([$this->username, $this->password]));
Copy link
Member

@robertlemke robertlemke Sep 6, 2024

Choose a reason for hiding this comment

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

I'd suggest to make this code a bit more readable – as not everyone is familiar with array_filter() and the fact that $redis->auth() accepts both a string or an array (see docs).

Also, I'd prefer strict comparisons over weak ones like `empty()'.

How about something like this?

        if ($this->username !== '' && $this->password !== '') {
            $result = $redis->auth([$this->username, $this->password]);
            if ($result === false) {
                throw new CacheException(sprintf('Redis authentication failed, using username "%s" and a %s bytes long password.', $this->username, strlen($this->password)), 1725607160);
            }
        } elseif ($this->password !== '') {
            $result = $redis->auth($this->password);
            if ($result === false) {
                throw new CacheException(sprintf('Redis authentication failed, using a %s bytes long password.', strlen($this->password)), 1502366200);
            }
        } else {
            $result = $redis->auth();
            if ($result === false) {
                throw new CacheException('Redis authentication with empty password failed.', 1725607324);
            }
        }

@vcg-development
Copy link
Author

Thx for the feedback. I will re-open a merge request for flow 8.4 with the suggested changes this afternoon :).

@robertlemke
Copy link
Member

Thanks for taking care, I'm happy that we'll have that new feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants