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

feat: add user and privilege proto definition #2645

Merged
merged 8 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
134 changes: 134 additions & 0 deletions proto/user.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
syntax = "proto3";

package user;

import "common.proto";

option optimize_for = SPEED;

/// AuthInfo is the information required to login to a server.
message AuthInfo {
enum EncryptionType {
UNKNOWN = 0;
PLAINTEXT = 1;
SHA256 = 2;
MD5 = 3;
}
EncryptionType encryption_type = 1;
bytes encrypted_value = 2;
}

/// User defines a user in the system.
message UserInfo {
uint32 id = 1;
string name = 2;
bool is_supper = 3;
bool can_create_db = 4;
bool can_login = 5;
AuthInfo auth_info = 6;

/// Granted privileges will be only updated through the command of GRANT/REVOKE.
repeated GrantPrivilege privileges = 7;
}

/// GrantPrivilege defines a privilege granted to a user.
message GrantPrivilege {
message GrantDatabase {
uint32 database_id = 1;
}

message GrantSchema {
uint32 database_id = 1;
uint32 schema_id = 2;
}

message GrantTable {
uint32 database_id = 1;
uint32 schema_id = 2;
uint32 table_id = 3;
}

/// To support grant privilege on ALL TABLES IN SCHEMA schema_name.
message GrantAllTables {
uint32 database_id = 1;
uint32 schema_id = 2;
}

enum Privilege {
UNKNOWN = 0;
SELECT = 1;
INSERT = 2;
UPDATE = 3;
DELETE = 4;
CREATE = 5;
CONNECT = 6;
ALL = 20;
}
oneof target {
GrantDatabase grant_database = 1;
GrantSchema grant_schema = 2;
GrantTable grant_table = 3;
GrantAllTables grant_all_tables = 4;
}
repeated Privilege privileges = 5;
bool with_grant_option = 6;
}

message CreateUserRequest {
UserInfo user = 1;
}

message CreateUserResponse {
common.Status status = 1;
uint32 user_id = 2;
uint64 version = 3;
}

message UpdateUserRequest {
UserInfo user = 1;
}

message UpdateUserResponse {
common.Status status = 1;
uint64 version = 2;
}

message DropUserRequest {
uint32 user_id = 1;
}

message DropUserResponse {
common.Status status = 1;
uint64 version = 2;
}

message GrantPrivilegeRequest {
uint32 user_id = 1;
GrantPrivilege privilege = 2;
}

message GrantPrivilegeResponse {
common.Status status = 1;
uint64 version = 2;
}

message RevokePrivilegeRequest {
uint32 user_id = 1;
GrantPrivilege privilege = 2;
}

message RevokePrivilegeResponse {
common.Status status = 1;
uint64 version = 2;
}

service UserService {
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse);
yezizp2012 marked this conversation as resolved.
Show resolved Hide resolved
rpc DropUser(DropUserRequest) returns (DropUserResponse);

/// GrantPrivilege grants a privilege to a user.
rpc GrantPrivilege(GrantPrivilegeRequest) returns (GrantPrivilegeResponse);
/// RevokePrivilege revokes a privilege from a user.
rpc RevokePrivilege(RevokePrivilegeRequest) returns (RevokePrivilegeResponse);
}
1 change: 1 addition & 0 deletions src/prost/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"stream_plan",
"stream_service",
"hummock",
"user",
];
let protos: Vec<String> = proto_files
.iter()
Expand Down
5 changes: 5 additions & 0 deletions src/prost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub mod stream_plan;
pub mod stream_service;
#[rustfmt::skip]
pub mod hummock;
#[rustfmt::skip]
pub mod user;

#[rustfmt::skip]
#[path = "catalog.serde.rs"]
Expand Down Expand Up @@ -61,6 +63,9 @@ pub mod stream_service_serde;
#[rustfmt::skip]
#[path = "hummock.serde.rs"]
pub mod hummock_serde;
#[rustfmt::skip]
#[path = "user.serde.rs"]
pub mod user_serde;


#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down