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 Object Table for Authz in __INTERNAL_DB #3804

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/nameserver/name_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5560,6 +5560,10 @@ void NameServerImpl::OnLocked() {
CreateSystemTableOrExit(SystemTableType::kUser);
}

if (FLAGS_system_table_replica_num > 0 && db_table_info_[INTERNAL_DB].count(OBJECT_INFO_NAME) == 0) {
CreateSystemTableOrExit(SystemTableType::kObject);
}

if (FLAGS_system_table_replica_num > 0 && db_table_info_[INTERNAL_DB].count(PRE_AGG_META_NAME) == 0) {
CreateSystemTableOrExit(SystemTableType::kPreAggMetaInfo);
}
Expand Down
1 change: 1 addition & 0 deletions src/nameserver/system_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static absl::flat_hash_map<SystemTableType, SystemTableInfo const> CreateSystemT
{SystemTableType::kGlobalVariable, {INFORMATION_SCHEMA_DB, GLOBAL_VARIABLES}},
{SystemTableType::kDeployResponseTime, {INFORMATION_SCHEMA_DB, DEPLOY_RESPONSE_TIME}},
{SystemTableType::kUser, {INTERNAL_DB, USER_INFO_NAME}},
{SystemTableType::kObject, {INTERNAL_DB, OBJECT_INFO_NAME}},
};
return map;
}
Expand Down
25 changes: 22 additions & 3 deletions src/nameserver/system_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <memory>
#include <string>

#include "absl/strings/string_view.h"
#include "base/status.h"
#include "gflags/gflags.h"
Expand All @@ -35,7 +36,7 @@ constexpr const char* PRE_AGG_DB = "__PRE_AGG_DB";
constexpr const char* JOB_INFO_NAME = "JOB_INFO";
constexpr const char* PRE_AGG_META_NAME = "PRE_AGG_META_INFO";
constexpr const char* USER_INFO_NAME = "USER";

constexpr const char* OBJECT_INFO_NAME = "OBJECT";

constexpr const char* INFORMATION_SCHEMA_DB = "INFORMATION_SCHEMA";
// start tables for INFORMATION_SCHEMA
Expand All @@ -49,11 +50,11 @@ enum class SystemTableType {
kGlobalVariable = 3,
kDeployResponseTime,
kUser,
kObject,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object is too general, pick a better name for privilege

Copy link
Collaborator Author

@oh2024 oh2024 Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about UserPrivilege?

};

struct SystemTableInfo {
SystemTableInfo(absl::string_view db, absl::string_view name)
: db_(db), name_(name) {}
SystemTableInfo(absl::string_view db, absl::string_view name) : db_(db), name_(name) {}

// db name
absl::string_view db_;
Expand Down Expand Up @@ -181,6 +182,24 @@ class SystemTable {
ttl->set_lat_ttl(1);
break;
}
case SystemTableType::kObject: {
SetColumnDesc("host", type::DataType::kString, table_info->add_column_desc());
SetColumnDesc("user", type::DataType::kString, table_info->add_column_desc());
SetColumnDesc("object_type", type::DataType::kInt, table_info->add_column_desc());
SetColumnDesc("db", type::DataType::kString, table_info->add_column_desc());
SetColumnDesc("name", type::DataType::kString, table_info->add_column_desc());
SetColumnDesc("privileges", type::DataType::kString, table_info->add_column_desc());
SetColumnDesc("extra_info", type::DataType::kString, table_info->add_column_desc());
auto index = table_info->add_column_key();
index->set_index_name("index");
index->add_col_name("host");
index->add_col_name("user");
index->add_col_name("object_type");
auto ttl = index->mutable_ttl();
ttl->set_ttl_type(::openmldb::type::kLatestTime);
ttl->set_lat_ttl(1);
break;
}
default:
return nullptr;
}
Expand Down
Loading