2020-05-12 23:36:39 +00:00
|
|
|
#include <Storages/System/StorageSystemRoles.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
2021-11-02 11:06:20 +00:00
|
|
|
#include <Access/AccessControl.h>
|
2020-05-12 23:36:39 +00:00
|
|
|
#include <Access/Role.h>
|
2021-10-31 08:51:20 +00:00
|
|
|
#include <Access/Common/AccessFlags.h>
|
2020-05-12 23:36:39 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
NamesAndTypesList StorageSystemRoles::getNamesAndTypes()
|
|
|
|
{
|
|
|
|
NamesAndTypesList names_and_types{
|
|
|
|
{"name", std::make_shared<DataTypeString>()},
|
|
|
|
{"id", std::make_shared<DataTypeUUID>()},
|
|
|
|
{"storage", std::make_shared<DataTypeString>()},
|
|
|
|
};
|
|
|
|
return names_and_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void StorageSystemRoles::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
|
2020-05-12 23:36:39 +00:00
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
context->checkAccess(AccessType::SHOW_ROLES);
|
2021-11-02 11:06:20 +00:00
|
|
|
const auto & access_control = context->getAccessControl();
|
2020-05-12 23:36:39 +00:00
|
|
|
std::vector<UUID> ids = access_control.findAll<Role>();
|
|
|
|
|
|
|
|
size_t column_index = 0;
|
|
|
|
auto & column_name = assert_cast<ColumnString &>(*res_columns[column_index++]);
|
2021-05-03 22:59:38 +00:00
|
|
|
auto & column_id = assert_cast<ColumnUUID &>(*res_columns[column_index++]).getData();
|
2020-05-12 23:36:39 +00:00
|
|
|
auto & column_storage = assert_cast<ColumnString &>(*res_columns[column_index++]);
|
|
|
|
|
|
|
|
auto add_row = [&](const String & name,
|
|
|
|
const UUID & id,
|
|
|
|
const String & storage_name)
|
|
|
|
{
|
|
|
|
column_name.insertData(name.data(), name.length());
|
2021-04-25 09:30:43 +00:00
|
|
|
column_id.push_back(id.toUnderType());
|
2020-05-12 23:36:39 +00:00
|
|
|
column_storage.insertData(storage_name.data(), storage_name.length());
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto & id : ids)
|
|
|
|
{
|
|
|
|
auto role = access_control.tryRead<Role>(id);
|
|
|
|
if (!role)
|
|
|
|
continue;
|
|
|
|
|
2020-08-05 19:54:06 +00:00
|
|
|
auto storage = access_control.findStorage(id);
|
2020-05-12 23:36:39 +00:00
|
|
|
if (!storage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
add_row(role->getName(), id, storage->getStorageName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|