1 // 2 // 3 // Copyright 2020 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // 17 // 18 19 #ifndef GRPC_SRC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_REGISTRY_H 20 #define GRPC_SRC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_REGISTRY_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <map> 25 #include <memory> 26 #include <utility> 27 28 #include "absl/strings/string_view.h" 29 30 #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h" 31 32 namespace grpc_core { 33 34 // Global registry for all the certificate provider plugins. 35 class CertificateProviderRegistry { 36 private: 37 using FactoryMap = 38 std::map<absl::string_view, std::unique_ptr<CertificateProviderFactory>>; 39 40 public: 41 class Builder { 42 public: 43 // Register a provider with the registry. The key of the factory is 44 // extracted from factory parameter with method 45 // CertificateProviderFactory::name. The registry with a given name 46 // cannot be registered twice. 47 void RegisterCertificateProviderFactory( 48 std::unique_ptr<CertificateProviderFactory> factory); 49 50 CertificateProviderRegistry Build(); 51 52 private: 53 FactoryMap factories_; 54 }; 55 56 CertificateProviderRegistry(const CertificateProviderRegistry&) = delete; 57 CertificateProviderRegistry& operator=(const CertificateProviderRegistry&) = 58 delete; 59 CertificateProviderRegistry(CertificateProviderRegistry&&) = default; 60 CertificateProviderRegistry& operator=(CertificateProviderRegistry&&) = 61 default; 62 63 // Returns the factory for the plugin keyed by name. 64 CertificateProviderFactory* LookupCertificateProviderFactory( 65 absl::string_view name) const; 66 67 private: CertificateProviderRegistry(FactoryMap factories)68 explicit CertificateProviderRegistry(FactoryMap factories) 69 : factories_(std::move(factories)) {} 70 71 FactoryMap factories_; 72 }; 73 74 } // namespace grpc_core 75 76 #endif // GRPC_SRC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_REGISTRY_H 77