MCPcopy Create free account
hub / github.com/ByConity/ByConity / readEntityFile

Function readEntityFile

src/Access/DiskAccessStorage.cpp:112–199  ·  view source on GitHub ↗

Reads a file containing ATTACH queries and then parses it to build an access entity.

Source from the content-addressed store, hash-verified

110
111 /// Reads a file containing ATTACH queries and then parses it to build an access entity.
112 AccessEntityPtr readEntityFile(const String & file_path)
113 {
114 /// Read the file.
115 ReadBufferFromFile in{file_path};
116 String file_contents;
117 readStringUntilEOF(file_contents, in);
118
119 /// Parse the file contents.
120 ASTs queries;
121 ParserAttachAccessEntity parser;
122 const char * begin = file_contents.data(); /// begin of current query
123 const char * pos = begin; /// parser moves pos from begin to the end of current query
124 const char * end = begin + file_contents.size();
125 while (pos < end)
126 {
127 queries.emplace_back(parseQueryAndMovePosition(parser, pos, end, "", true, 0, DBMS_DEFAULT_MAX_PARSER_DEPTH));
128 while (isWhitespaceASCII(*pos) || *pos == ';')
129 ++pos;
130 }
131
132 /// Interpret the AST to build an access entity.
133 std::shared_ptr<User> user;
134 std::shared_ptr<Role> role;
135 std::shared_ptr<RowPolicy> policy;
136 std::shared_ptr<Quota> quota;
137 std::shared_ptr<SettingsProfile> profile;
138 AccessEntityPtr res;
139 bool sensitive_tenant = false;
140
141 for (const auto & query : queries)
142 {
143 if (auto * create_user_query = query->as<ASTCreateUserQuery>())
144 {
145 if (res)
146 throw Exception("Two access entities in one file " + file_path, ErrorCodes::INCORRECT_ACCESS_ENTITY_DEFINITION);
147 res = user = std::make_unique<User>();
148 InterpreterCreateUserQuery::updateUserFromQuery(*user, *create_user_query);
149 }
150 else if (auto * create_role_query = query->as<ASTCreateRoleQuery>())
151 {
152 if (res)
153 throw Exception("Two access entities in one file " + file_path, ErrorCodes::INCORRECT_ACCESS_ENTITY_DEFINITION);
154 res = role = std::make_unique<Role>();
155 InterpreterCreateRoleQuery::updateRoleFromQuery(*role, *create_role_query);
156 }
157 else if (auto * create_policy_query = query->as<ASTCreateRowPolicyQuery>())
158 {
159 if (res)
160 throw Exception("Two access entities in one file " + file_path, ErrorCodes::INCORRECT_ACCESS_ENTITY_DEFINITION);
161 res = policy = std::make_unique<RowPolicy>();
162 InterpreterCreateRowPolicyQuery::updateRowPolicyFromQuery(*policy, *create_policy_query);
163 }
164 else if (auto * create_quota_query = query->as<ASTCreateQuotaQuery>())
165 {
166 if (res)
167 throw Exception("Two access entities are attached in the same file " + file_path, ErrorCodes::INCORRECT_ACCESS_ENTITY_DEFINITION);
168 res = quota = std::make_unique<Quota>();
169 InterpreterCreateQuotaQuery::updateQuotaFromQuery(*quota, *create_quota_query);

Callers 2

tryReadEntityFileFunction · 0.85

Calls 8

readStringUntilEOFFunction · 0.85
isWhitespaceASCIIFunction · 0.85
ExceptionClass · 0.50
dataMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45
getIDMethod · 0.45

Tested by

no test coverage detected