tanruixiang commented on code in PR #881:
URL: https://github.com/apache/incubator-kvrocks/pull/881#discussion_r973596441
##########
src/redis_cmd.cc:
##########
@@ -73,29 +74,47 @@ const char *errUnbalacedStreamList =
const char *errTimeoutIsNegative = "timeout is negative";
const char *errLimitOptionNotAllowed = "syntax error, LIMIT cannot be used
without the special ~ option";
+enum class AuthResult {
+ OK,
+ INVALID_PASSWORD,
+ NO_REQUIRE_PASS,
+};
+
+AuthResult AuthenticateUser(Connection *conn, Config* config, const
std::string& user_password) {
+ auto iter = config->tokens.find(user_password);
+ if (iter != config->tokens.end()) {
+ conn->SetNamespace(iter->second);
+ conn->BecomeUser();
+ return AuthResult::OK;
+ }
+ const auto& requirepass = config->requirepass;
+ if (!requirepass.empty() && user_password != requirepass) {
+ return AuthResult::INVALID_PASSWORD;
+ }
+ conn->SetNamespace(kDefaultNamespace);
+ conn->BecomeAdmin();
+ if (requirepass.empty()) {
+ return AuthResult::NO_REQUIRE_PASS;
+ }
+ return AuthResult::OK;
+}
+
Review Comment:
Hi. May I ask why do we introduce global `enum class AuthResult` and
`AuthenticateUser` function instead of putting them in classes or
corresponding constant definition files? Thank you for your contribution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]