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 #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h" 30 31 namespace grpc_core { 32 33 // Global registry for all the certificate provider plugins. 34 class CertificateProviderRegistry { 35 private: 36 using FactoryMap = 37 std::map<absl::string_view, std::unique_ptr<CertificateProviderFactory>>; 38 39 public: 40 class Builder { 41 public: 42 // Register a provider with the registry. The key of the factory is 43 // extracted from factory parameter with method 44 // CertificateProviderFactory::name. The registry with a given name 45 // cannot be registered twice. 46 void RegisterCertificateProviderFactory( 47 std::unique_ptr<CertificateProviderFactory> factory); 48 49 CertificateProviderRegistry Build(); 50 51 private: 52 FactoryMap factories_; 53 }; 54 55 CertificateProviderRegistry(const CertificateProviderRegistry&) = delete; 56 CertificateProviderRegistry& operator=(const CertificateProviderRegistry&) = 57 delete; 58 CertificateProviderRegistry(CertificateProviderRegistry&&) = default; 59 CertificateProviderRegistry& operator=(CertificateProviderRegistry&&) = 60 default; 61 62 // Returns the factory for the plugin keyed by name. 63 CertificateProviderFactory* LookupCertificateProviderFactory( 64 absl::string_view name) const; 65 66 private: CertificateProviderRegistry(FactoryMap factories)67 explicit CertificateProviderRegistry(FactoryMap factories) 68 : factories_(std::move(factories)) {} 69 70 FactoryMap factories_; 71 }; 72 73 } // namespace grpc_core 74 75 #endif // GRPC_SRC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_REGISTRY_H 76