Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate for scan-part1 #133

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 68 additions & 45 deletions examples/StorageClientExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,80 @@
* This source code is licensed under Apache 2.0 License.
*/

#include <common/Init.h>
#include <nebula/sclient/ScanEdgeIter.h>
#include <nebula/sclient/StorageClient.h>

#include <atomic>
#include <chrono>
#include <limits>
#include <thread>

#include <nebula/sclient/ScanEdgeIter.h>
#include <common/Init.h>
#include <nebula/sclient/StorageClient.h>
#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<std::string>{"likeness"},
10,
0,
std::numeric_limits<int64_t>::max(),
"",
true,
true,
auth,
username,
password);
std::cout << "scan edge..." << std::endl;
while (scanEdgeIter.hasNext()) {
std::cout << "-------------------------" << std::endl;
std::pair<nebula::ErrorCode, nebula::DataSet> res = scanEdgeIter.next();
std::cout << res.first << std::endl;
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,
{{"player", std::vector<std::string>{"name"}}},
10,
0,
std::numeric_limits<int64_t>::max(),
"",
true,
true,
auth,
username,
password);
std::cout << "scan vertex..." << std::endl;
while (scanVertexIter.hasNext()) {
std::cout << "-------------------------" << std::endl;
std::pair<nebula::ErrorCode, nebula::DataSet> res = scanVertexIter.next();
std::cout << res.first << std::endl;
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"});

nebula::ScanEdgeIter scanEdgeIter = c.scanEdgeWithPart("nba",
1,
"like",
std::vector<std::string>{"likeness"},
10,
0,
std::numeric_limits<int64_t>::max(),
"",
true,
true);
std::cout << "scan edge..." << std::endl;
while (scanEdgeIter.hasNext()) {
std::cout << "-------------------------" << std::endl;
std::pair<nebula::ErrorCode, nebula::DataSet> res = scanEdgeIter.next();
std::cout << res.first << std::endl;
std::cout << res.second << std::endl;
std::cout << "+++++++++++++++++++++++++" << std::endl;
}

nebula::ScanVertexIter scanVertexIter = c.scanVertexWithPart("nba",
1,
{{"player", std::vector<std::string>{"name"}}},
10,
0,
std::numeric_limits<int64_t>::max(),
"",
true,
true);
std::cout << "scan vertex..." << std::endl;
while (scanVertexIter.hasNext()) {
std::cout << "-------------------------" << std::endl;
std::pair<nebula::ErrorCode, nebula::DataSet> res = scanVertexIter.next();
std::cout << res.first << std::endl;
std::cout << res.second << std::endl;
std::cout << "+++++++++++++++++++++++++" << std::endl;
}

return 0;
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;
}
16 changes: 11 additions & 5 deletions include/nebula/sclient/StorageClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

#include "ScanEdgeIter.h"
#include "common/datatypes/HostAddr.h"
#include "common/graph/Response.h"
#include "common/thrift/ThriftTypes.h"
#include "nebula/mclient/MetaClient.h"
#include "nebula/sclient/SConfig.h"
#include "nebula/sclient/ScanEdgeIter.h"
#include "nebula/sclient/ScanVertexIter.h"
#include "common/graph/Response.h"

