1 // 2 // Copyright 2023 gRPC authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef GRPC_SRC_CORE_EXT_XDS_XDS_AUDIT_LOGGER_REGISTRY_H 18 #define GRPC_SRC_CORE_EXT_XDS_XDS_AUDIT_LOGGER_REGISTRY_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include <map> 23 #include <memory> 24 25 #include "absl/strings/string_view.h" 26 #include "envoy/config/rbac/v3/rbac.upb.h" 27 28 #include "src/core/ext/xds/xds_resource_type.h" 29 #include "src/core/lib/gprpp/validation_errors.h" 30 #include "src/core/lib/json/json.h" 31 32 namespace grpc_core { 33 34 // A registry that maintains a set of converters that are able to map xDS 35 // RBAC audit logger configuration to gRPC's JSON format. 36 class XdsAuditLoggerRegistry { 37 public: 38 class ConfigFactory { 39 public: 40 virtual ~ConfigFactory() = default; 41 virtual Json::Object ConvertXdsAuditLoggerConfig( 42 const XdsResourceType::DecodeContext& context, 43 absl::string_view configuration, ValidationErrors* errors) = 0; 44 // The full proto message name for the logger config. 45 virtual absl::string_view type() = 0; 46 // The logger name used for the gRPC registry. 47 virtual absl::string_view name() = 0; 48 }; 49 50 XdsAuditLoggerRegistry(); 51 52 Json ConvertXdsAuditLoggerConfig( 53 const XdsResourceType::DecodeContext& context, 54 const envoy_config_rbac_v3_RBAC_AuditLoggingOptions_AuditLoggerConfig* 55 logger_config, 56 ValidationErrors* errors) const; 57 58 private: 59 // A map of config factories that goes from the type of the audit logging 60 // config to the config factory. 61 std::map<absl::string_view /* Owned by ConfigFactory */, 62 std::unique_ptr<ConfigFactory>> 63 audit_logger_config_factories_; 64 }; 65 66 } // namespace grpc_core 67 68 #endif // GRPC_SRC_CORE_EXT_XDS_XDS_AUDIT_LOGGER_REGISTRY_H 69