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

Function NativeCheck

eval/tests/modern_benchmark_test.cc:293–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291const char kToken[] = "admin";
292
293ABSL_ATTRIBUTE_NOINLINE
294bool NativeCheck(absl::btree_map<std::string, std::string>& attributes,
295 const absl::flat_hash_set<std::string>& denylists,
296 const absl::flat_hash_set<std::string>& allowlists) {
297 auto& ip = attributes["ip"];
298 auto& path = attributes["path"];
299 auto& token = attributes["token"];
300 if (denylists.find(ip) != denylists.end()) {
301 return false;
302 }
303 if (absl::StartsWith(path, "v1")) {
304 if (token == "v1" || token == "v2" || token == "admin") {
305 return true;
306 }
307 } else if (absl::StartsWith(path, "v2")) {
308 if (token == "v2" || token == "admin") {
309 return true;
310 }
311 } else if (absl::StartsWith(path, "/admin")) {
312 if (token == "admin") {
313 if (allowlists.find(ip) != allowlists.end()) {
314 return true;
315 }
316 }
317 }
318 return false;
319}
320
321void BM_PolicyNative(benchmark::State& state) {
322 const auto denylists =

Callers 1

BM_PolicyNativeFunction · 0.70

Calls 1

endMethod · 0.45

Tested by

no test coverage detected