/Users/deen/code/yugabyte-db/src/yb/master/yql_auth_roles_vtable.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/master/yql_auth_roles_vtable.h" |
15 | | |
16 | | #include "yb/common/ql_type.h" |
17 | | #include "yb/common/schema.h" |
18 | | |
19 | | #include "yb/master/permissions_manager.h" |
20 | | |
21 | | #include "yb/util/status_log.h" |
22 | | |
23 | | namespace yb { |
24 | | namespace master { |
25 | | |
26 | | YQLAuthRolesVTable::YQLAuthRolesVTable(const TableName& table_name, |
27 | | const NamespaceName& namespace_name, |
28 | | Master * const master) |
29 | 2.00k | : YQLVirtualTable(table_name, namespace_name, master, CreateSchema()) { |
30 | 2.00k | } |
31 | | |
32 | | Result<std::shared_ptr<QLRowBlock>> YQLAuthRolesVTable::RetrieveData( |
33 | 7.58k | const QLReadRequestPB& request) const { |
34 | 7.58k | auto vtable = std::make_shared<QLRowBlock>(schema()); |
35 | 7.58k | std::vector<scoped_refptr<RoleInfo>> roles; |
36 | 7.58k | catalog_manager().permissions_manager()->GetAllRoles(&roles); |
37 | 13.9k | for (const auto& role : roles) { |
38 | 13.9k | auto l = role->LockForRead(); |
39 | 13.9k | const auto& pb = l->pb; |
40 | 13.9k | QLRow& row = vtable->Extend(); |
41 | 13.9k | RETURN_NOT_OK(SetColumnValue(kRole, pb.role(), &row)); |
42 | 13.9k | RETURN_NOT_OK(SetColumnValue(kCanLogin, pb.can_login(), &row)); |
43 | 13.9k | RETURN_NOT_OK(SetColumnValue(kIsSuperuser, pb.is_superuser(), &row)); |
44 | | |
45 | 13.9k | QLValuePB members; |
46 | 13.9k | QLSeqValuePB* list_value = members.mutable_list_value(); |
47 | | |
48 | 92 | for (const auto& member : pb.member_of()) { |
49 | 92 | (*list_value->add_elems()).set_string_value(member); |
50 | 92 | } |
51 | 13.9k | RETURN_NOT_OK(SetColumnValue(kMemberOf, members, &row)); |
52 | 13.9k | if (pb.has_salted_hash()) { |
53 | 13.8k | RETURN_NOT_OK(SetColumnValue(kSaltedHash, pb.salted_hash(), &row)); |
54 | 13.8k | } |
55 | 13.9k | } |
56 | | |
57 | 7.58k | return vtable; |
58 | 7.58k | } |
59 | | |
60 | | |
61 | 2.00k | Schema YQLAuthRolesVTable::CreateSchema() const { |
62 | 2.00k | SchemaBuilder builder; |
63 | 2.00k | CHECK_OK(builder.AddHashKeyColumn(kRole, DataType::STRING)); |
64 | 2.00k | CHECK_OK(builder.AddColumn(kCanLogin, QLType::Create(DataType::BOOL))); |
65 | 2.00k | CHECK_OK(builder.AddColumn(kIsSuperuser, QLType::Create(DataType::BOOL))); |
66 | 2.00k | CHECK_OK(builder.AddColumn(kMemberOf, QLType::CreateTypeList(DataType::STRING))); |
67 | 2.00k | CHECK_OK(builder.AddColumn(kSaltedHash, QLType::Create(DataType::STRING))); |
68 | 2.00k | return builder.Build(); |
69 | 2.00k | } |
70 | | |
71 | | } // namespace master |
72 | | } // namespace yb |