| 1 | #include <Storages/System/StorageSystemRowPolicies.h> |
| 2 | #include <DataTypes/DataTypeString.h> |
| 3 | #include <DataTypes/DataTypesNumber.h> |
| 4 | #include <DataTypes/DataTypeUUID.h> |
| 5 | #include <DataTypes/DataTypeDateTime.h> |
| 6 | #include <DataTypes/DataTypeNullable.h> |
| 7 | #include <Interpreters/Context.h> |
| 8 | #include <Access/AccessControlManager.h> |
| 9 | #include <Access/RowPolicy.h> |
| 10 | #include <ext/range.h> |
| 11 | |
| 12 | |
| 13 | namespace DB |
| 14 | { |
| 15 | NamesAndTypesList StorageSystemRowPolicies::getNamesAndTypes() |
| 16 | { |
| 17 | NamesAndTypesList names_and_types{ |
| 18 | {"database" , std::make_shared<DataTypeString>()}, |
| 19 | {"table" , std::make_shared<DataTypeString>()}, |
| 20 | {"name" , std::make_shared<DataTypeString>()}, |
| 21 | {"full_name" , std::make_shared<DataTypeString>()}, |
| 22 | {"id" , std::make_shared<DataTypeUUID>()}, |
| 23 | {"source" , std::make_shared<DataTypeString>()}, |
| 24 | {"restrictive" , std::make_shared<DataTypeUInt8>()}, |
| 25 | }; |
| 26 | |
| 27 | for (auto index : ext::range_with_static_cast<RowPolicy::ConditionIndex>(RowPolicy::MAX_CONDITION_INDEX)) |
| 28 | names_and_types.push_back({RowPolicy::conditionIndexToColumnName(index), std::make_shared<DataTypeString>()}); |
| 29 | |
| 30 | return names_and_types; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | void StorageSystemRowPolicies::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const |
| 35 | { |
| 36 | const auto & access_control = context.getAccessControlManager(); |
| 37 | std::vector<UUID> ids = access_control.findAll<RowPolicy>(); |
| 38 | |
| 39 | for (const auto & id : ids) |
| 40 | { |
| 41 | auto policy = access_control.tryRead<RowPolicy>(id); |
| 42 | if (!policy) |
| 43 | continue; |
| 44 | const auto * storage = access_control.findStorage(id); |
| 45 | |
| 46 | size_t i = 0; |
| 47 | res_columns[i++]->insert(policy->getDatabase()); |
| 48 | res_columns[i++]->insert(policy->getTableName()); |
| 49 | res_columns[i++]->insert(policy->getName()); |
| 50 | res_columns[i++]->insert(policy->getFullName()); |
| 51 | res_columns[i++]->insert(id); |
| 52 | res_columns[i++]->insert(storage ? storage->getStorageName() : "" ); |
| 53 | res_columns[i++]->insert(policy->isRestrictive()); |
| 54 | |
| 55 | for (auto index : ext::range(RowPolicy::MAX_CONDITION_INDEX)) |
| 56 | res_columns[i++]->insert(policy->conditions[index]); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |