Skip to content

Commit

Permalink
User manager of Meta Server
Browse files Browse the repository at this point in the history
  • Loading branch information
boshengchen committed Jun 3, 2019
1 parent c50426e commit e7e0424
Show file tree
Hide file tree
Showing 18 changed files with 1,324 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/common/base/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Status final {
STATUS_GENERATOR(HostNotFound);
STATUS_GENERATOR(TagNotFound);
STATUS_GENERATOR(EdgeNotFound);
STATUS_GENERATOR(UserNotFound);

#undef STATUS_GENERATOR

Expand All @@ -128,6 +129,7 @@ class Status final {
kHostNotFound = 405,
kTagNotFound = 406,
kEdgeNotFound = 407,
kUserNotFound = 408,
};

Code code() const {
Expand Down
1 change: 1 addition & 0 deletions src/common/base/ThriftTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using EdgeType = int32_t;
using EdgeRanking = int64_t;
using EdgeVersion = int64_t;
using SchemaVer = int64_t;
using UserID = int32_t;

} // namespace nebula
#endif // COMMON_BASE_THRIFTTYPES_H_
Expand Down
1 change: 1 addition & 0 deletions src/daemons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ add_executable(
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:dataman_obj>
)
nebula_link_libraries(
nebula-metad
Expand Down
2 changes: 2 additions & 0 deletions src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef i32 (cpp.type = "nebula::Port") Port

typedef i64 (cpp.type = "nebula::SchemaVer") SchemaVer

typedef i32 (cpp.type = "nebula::UserID") UserID

// These are all data types supported in the graph properties
enum SupportedType {
UNKNOWN = 0,
Expand Down
97 changes: 97 additions & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ enum ErrorCode {
E_STORE_FAILURE = -31,
E_STORE_SEGMENT_ILLEGAL = -32,

E_INVALID_PASSWORD = -41,
E_INPROPER_ROLE = -42,

E_UNKNOWN = -99,
} (cpp.enum_strict)

Expand All @@ -43,10 +46,19 @@ enum AlterSchemaOp {
} (cpp.enum_strict)


enum RoleType {
GOD = 0x01,
ADMIN = 0x02,
USER = 0x03,
GUEST = 0x04,
} (cpp.enum_strict)


union ID {
1: common.GraphSpaceID space_id,
2: common.TagID tag_id,
3: common.EdgeType edge_type,
4: common.UserID user_id,
}

struct IdName {
Expand Down Expand Up @@ -89,6 +101,22 @@ struct EdgeItem {
4: common.Schema schema,
}



struct UserItem {
1: string account,
2: string first_name,
3: string last_name,
4: string email,
5: string phone,
}

struct RoleItem {
1: string account,
2: string space,
3: RoleType RoleType,
}

struct ExecResp {
1: ErrorCode code,
// For custom kv operations, it is useless.
Expand Down Expand Up @@ -300,6 +328,63 @@ struct HBReq {
1: common.HostAddr host,
}

struct CreateUserReq {
1: UserItem user,
2: string encoded_pwd,
3: bool missing_ok,
}

struct DropUserReq {
1: string account,
2: bool missing_ok,
}

struct AlterUserReq {
1: UserItem user_item,
}

struct GrantRoleReq {
1: RoleItem role_item,
}

struct RevokeRoleReq {
1: RoleItem role_item,
}

struct GetUserReq {
1: string account,
}

struct GetUserResp {
1: UserItem user_item,
}

struct ListUsersReq {
}

struct ListUsersResp {
1: list<UserItem> users,
}

struct ListRolesReq {
1: string space,
}

struct ListRolesResp {
1: list<RoleItem> roles,
}

struct ChangePasswordReq {
1: string account,
2: string new_encoded_pwd,
3: string old_encoded_pwd,
}

struct CheckPasswordReq {
1: string account,
2: string encoded_pwd,
}

service MetaService {
ExecResp createSpace(1: CreateSpaceReq req);
ExecResp dropSpace(1: DropSpaceReq req);
Expand Down Expand Up @@ -332,5 +417,17 @@ service MetaService {
ScanResp scan(1: ScanReq req);

HBResp heartBeat(1: HBReq req);

ExecResp createUser(1: CreateUserReq req);
ExecResp dropUser(1: DropUserReq req);
ExecResp alterUser(1: AlterUserReq req);
ExecResp grantRole(1: GrantRoleReq req);
ExecResp revokeRole(1: RevokeRoleReq req);
GetUserResp getUser(1: GetUserReq req);
ListUsersResp listUsers(1: ListUsersReq req);
ListRolesResp listRoles(1: ListRolesReq req);
ExecResp changePassword(1: ChangePasswordReq req);
ExecResp checkPassword(1: CheckPasswordReq req);

}

2 changes: 2 additions & 0 deletions src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_library(
processors/customKV/RemoveRangeProcessor.cpp
processors/customKV/ScanProcessor.cpp
processors/admin/HBProcessor.cpp
processors/usersMan/AuthenticationProcessor.cpp
)
add_dependencies(
meta_service_handler
Expand All @@ -45,6 +46,7 @@ add_dependencies(
kvstore_obj
thread_obj
stats_obj
dataman_obj
)

add_library(
Expand Down
61 changes: 61 additions & 0 deletions src/meta/MetaServiceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "meta/processors/customKV/RemoveProcessor.h"
#include "meta/processors/customKV/RemoveRangeProcessor.h"
#include "meta/processors/admin/HBProcessor.h"
#include "meta/processors/usersMan/AuthenticationProcessor.h"

#define RETURN_FUTURE(processor) \
auto f = processor->getFuture(); \
Expand Down Expand Up @@ -190,5 +191,65 @@ MetaServiceHandler::future_heartBeat(const cpp2::HBReq& req) {
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_createUser(const cpp2::CreateUserReq& req) {
auto* processor = CreateUserProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_dropUser(const cpp2::DropUserReq& req) {
auto* processor = DropUserProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_alterUser(const cpp2::AlterUserReq& req) {
auto* processor = AlterUserProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_grantRole(const cpp2::GrantRoleReq& req) {
auto* processor = GrantProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_revokeRole(const cpp2::RevokeRoleReq& req) {
auto* processor = RevokeProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::GetUserResp>
MetaServiceHandler::future_getUser(const cpp2::GetUserReq& req) {
auto* processor = GetUserProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ListUsersResp>
MetaServiceHandler::future_listUsers(const cpp2::ListUsersReq& req) {
auto* processor = ListUsersProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ListRolesResp>
MetaServiceHandler::future_listRoles(const cpp2::ListRolesReq& req) {
auto* processor = ListRolesProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_changePassword(const cpp2::ChangePasswordReq& req) {
auto* processor = ChangePasswordProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

folly::Future<cpp2::ExecResp>
MetaServiceHandler::future_checkPassword(const cpp2::CheckPasswordReq& req) {
auto* processor = CheckPasswordProcessor::instance(kvstore_);
RETURN_FUTURE(processor);
}

} // namespace meta
} // namespace nebula
33 changes: 33 additions & 0 deletions src/meta/MetaServiceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf {
folly::Future<cpp2::HBResp>
future_heartBeat(const cpp2::HBReq& req) override;

/**
* User manager
**/
folly::Future<cpp2::ExecResp>
future_createUser(const cpp2::CreateUserReq& req) override;

folly::Future<cpp2::ExecResp>
future_dropUser(const cpp2::DropUserReq& req) override;

folly::Future<cpp2::ExecResp>
future_alterUser(const cpp2::AlterUserReq& req) override;

folly::Future<cpp2::ExecResp>
future_grantRole(const cpp2::GrantRoleReq& req) override;

folly::Future<cpp2::ExecResp>
future_revokeRole(const cpp2::RevokeRoleReq& req) override;

folly::Future<cpp2::GetUserResp>
future_getUser(const cpp2::GetUserReq& req) override;

folly::Future<cpp2::ListUsersResp>
future_listUsers(const cpp2::ListUsersReq& req) override;

folly::Future<cpp2::ListRolesResp>
future_listRoles(const cpp2::ListRolesReq& req) override;

folly::Future<cpp2::ExecResp>
future_changePassword(const cpp2::ChangePasswordReq& req) override;

folly::Future<cpp2::ExecResp>
future_checkPassword(const cpp2::CheckPasswordReq& req) override;

private:
kvstore::KVStore* kvstore_ = nullptr;
};
Expand Down
Loading

0 comments on commit e7e0424

Please sign in to comment.