-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import descriptor from top-level remove unused patch add protobuf submodule add protovalidate submodule add abseil submodule set protobuf version to latest release add cel submodule green cmake build and install add CMake .gitignore
- Loading branch information
Showing
14 changed files
with
128 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[submodule "third_party/protobuf"] | ||
path = third_party/protobuf | ||
url = https://github.com/protocolbuffers/protobuf | ||
[submodule "third_party/protovalidate"] | ||
path = third_party/protovalidate | ||
url = https://github.com/bufbuild/protovalidate | ||
[submodule "third_party/abseil-cpp"] | ||
path = third_party/abseil-cpp | ||
url = https://github.com/abseil/abseil-cpp | ||
[submodule "third_party/cel-cpp"] | ||
path = third_party/cel-cpp | ||
url = https://github.com/google/cel-cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.26) | ||
|
||
project(protovalidate-cc) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
|
||
if(APPLE) | ||
set(CMAKE_INSTALL_RPATH "@executable_path/../lib") | ||
elseif(UNIX) | ||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") | ||
endif() | ||
|
||
set(ABSL_PROPAGATE_CXX_STD ON) | ||
set(protobuf_ABSL_PROVIDER "module") | ||
set(protobuf_BUILD_PROTOC_BINARIES OFF) | ||
set(protobuf_BUILD_TESTS OFF) | ||
|
||
add_subdirectory(buf/validate) | ||
add_subdirectory(third_party/protobuf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1 @@ | ||
diff --git a/eval/eval/container_access_step.cc b/eval/eval/container_access_step.cc | ||
index 39c2507..d7962a2 100644 | ||
--- a/eval/eval/container_access_step.cc | ||
+++ b/eval/eval/container_access_step.cc | ||
@@ -11,6 +11,8 @@ | ||
#include "eval/public/cel_number.h" | ||
#include "eval/public/cel_value.h" | ||
#include "eval/public/unknown_attribute_set.h" | ||
+#include "eval/public/structs/legacy_type_adapter.h" | ||
+#include "eval/public/structs/legacy_type_info_apis.h" | ||
|
||
namespace google::api::expr::runtime { | ||
|
||
@@ -34,6 +36,8 @@ class ContainerAccessStep : public ExpressionStepBase { | ||
ExecutionFrame* frame) const; | ||
CelValue LookupInList(const CelList* cel_list, const CelValue& key, | ||
ExecutionFrame* frame) const; | ||
+ CelValue LookupInMessage(const CelValue::MessageWrapper& msg, const CelValue& key, | ||
+ ExecutionFrame* frame) const; | ||
}; | ||
|
||
inline CelValue ContainerAccessStep::LookupInMap(const CelMap* cel_map, | ||
@@ -109,6 +113,26 @@ inline CelValue ContainerAccessStep::LookupInList(const CelList* cel_list, | ||
CelValue::TypeName(key.type()))); | ||
} | ||
|
||
+CelValue ContainerAccessStep::LookupInMessage(const CelValue::MessageWrapper& msg, const CelValue& key, | ||
+ ExecutionFrame* frame) const { | ||
+ if (!key.IsString()) { | ||
+ return CreateErrorValue( | ||
+ frame->memory_manager(), | ||
+ absl::StrCat("Field name error: expected string type, got ", | ||
+ CelValue::TypeName(key.type()))); | ||
+ } | ||
+ const LegacyTypeAccessApis* accessor = | ||
+ msg.legacy_type_info()->GetAccessApis(msg); | ||
+ if (accessor == nullptr) { | ||
+ return CreateNoSuchFieldError(frame->memory_manager()); | ||
+ } | ||
+ auto result_or = accessor->GetField(key.StringOrDie().value(), msg, ProtoWrapperTypeOptions::kUnsetNull, frame->memory_manager()); | ||
+ if (!result_or.ok()) { | ||
+ return CreateErrorValue(frame->memory_manager(), result_or.status()); | ||
+ } | ||
+ return std::move(result_or).value(); | ||
+} | ||
+ | ||
ContainerAccessStep::ValueAttributePair ContainerAccessStep::PerformLookup( | ||
ExecutionFrame* frame) const { | ||
auto input_args = frame->value_stack().GetSpan(kNumContainerAccessArguments); | ||
@@ -158,6 +182,12 @@ ContainerAccessStep::ValueAttributePair ContainerAccessStep::PerformLookup( | ||
const CelList* cel_list = container.ListOrDie(); | ||
return {LookupInList(cel_list, key, frame), trail}; | ||
} | ||
+ case CelValue::Type::kMessage: { | ||
+ CelValue::MessageWrapper wrapper; | ||
+ bool success = container.GetValue(&wrapper); | ||
+ ABSL_ASSERT(success); | ||
+ return {LookupInMessage(wrapper, key, frame), trail}; | ||
+ } | ||
default: { | ||
auto error = | ||
CreateErrorValue(frame->memory_manager(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
add_custom_command( | ||
OUTPUT | ||
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.h | ||
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.cc | ||
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.h | ||
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.cc | ||
COMMAND buf generate ${CMAKE_SOURCE_DIR}/third_party/protovalidate/proto/protovalidate --template ${CMAKE_SOURCE_DIR}/third_party/buf.gen.yaml --output ${CMAKE_BINARY_DIR} | ||
VERBATIM | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.h | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.cc | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.h | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.cc | ||
COMMAND buf generate ${CMAKE_SOURCE_DIR}/third_party/proto --include-imports --template ${CMAKE_SOURCE_DIR}/third_party/buf.gen.yaml --output ${CMAKE_BINARY_DIR} | ||
VERBATIM | ||
) | ||
|
||
add_library( | ||
validator | ||
validator.cc | ||
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.cc | ||
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.cc | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.cc | ||
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.cc | ||
) | ||
|
||
target_link_libraries(validator PUBLIC protobuf) | ||
target_include_directories(validator PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/protobuf/src> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/abseil-cpp> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/cel-cpp> | ||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
install(TARGETS validator DESTINATION lib) | ||
install(FILES validator.h DESTINATION include/buf/validate) | ||
install(FILES ${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.h DESTINATION include/buf/validate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule abseil-cpp
added at
372124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: github.com/bufbuild/protovalidate/tools/internal/gen | ||
except: | ||
- buf.build/envoyproxy/protoc-gen-validate | ||
plugins: | ||
- plugin: buf.build/protocolbuffers/cpp:v27.3 | ||
out: include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Generated by buf. DO NOT EDIT. | ||
version: v2 | ||
deps: | ||
- name: buf.build/googleapis/googleapis | ||
commit: 8bc2c51e08c447cd8886cdea48a73e14 | ||
digest: b5:b7e0ac9d192bd0eae88160101269550281448c51f25121cd0d51957661a350aab07001bc145fe9029a8da10b99ff000ae5b284ecaca9c75f2a99604a04d9b4ab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: v2 | ||
deps: | ||
- buf.build/googleapis/googleapis | ||
lint: | ||
except: | ||
- FIELD_NOT_REQUIRED | ||
- PACKAGE_NO_IMPORT_CYCLE | ||
breaking: | ||
except: | ||
- EXTENSION_NO_DELETE | ||
- FIELD_SAME_DEFAULT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/api/expr/v1alpha1/checked.proto"; | ||
import "google/api/expr/v1alpha1/syntax.proto"; |
Submodule protovalidate
added at
40f7ac