| 172 | explicit AuthCommandHandler(RedisServiceImpl* rsimpl) |
| 173 | : _rsimpl(rsimpl) {} |
| 174 | brpc::RedisCommandHandlerResult Run(brpc::RedisConnContext* ctx, |
| 175 | const std::vector<butil::StringPiece>& args, |
| 176 | brpc::RedisReply* output, |
| 177 | bool /*flush_batched*/) override { |
| 178 | if (args.size() != 3ul) { |
| 179 | output->FormatError("Expect 2 args for 'auth', actually %lu", args.size()-1); |
| 180 | return brpc::REDIS_CMD_HANDLED; |
| 181 | } |
| 182 | |
| 183 | const std::string db_name(args[1].data(), args[1].size()); |
| 184 | const std::string password(args[2].data(), args[2].size()); |
| 185 | |
| 186 | if (_rsimpl->Auth(db_name, password)) { |
| 187 | output->SetStatus("OK"); |
| 188 | auto auth_session = new AuthSession(db_name, password); |
| 189 | ctx->reset_session(auth_session); |
| 190 | } else { |
| 191 | output->FormatError("Invalid password for database '%s'", db_name.c_str()); |
| 192 | } |
| 193 | return brpc::REDIS_CMD_HANDLED; |
| 194 | } |
| 195 | |
| 196 | private: |
| 197 | RedisServiceImpl* _rsimpl; |
nothing calls this directly
no test coverage detected