From 4e4138f17f9c04c3b1667903c58c57b475cf1258 Mon Sep 17 00:00:00 2001 From: caton-hpg <87342612+caton-hpg@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:05:52 +0800 Subject: [PATCH 1/3] fix auth for scan --- include/nebula/sclient/StorageClient.h | 2 -- src/sclient/StorageClient.cpp | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/nebula/sclient/StorageClient.h b/include/nebula/sclient/StorageClient.h index d80be7c..d97f4b1 100644 --- a/include/nebula/sclient/StorageClient.h +++ b/include/nebula/sclient/StorageClient.h @@ -81,7 +81,6 @@ class StorageClient { std::string filter = "", bool onlyLatestVersion = false, bool enableReadFromFollower = true, - bool needAuth = false, const std::string& username = "", const std::string& password = ""); @@ -96,7 +95,6 @@ class StorageClient { std::string filter = "", bool onlyLatestVersion = false, bool enableReadFromFollower = true, - bool needAuth = false, const std::string& username = "", const std::string& password = ""); diff --git a/src/sclient/StorageClient.cpp b/src/sclient/StorageClient.cpp index d8b3bc5..a431fb4 100644 --- a/src/sclient/StorageClient.cpp +++ b/src/sclient/StorageClient.cpp @@ -51,7 +51,6 @@ ScanEdgeIter StorageClient::scanEdgeWithPart(std::string spaceName, std::string filter, bool onlyLatestVersion, bool enableReadFromFollower, - bool needAuth, const std::string& username, const std::string& password) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); @@ -84,7 +83,7 @@ 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_need_authenticate(true); req->set_username(username); req->set_password(password); @@ -125,7 +124,6 @@ ScanVertexIter StorageClient::scanVertexWithPart( std::string filter, bool onlyLatestVersion, bool enableReadFromFollower, - bool needAuth, const std::string& username, const std::string& password) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); @@ -164,7 +162,7 @@ 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_need_authenticate(true); req->set_username(username); req->set_password(password); From 348bc7c8b026ee2645c4d84c6b7d7f4ea13ab46a Mon Sep 17 00:00:00 2001 From: caton-hpg <87342612+caton-hpg@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:08:07 +0800 Subject: [PATCH 2/3] fix StorageClient --- examples/StorageClientExample.cpp | 53 +++++++--------------- include/nebula/sclient/StorageClient.h | 12 ++--- src/sclient/StorageClient.cpp | 21 ++++----- src/sclient/tests/StorageClientSSLTest.cpp | 2 +- src/sclient/tests/StorageClientTest.cpp | 2 +- 5 files changed, 34 insertions(+), 56 deletions(-) diff --git a/examples/StorageClientExample.cpp b/examples/StorageClientExample.cpp index 5cd3b2d..99c81da 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"}, "root", "nebula"); + + 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 d97f4b1..668762f 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,9 +82,7 @@ class StorageClient { int64_t endTime = DEFAULT_END_TIME, std::string filter = "", bool onlyLatestVersion = false, - bool enableReadFromFollower = true, - const std::string& username = "", - const std::string& password = ""); + bool enableReadFromFollower = true); ScanVertexIter scanVertexWithPart( std::string spaceName, @@ -94,9 +94,7 @@ class StorageClient { int64_t endTime = DEFAULT_END_TIME, std::string filter = "", bool onlyLatestVersion = false, - bool enableReadFromFollower = true, - const std::string& username = "", - const std::string& password = ""); + bool enableReadFromFollower = true); MetaClient* getMetaClient() { return mClient_.get(); @@ -114,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 a431fb4..5a70e57 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,9 +53,7 @@ ScanEdgeIter StorageClient::scanEdgeWithPart(std::string spaceName, int64_t endTime, std::string filter, bool onlyLatestVersion, - bool enableReadFromFollower, - const std::string& username, - const std::string& password) { + bool enableReadFromFollower) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); if (!spaceIdResult.first) { return {nullptr, nullptr, false}; @@ -84,8 +85,8 @@ ScanEdgeIter StorageClient::scanEdgeWithPart(std::string spaceName, req->set_only_latest_version(onlyLatestVersion); req->set_enable_read_from_follower(enableReadFromFollower); req->set_need_authenticate(true); - req->set_username(username); - req->set_password(password); + req->set_username(user_); + req->set_password(password_); return {this, req}; } @@ -123,9 +124,7 @@ ScanVertexIter StorageClient::scanVertexWithPart( int64_t endTime, std::string filter, bool onlyLatestVersion, - bool enableReadFromFollower, - const std::string& username, - const std::string& password) { + bool enableReadFromFollower) { auto spaceIdResult = mClient_->getSpaceIdByNameFromCache(spaceName); if (!spaceIdResult.first) { return {nullptr, nullptr, false}; @@ -163,8 +162,8 @@ ScanVertexIter StorageClient::scanVertexWithPart( req->set_only_latest_version(onlyLatestVersion); req->set_enable_read_from_follower(enableReadFromFollower); req->set_need_authenticate(true); - req->set_username(username); - req->set_password(password); + 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 bd11114..8863112 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 446fa9b..27dbc1b 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); From 4d901ab69ef21a0b0f8542cbd707bf77aed9aa82 Mon Sep 17 00:00:00 2001 From: caton-hpg <87342612+caton-hpg@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:53:38 +0800 Subject: [PATCH 3/3] default value for user and password --- examples/StorageClientExample.cpp | 2 +- include/nebula/sclient/StorageClient.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/StorageClientExample.cpp b/examples/StorageClientExample.cpp index 99c81da..b30d1c5 100644 --- a/examples/StorageClientExample.cpp +++ b/examples/StorageClientExample.cpp @@ -17,7 +17,7 @@ int main(int argc, char* argv[]) { nebula::init(&argc, &argv); - nebula::StorageClient c({"127.0.0.1:9559"}, "root", "nebula"); + nebula::StorageClient c({"127.0.0.1:9559"}); nebula::ScanEdgeIter scanEdgeIter = c.scanEdgeWithPart("nba", 1, diff --git a/include/nebula/sclient/StorageClient.h b/include/nebula/sclient/StorageClient.h index 668762f..32ef0c0 100644 --- a/include/nebula/sclient/StorageClient.h +++ b/include/nebula/sclient/StorageClient.h @@ -64,8 +64,8 @@ class StorageClient { public: explicit StorageClient(const std::vector& metaAddrs, - const std::string& user, - const std::string& password, + const std::string& user = "", + const std::string& password = "", const MConfig& mConfig = MConfig{}, const SConfig& sConfig = SConfig{});