diff --git a/examples/StorageClientExample.cpp b/examples/StorageClientExample.cpp index 5cd3b2dc..b30d1c5c 100644 --- a/examples/StorageClientExample.cpp +++ b/examples/StorageClientExample.cpp @@ -14,23 +14,21 @@ #include "common/graph/Response.h" -void scanEdge(nebula::StorageClient& c, - bool auth = false, - const std::string& username = "", - const std::string& password = "") { - auto scanEdgeIter = c.scanEdgeWithPart("nba", - 1, - "like", - std::vector{"likeness"}, - 10, - 0, - std::numeric_limits::max(), - "", - true, - true, - auth, - username, - password); +int main(int argc, char* argv[]) { + nebula::init(&argc, &argv); + + nebula::StorageClient c({"127.0.0.1:9559"}); + + nebula::ScanEdgeIter scanEdgeIter = c.scanEdgeWithPart("nba", + 1, + "like", + std::vector{"likeness"}, + 10, + 0, + std::numeric_limits::max(), + "", + true, + true); std::cout << "scan edge..." << std::endl; while (scanEdgeIter.hasNext()) { std::cout << "-------------------------" << std::endl; @@ -39,12 +37,7 @@ void scanEdge(nebula::StorageClient& c, std::cout << res.second << std::endl; std::cout << "+++++++++++++++++++++++++" << std::endl; } -} -void scanVertex(nebula::StorageClient& c, - bool auth = false, - const std::string& username = "", - const std::string& password = "") { nebula::ScanVertexIter scanVertexIter = c.scanVertexWithPart("nba", 1, @@ -54,10 +47,7 @@ void scanVertex(nebula::StorageClient& c, std::numeric_limits::max(), "", true, - true, - auth, - username, - password); + true); std::cout << "scan vertex..." << std::endl; while (scanVertexIter.hasNext()) { std::cout << "-------------------------" << std::endl; @@ -66,17 +56,6 @@ void scanVertex(nebula::StorageClient& c, std::cout << res.second << std::endl; std::cout << "+++++++++++++++++++++++++" << std::endl; } -} - -int main(int argc, char* argv[]) { - nebula::init(&argc, &argv); - nebula::StorageClient c({"127.0.0.1:9559"}); - - scanVertex(c); - scanEdge(c); - - scanVertex(c, true, "root", "nebula"); - scanEdge(c, true, "root", "nebula"); return 0; } diff --git a/include/nebula/sclient/StorageClient.h b/include/nebula/sclient/StorageClient.h index d80be7ce..32ef0c0b 100644 --- a/include/nebula/sclient/StorageClient.h +++ b/include/nebula/sclient/StorageClient.h @@ -64,6 +64,8 @@ class StorageClient { public: explicit StorageClient(const std::vector& metaAddrs, + const std::string& user = "", + const std::string& password = "", const MConfig& mConfig = MConfig{}, const SConfig& sConfig = SConfig{}); @@ -80,10 +82,7 @@ class StorageClient { int64_t endTime = DEFAULT_END_TIME, std::string filter = "", bool onlyLatestVersion = false, - bool enableReadFromFollower = true, - bool needAuth = false, - const std::string& username = "", - const std::string& password = ""); + bool enableReadFromFollower = true); ScanVertexIter scanVertexWithPart( std::string spaceName, @@ -95,10 +94,7 @@ class StorageClient { int64_t endTime = DEFAULT_END_TIME, std::string filter = "", bool onlyLatestVersion = false, - bool enableReadFromFollower = true, - bool needAuth = false, - const std::string& username = "", - const std::string& password = ""); + bool enableReadFromFollower = true); MetaClient* getMetaClient() { return mClient_.get(); @@ -116,6 +112,8 @@ class StorageClient { RemoteFunc&& remoteFunc, folly::Promise> pro); + std::string user_; + std::string password_; std::unique_ptr mClient_; SConfig sConfig_; std::shared_ptr ioExecutor_; diff --git a/src/sclient/StorageClient.cpp b/src/sclient/StorageClient.cpp index d8b3bc5f..5a70e577 100644 --- a/src/sclient/StorageClient.cpp +++ b/src/sclient/StorageClient.cpp @@ -14,8 +14,11 @@ namespace nebula { StorageClient::StorageClient(const std::vector& metaAddrs, + const std::string& user, + const std::string& password, const MConfig& mConfig, - const SConfig& sConfig) { + const SConfig& sConfig) + : user_(user), password_(password) { mClient_ = std::make_unique(metaAddrs, mConfig); sConfig_ = sConfig; ioExecutor_ = std::make_shared(std::thread::hardware_concurrency()); @@ -50,10 +53,7 @@ ScanEdgeIter StorageClient::scanEdgeWithPart(std::string spaceName, int64_t endTime, std::string filter, bool onlyLatestVersion, - bool enableReadFromFollower, - bool needAuth, - const std::string& username, - const std::string& password) { + bool enableReadFromFollower) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); if (!spaceIdResult.first) { return {nullptr, nullptr, false}; @@ -84,9 +84,9 @@ ScanEdgeIter StorageClient::scanEdgeWithPart(std::string spaceName, req->set_filter(filter); req->set_only_latest_version(onlyLatestVersion); req->set_enable_read_from_follower(enableReadFromFollower); - req->set_need_authenticate(needAuth); - req->set_username(username); - req->set_password(password); + req->set_need_authenticate(true); + req->set_username(user_); + req->set_password(password_); return {this, req}; } @@ -124,10 +124,7 @@ ScanVertexIter StorageClient::scanVertexWithPart( int64_t endTime, std::string filter, bool onlyLatestVersion, - bool enableReadFromFollower, - bool needAuth, - const std::string& username, - const std::string& password) { + bool enableReadFromFollower) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); if (!spaceIdResult.first) { return {nullptr, nullptr, false}; @@ -164,9 +161,9 @@ ScanVertexIter StorageClient::scanVertexWithPart( req->set_filter(filter); req->set_only_latest_version(onlyLatestVersion); req->set_enable_read_from_follower(enableReadFromFollower); - req->set_need_authenticate(needAuth); - req->set_username(username); - req->set_password(password); + req->set_need_authenticate(true); + req->set_username(user_); + req->set_password(password_); return {this, req}; } diff --git a/src/sclient/tests/StorageClientSSLTest.cpp b/src/sclient/tests/StorageClientSSLTest.cpp index bd111149..88631124 100644 --- a/src/sclient/tests/StorageClientSSLTest.cpp +++ b/src/sclient/tests/StorageClientSSLTest.cpp @@ -200,7 +200,7 @@ TEST_F(StorageClientTest, SSL) { prepare(); nebula::MConfig mConfig{1000, 60 * 1000, true, ""}; nebula::SConfig sConfig{1000, 60 * 1000, true, ""}; - nebula::StorageClient c({kServerHost ":9559"}, mConfig, sConfig); + nebula::StorageClient c({kServerHost ":9559"}, "root", "nebula", mConfig, sConfig); auto *m = c.getMetaClient(); LOG(INFO) << "Testing run once of meta client"; runOnce(*m); diff --git a/src/sclient/tests/StorageClientTest.cpp b/src/sclient/tests/StorageClientTest.cpp index 446fa9b6..27dbc1b0 100644 --- a/src/sclient/tests/StorageClientTest.cpp +++ b/src/sclient/tests/StorageClientTest.cpp @@ -199,7 +199,7 @@ class StorageClientTest : public SClientTest { TEST_F(StorageClientTest, Basic) { LOG(INFO) << "Prepare data."; prepare(); - nebula::StorageClient c({kServerHost ":9559"}); + nebula::StorageClient c({kServerHost ":9559"}, "root", "nebula"); auto *m = c.getMetaClient(); LOG(INFO) << "Testing run once of meta client"; runOnce(*m);