MCPcopy Create free account
hub / github.com/apache/brpc / authenticateAll

Method authenticateAll

src/brpc/couchbase.cpp:2192–2280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2190}
2191
2192CouchbaseOperations::Result CouchbaseOperations::authenticateAll(
2193 const std::string& username, const std::string& password,
2194 const std::string& server_address, const std::string& bucket_name, bool enable_ssl,
2195 std::string path_to_cert) {
2196 // Create a channel to the Couchbase server
2197 brpc::ChannelOptions options;
2198 options.protocol = brpc::PROTOCOL_COUCHBASE;
2199 options.connection_type = "single";
2200 options.timeout_ms = 1000; // 1 second
2201 options.max_retry = 3;
2202
2203 // CRITICAL: Set unique connection_group to prevent connection sharing
2204 // Each CouchbaseOperations instance connected to same bucket gets its own
2205 // connection group
2206 options.connection_group = server_address + bucket_name;
2207
2208 // enable_ssl
2209 if (enable_ssl) {
2210 brpc::ChannelSSLOptions* ssl_options = options.mutable_ssl_options();
2211 ssl_options->sni_name = server_address;
2212 ssl_options->verify.verify_depth =
2213 1; // Enable certificate verification, to disable SSL set it to 0
2214 ssl_options->verify.ca_file_path =
2215 path_to_cert; // Path to your downloaded TLS certificate
2216 }
2217 CouchbaseOperations::Result result;
2218 brpc::Channel* new_channel = new brpc::Channel();
2219 if (new_channel->Init(server_address.c_str(), &options) != 0) {
2220 DEBUG_PRINT("Failed to initialize Couchbase channel to " << server_address);
2221 delete new_channel;
2222 result.success = false;
2223 result.value = "";
2224 result.error_message = "Failed to initialize Couchbase channel";
2225 return result;
2226 }
2227 // Create a CouchbaseRequest and CouchbaseResponse for authentication
2228 CouchbaseRequest request;
2229 CouchbaseResponse response;
2230 brpc::Controller cntl;
2231 if (request.authenticateRequest(username.c_str(), password.c_str()) ==
2232 false) {
2233 DEBUG_PRINT("Failed to create Authenticate request for user: " << username);
2234 delete new_channel;
2235 result.success = false;
2236 return result;
2237 }
2238 new_channel->CallMethod(NULL, &cntl, &request, &response, NULL);
2239 if (cntl.Failed()) {
2240 DEBUG_PRINT("Failed to access Couchbase: " << cntl.ErrorText());
2241 delete new_channel;
2242 result.success = false;
2243 result.value = "";
2244 result.error_message = cntl.ErrorText();
2245 return result;
2246 }
2247 uint64_t cas;
2248 if (response.popHello(&cas) == false) {
2249 DEBUG_PRINT("Failed to receive HELO response from Couchbase: "

Callers

nothing calls this directly

Calls 9

authenticateRequestMethod · 0.80
ErrorTextMethod · 0.80
popHelloMethod · 0.80
popAuthenticateMethod · 0.80
mutable_ssl_optionsMethod · 0.45
InitMethod · 0.45
c_strMethod · 0.45
CallMethodMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected