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_EXT_XDS_FILE_WATCHER_CERTIFICATE_PROVIDER_FACTORY_H 20 #define GRPC_SRC_CORE_EXT_XDS_FILE_WATCHER_CERTIFICATE_PROVIDER_FACTORY_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <string> 25 26 #include "absl/strings/string_view.h" 27 28 #include <grpc/grpc_security.h> 29 30 #include "src/core/lib/gprpp/ref_counted_ptr.h" 31 #include "src/core/lib/gprpp/time.h" 32 #include "src/core/lib/gprpp/validation_errors.h" 33 #include "src/core/lib/json/json.h" 34 #include "src/core/lib/json/json_args.h" 35 #include "src/core/lib/json/json_object_loader.h" 36 #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h" 37 38 namespace grpc_core { 39 40 class FileWatcherCertificateProviderFactory 41 : public CertificateProviderFactory { 42 public: 43 class Config : public CertificateProviderFactory::Config { 44 public: 45 absl::string_view name() const override; 46 47 std::string ToString() const override; 48 identity_cert_file()49 const std::string& identity_cert_file() const { 50 return identity_cert_file_; 51 } 52 private_key_file()53 const std::string& private_key_file() const { return private_key_file_; } 54 root_cert_file()55 const std::string& root_cert_file() const { return root_cert_file_; } 56 refresh_interval()57 Duration refresh_interval() const { return refresh_interval_; } 58 59 static const JsonLoaderInterface* JsonLoader(const JsonArgs& args); 60 void JsonPostLoad(const Json& json, const JsonArgs& args, 61 ValidationErrors* errors); 62 63 private: 64 std::string identity_cert_file_; 65 std::string private_key_file_; 66 std::string root_cert_file_; 67 Duration refresh_interval_ = Duration::Minutes(10); 68 }; 69 70 absl::string_view name() const override; 71 72 RefCountedPtr<CertificateProviderFactory::Config> 73 CreateCertificateProviderConfig(const Json& config_json, const JsonArgs& args, 74 ValidationErrors* errors) override; 75 76 RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider( 77 RefCountedPtr<CertificateProviderFactory::Config> config) override; 78 }; 79 80 } // namespace grpc_core 81 82 #endif // GRPC_SRC_CORE_EXT_XDS_FILE_WATCHER_CERTIFICATE_PROVIDER_FACTORY_H 83