namespace folly {
class IOThreadPoolExecutor;
Expand Down Expand Up @@ -69,7 +69,7 @@ class StorageClient {

~StorageClient();

std::vector<PartitionID> getParts(const std::string& spaceName); // plato needed
std::vector<PartitionID> getParts(const std::string& spaceName);

ScanEdgeIter scanEdgeWithPart(std::string spaceName,
int32_t partID,
Expand All @@ -80,7 +80,10 @@ class StorageClient {
int64_t endTime = DEFAULT_END_TIME,
std::string filter = "",
bool onlyLatestVersion = false,
bool enableReadFromFollower = true); // plato needed
bool enableReadFromFollower = true,
bool needAuth = false,
const std::string& username = "",
const std::string& password = "");

ScanVertexIter scanVertexWithPart(
std::string spaceName,
Expand All @@ -92,7 +95,10 @@ class StorageClient {
int64_t endTime = DEFAULT_END_TIME,
std::string filter = "",
bool onlyLatestVersion = false,
bool enableReadFromFollower = true); // plato needed
bool enableReadFromFollower = true,
bool needAuth = false,
const std::string& username = "",
const std::string& password = "");

MetaClient* getMetaClient() {
return mClient_.get();
Expand All @@ -106,7 +112,7 @@ class StorageClient {
const storage::cpp2::ScanVertexRequest& req);

template <typename Request, typename RemoteFunc, typename Response>
void getResponse(std::pair<HostAddr, Request>&& request,
void getResponse(std::pair<HostAddr, Request>&& request,
RemoteFunc&& remoteFunc,
folly::Promise<std::pair<::nebula::ErrorCode, Response>> pro);

Expand Down
1 change: 1 addition & 0 deletions src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ enum ErrorCode {
E_PRIVILEGE_NOT_EXIST = -2037, // remove un-exist privilege[only ent]
E_PRIVILEGE_NEED_BASIC_ROLE = -2038, // only basic role support tag/edge privilege[only ent]
E_PRIVILEGE_ACTION_INVALID = -2039, // only add and drop now.[only ent]
E_STORAGE_ENABLE_AUTH = -2058, // Storage has enable auth, but the request disable auth.[only ent]

// Admin Failure
E_SNAPSHOT_FAILURE = -2040, // Failed to generate a snapshot
Expand Down
6 changes: 4 additions & 2 deletions src/interface/gen-cpp2/common_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const std::array<folly::StringPiece, 17> TEnumDataStorage<::nebula::cpp2::Proper
"GEOGRAPHY",
}};

const std::array<::nebula::cpp2::ErrorCode, 196> TEnumDataStorage<::nebula::cpp2::ErrorCode>::values = {{
const std::array<::nebula::cpp2::ErrorCode, 197> TEnumDataStorage<::nebula::cpp2::ErrorCode>::values = {{
type::SUCCEEDED,
type::E_DISCONNECTED,
type::E_FAIL_TO_CONNECT,
Expand Down Expand Up @@ -157,6 +157,7 @@ const std::array<::nebula::cpp2::ErrorCode, 196> TEnumDataStorage<::nebula::cpp2
type::E_PRIVILEGE_NOT_EXIST,
type::E_PRIVILEGE_NEED_BASIC_ROLE,
type::E_PRIVILEGE_ACTION_INVALID,
type::E_STORAGE_ENABLE_AUTH,
type::E_SNAPSHOT_FAILURE,
type::E_SNAPSHOT_RUNNING_JOBS,
type::E_SNAPSHOT_NOT_FOUND,
Expand Down Expand Up @@ -270,7 +271,7 @@ const std::array<::nebula::cpp2::ErrorCode, 196> TEnumDataStorage<::nebula::cpp2
type::E_STORAGE_MEMORY_EXCEEDED,
type::E_UNKNOWN,
}};
const std::array<folly::StringPiece, 196> TEnumDataStorage<::nebula::cpp2::ErrorCode>::names = {{
const std::array<folly::StringPiece, 197> TEnumDataStorage<::nebula::cpp2::ErrorCode>::names = {{
"SUCCEEDED",
"E_DISCONNECTED",
"E_FAIL_TO_CONNECT",
Expand Down Expand Up @@ -355,6 +356,7 @@ const std::array<folly::StringPiece, 196> TEnumDataStorage<::nebula::cpp2::Error
"E_PRIVILEGE_NOT_EXIST",
"E_PRIVILEGE_NEED_BASIC_ROLE",
"E_PRIVILEGE_ACTION_INVALID",
"E_STORAGE_ENABLE_AUTH",
"E_SNAPSHOT_FAILURE",
"E_SNAPSHOT_RUNNING_JOBS",
"E_SNAPSHOT_NOT_FOUND",
Expand Down
2 changes: 1 addition & 1 deletion src/interface/gen-cpp2/common_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template <> struct TEnumDataStorage<::nebula::cpp2::PropertyType> {

template <> struct TEnumDataStorage<::nebula::cpp2::ErrorCode> {
using type = ::nebula::cpp2::ErrorCode;
static constexpr const std::size_t size = 196;
static constexpr const std::size_t size = 197;
static const std::array<type, size> values;
static const std::array<folly::StringPiece, size> names;
};
Expand Down
3 changes: 2 additions & 1 deletion src/interface/gen-cpp2/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ enum class ErrorCode {
E_PRIVILEGE_NOT_EXIST = -2037,
E_PRIVILEGE_NEED_BASIC_ROLE = -2038,
E_PRIVILEGE_ACTION_INVALID = -2039,
E_STORAGE_ENABLE_AUTH = -2058,
E_SNAPSHOT_FAILURE = -2040,
E_SNAPSHOT_RUNNING_JOBS = -2056,
E_SNAPSHOT_NOT_FOUND = -2057,
Expand Down Expand Up @@ -745,7 +746,7 @@ template <> struct TEnumDataStorage<::nebula::cpp2::ErrorCode>;
template <> struct TEnumTraits<::nebula::cpp2::ErrorCode> {
using type = ::nebula::cpp2::ErrorCode;

static constexpr std::size_t const size = 196;
static constexpr std::size_t const size = 197;
static folly::Range<type const*> const values;
static folly::Range<folly::StringPiece const*> const names;

Expand Down
30 changes: 24 additions & 6 deletions src/interface/gen-cpp2/storage_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ const std::array<protocol::TType, 1> TStructDataStorage<::nebula::storage::cpp2:
TType::T_STRING,
}};

const std::array<folly::StringPiece, 10> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_names = {{
const std::array<folly::StringPiece, 13> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_names = {{
"space_id",
"parts",
"return_columns",
Expand All @@ -787,8 +787,11 @@ const std::array<folly::StringPiece, 10> TStructDataStorage<::nebula::storage::c
"only_latest_version",
"enable_read_from_follower",
"common",
"username",
"password",
"need_authenticate",
}};
const std::array<int16_t, 10> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_ids = {{
const std::array<int16_t, 13> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_ids = {{
1,
2,
3,
Expand All @@ -799,8 +802,11 @@ const std::array<int16_t, 10> TStructDataStorage<::nebula::storage::cpp2::ScanVe
8,
9,
10,
11,
12,
13,
}};
const std::array<protocol::TType, 10> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_types = {{
const std::array<protocol::TType, 13> TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest>::fields_types = {{
TType::T_I32,
TType::T_MAP,
TType::T_LIST,
Expand All @@ -811,9 +817,12 @@ const std::array<protocol::TType, 10> TStructDataStorage<::nebula::storage::cpp2
TType::T_BOOL,
TType::T_BOOL,
TType::T_STRUCT,
TType::T_STRING,
TType::T_STRING,
TType::T_BOOL,
}};

const std::array<folly::StringPiece, 10> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_names = {{
const std::array<folly::StringPiece, 13> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_names = {{
"space_id",
"parts",
"return_columns",
Expand All @@ -824,8 +833,11 @@ const std::array<folly::StringPiece, 10> TStructDataStorage<::nebula::storage::c
"only_latest_version",
"enable_read_from_follower",
"common",
"username",
"password",
"need_authenticate",
}};
const std::array<int16_t, 10> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_ids = {{
const std::array<int16_t, 13> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_ids = {{
1,
2,
3,
Expand All @@ -836,8 +848,11 @@ const std::array<int16_t, 10> TStructDataStorage<::nebula::storage::cpp2::ScanEd
8,
9,
10,
11,
12,
13,
}};
const std::array<protocol::TType, 10> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_types = {{
const std::array<protocol::TType, 13> TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest>::fields_types = {{
TType::T_I32,
TType::T_MAP,
TType::T_LIST,
Expand All @@ -848,6 +863,9 @@ const std::array<protocol::TType, 10> TStructDataStorage<::nebula::storage::cpp2
TType::T_BOOL,
TType::T_BOOL,
TType::T_STRUCT,
TType::T_STRING,
TType::T_STRING,
TType::T_BOOL,
}};

const std::array<folly::StringPiece, 3> TStructDataStorage<::nebula::storage::cpp2::ScanResponse>::fields_names = {{
Expand Down
4 changes: 2 additions & 2 deletions src/interface/gen-cpp2/storage_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ template <> struct TStructDataStorage<::nebula::storage::cpp2::ScanCursor> {
};

template <> struct TStructDataStorage<::nebula::storage::cpp2::ScanVertexRequest> {
static constexpr const std::size_t fields_size = 10;
static constexpr const std::size_t fields_size = 13;
static const std::array<folly::StringPiece, fields_size> fields_names;
static const std::array<int16_t, fields_size> fields_ids;
static const std::array<protocol::TType, fields_size> fields_types;
};

template <> struct TStructDataStorage<::nebula::storage::cpp2::ScanEdgeRequest> {
static constexpr const std::size_t fields_size = 10;
static constexpr const std::size_t fields_size = 13;
static const std::array<folly::StringPiece, fields_size> fields_names;
static const std::array<int16_t, fields_size> fields_ids;
static const std::array<protocol::TType, fields_size> fields_types;
Expand Down
6 changes: 6 additions & 0 deletions src/interface/gen-cpp2/storage_for_each_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ struct ForEachField<::nebula::storage::cpp2::ScanVertexRequest> {
f(7, static_cast<T&&>(t).only_latest_version_ref()...);
f(8, static_cast<T&&>(t).enable_read_from_follower_ref()...);
f(9, static_cast<T&&>(t).common_ref()...);
f(10, static_cast<T&&>(t).username_ref()...);
f(11, static_cast<T&&>(t).password_ref()...);
f(12, static_cast<T&&>(t).need_authenticate_ref()...);
}
};

Expand All @@ -463,6 +466,9 @@ struct ForEachField<::nebula::storage::cpp2::ScanEdgeRequest> {
f(7, static_cast<T&&>(t).only_latest_version_ref()...);
f(8, static_cast<T&&>(t).enable_read_from_follower_ref()...);
f(9, static_cast<T&&>(t).common_ref()...);
f(10, static_cast<T&&>(t).username_ref()...);
f(11, static_cast<T&&>(t).password_ref()...);
f(12, static_cast<T&&>(t).need_authenticate_ref()...);
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/interface/gen-cpp2/storage_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,9 @@ StructMetadata<::nebula::storage::cpp2::ScanVertexRequest>::gen(ThriftMetadata&
std::make_tuple(8, "only_latest_version", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(9, "enable_read_from_follower", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(10, "common", true, std::make_unique<Struct< ::nebula::storage::cpp2::RequestCommon>>("storage.RequestCommon"), std::vector<ThriftConstStruct>{}),
std::make_tuple(11, "username", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BINARY_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(12, "password", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BINARY_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(13, "need_authenticate", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
};
for (const auto& f : storage_ScanVertexRequest_fields) {
::apache::thrift::metadata::ThriftField field;
Expand Down Expand Up @@ -1176,6 +1179,9 @@ StructMetadata<::nebula::storage::cpp2::ScanEdgeRequest>::gen(ThriftMetadata& me
std::make_tuple(8, "only_latest_version", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(9, "enable_read_from_follower", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(10, "common", true, std::make_unique<Struct< ::nebula::storage::cpp2::RequestCommon>>("storage.RequestCommon"), std::vector<ThriftConstStruct>{}),
std::make_tuple(11, "username", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BINARY_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(12, "password", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BINARY_TYPE), std::vector<ThriftConstStruct>{}),
std::make_tuple(13, "need_authenticate", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_BOOL_TYPE), std::vector<ThriftConstStruct>{}),
};
for (const auto& f : storage_ScanEdgeRequest_fields) {
::apache::thrift::metadata::ThriftField field;
Expand Down
Loading
Loading