/src/brpc/src/brpc/policy/redis_authenticator.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "brpc/policy/redis_authenticator.h" |
19 | | |
20 | | #include "butil/base64.h" |
21 | | #include "butil/iobuf.h" |
22 | | #include "butil/string_printf.h" |
23 | | #include "butil/sys_byteorder.h" |
24 | | #include "brpc/redis_command.h" |
25 | | |
26 | | namespace brpc { |
27 | | namespace policy { |
28 | | |
29 | 0 | int RedisAuthenticator::GenerateCredential(std::string* auth_str) const { |
30 | 0 | butil::IOBuf buf; |
31 | 0 | if (!passwd_.empty()) { |
32 | 0 | brpc::RedisCommandFormat(&buf, "AUTH %s", passwd_.c_str()); |
33 | 0 | } |
34 | 0 | if (db_ >= 0) { |
35 | 0 | brpc::RedisCommandFormat(&buf, "SELECT %d", db_); |
36 | 0 | } |
37 | 0 | *auth_str = buf.to_string(); |
38 | 0 | return 0; |
39 | 0 | } |
40 | | |
41 | | } // namespace policy |
42 | | } // namespace brpc |