1 // Copyright 2020 gRPC authors.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_VALUE_H
16 #define GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_VALUE_H
18 // CelValue is a holder, capable of storing all kinds of data
20 // CelValue defines explicitly typed/named getters/setters.
21 // When storing pointers to objects, CelValue does not accept ownership
22 // to them and does not control their lifecycle. Instead objects are expected
23 // to be either external to expression evaluation, and controlled beyond the
24 // scope or to be allocated and associated with some allocation/ownership
25 // controller (Arena).
27 // (a) For primitive types:
28 // CelValue value = CelValue::CreateInt64(1);
30 // std::string* msg("test");
31 // CelValue value = CelValue::CreateString(msg);
33 #include <grpc/support/port_platform.h>
35 #include "absl/strings/string_view.h"
40 // Break cyclic depdendencies for container types.
46 // This is a temporary stub implementation of CEL APIs.
47 // Once gRPC imports the CEL library, this class will be removed.
50 // Default constructor.
51 // Creates CelValue with null data type.
52 CelValue() : CelValue(nullptr) {}
54 // We will use factory methods instead of public constructors
55 // The reason for this is the high risk of implicit type conversions
56 // between bool/int/pointer types.
57 // We rely on copy elision to avoid extra copying.
58 static CelValue CreateNull() { return CelValue(nullptr); }
60 static CelValue CreateInt64(int64_t value) { return CreateNull(); }
62 static CelValue CreateUint64(uint64_t value) { return CreateNull(); }
64 static CelValue CreateStringView(absl::string_view value) {
68 static CelValue CreateString(const std::string* str) { return CreateNull(); }
70 static CelValue CreateMap(const CelMap* value) { return CreateNull(); }
73 // Constructs CelValue wrapping value supplied as argument.
74 // Value type T should be supported by specification of ValueHolder.
76 explicit CelValue(T value) {}
79 // CelMap implementation that uses STL map container as backing storage.
80 class ContainerBackedMapImpl : public CelMap {
82 ContainerBackedMapImpl() = default;
84 static std::unique_ptr<CelMap> Create(
85 absl::Span<std::pair<CelValue, CelValue>> key_values) {
86 return absl::make_unique<ContainerBackedMapImpl>();
90 } // namespace mock_cel
91 } // namespace grpc_core
93 #endif // GRPC_CORE_LIB_SECURITY_AUTHORIZATION_MOCK_CEL_CEL_VALUE_H