MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / NativeCheck

Function NativeCheck

eval/tests/benchmark_test.cc:239–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237const char kToken[] = "admin";
238
239ABSL_ATTRIBUTE_NOINLINE
240bool NativeCheck(absl::btree_map<std::string, std::string>& attributes,
241 const absl::flat_hash_set<std::string>& denylists,
242 const absl::flat_hash_set<std::string>& allowlists) {
243 auto& ip = attributes["ip"];
244 auto& path = attributes["path"];
245 auto& token = attributes["token"];
246 if (denylists.find(ip) != denylists.end()) {
247 return false;
248 }
249 if (absl::StartsWith(path, "v1")) {
250 if (token == "v1" || token == "v2" || token == "admin") {
251 return true;
252 }
253 } else if (absl::StartsWith(path, "v2")) {
254 if (token == "v2" || token == "admin") {
255 return true;
256 }
257 } else if (absl::StartsWith(path, "/admin")) {
258 if (token == "admin") {
259 if (allowlists.find(ip) != allowlists.end()) {
260 return true;
261 }
262 }
263 }
264 return false;
265}
266
267void BM_PolicyNative(benchmark::State& state) {
268 const auto denylists =

Callers 1

BM_PolicyNativeFunction · 0.70

Calls 1

endMethod · 0.45

Tested by

no test coverage detected