1 // Copyright 2020 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_EXPRESSION_H 16 #define GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_EXPRESSION_H 17 18 #include <grpc/support/port_platform.h> 19 20 #include <memory> 21 #include <vector> 22 23 #include "absl/status/statusor.h" 24 25 #include "google/api/expr/v1alpha1/syntax.upb.h" 26 #include "src/core/lib/security/authorization/mock_cel/activation.h" 27 #include "src/core/lib/security/authorization/mock_cel/cel_value.h" 28 29 namespace grpc_core { 30 namespace mock_cel { 31 32 // This is a temporary stub implementation of CEL APIs. 33 // Once gRPC imports the CEL library, this file will be removed. 34 35 // Base interface for expression evaluating objects. 36 class CelExpression { 37 public: 38 virtual ~CelExpression() = default; 39 40 // Evaluates expression and returns value. 41 // activation contains bindings from parameter names to values 42 virtual absl::StatusOr<CelValue> Evaluate( 43 const BaseActivation& activation) const = 0; 44 }; 45 46 // Base class for Expression Builder implementations 47 // Provides user with factory to register extension functions. 48 // ExpressionBuilder MUST NOT be destroyed before CelExpression objects 49 // it built. 50 class CelExpressionBuilder { 51 public: 52 virtual ~CelExpressionBuilder() = default; 53 54 // Creates CelExpression object from AST tree. 55 // expr specifies root of AST tree 56 virtual absl::StatusOr<std::unique_ptr<CelExpression>> CreateExpression( 57 const google_api_expr_v1alpha1_Expr* expr, 58 const google_api_expr_v1alpha1_SourceInfo* source_info) const = 0; 59 60 virtual absl::StatusOr<std::unique_ptr<CelExpression>> CreateExpression( 61 const google_api_expr_v1alpha1_Expr* expr, 62 const google_api_expr_v1alpha1_SourceInfo* source_info, 63 std::vector<absl::Status>* warnings) const = 0; 64 }; 65 66 } // namespace mock_cel 67 } // namespace grpc_core 68 69 #endif // GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_EXPRESSION_H