Imported Upstream version 1.34.0
[platform/upstream/grpc.git] / src / core / ext / xds / google_mesh_ca_certificate_provider_factory.h
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_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
20 #define GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/ext/xds/certificate_provider_factory.h"
25 #include "src/core/lib/backoff/backoff.h"
26 #include "src/core/lib/gprpp/ref_counted.h"
27
28 namespace grpc_core {
29
30 class GoogleMeshCaCertificateProviderFactory
31     : public CertificateProviderFactory {
32  public:
33   class Config : public CertificateProviderFactory::Config {
34    public:
35     struct StsConfig {
36       std::string token_exchange_service_uri;
37       std::string resource;
38       std::string audience;
39       std::string scope;
40       std::string requested_token_type;
41       std::string subject_token_path;
42       std::string subject_token_type;
43       std::string actor_token_path;
44       std::string actor_token_type;
45     };
46
47     const char* name() const override;
48
49     std::string ToString() const override;
50
51     const std::string& endpoint() const { return endpoint_; }
52
53     const StsConfig& sts_config() const { return sts_config_; }
54
55     grpc_millis timeout() const { return timeout_; }
56
57     grpc_millis certificate_lifetime() const { return certificate_lifetime_; }
58
59     grpc_millis renewal_grace_period() const { return renewal_grace_period_; }
60
61     uint32_t key_size() const { return key_size_; }
62
63     const std::string& location() const { return location_; }
64
65     static RefCountedPtr<Config> Parse(const Json& config_json,
66                                        grpc_error** error);
67
68    private:
69     // Helpers for parsing the config
70     std::vector<grpc_error*> ParseJsonObjectStsService(
71         const Json::Object& sts_service);
72     std::vector<grpc_error*> ParseJsonObjectCallCredentials(
73         const Json::Object& call_credentials);
74     std::vector<grpc_error*> ParseJsonObjectGoogleGrpc(
75         const Json::Object& google_grpc);
76     std::vector<grpc_error*> ParseJsonObjectGrpcServices(
77         const Json::Object& grpc_service);
78     std::vector<grpc_error*> ParseJsonObjectServer(const Json::Object& server);
79
80     std::string endpoint_;
81     StsConfig sts_config_;
82     grpc_millis timeout_;
83     grpc_millis certificate_lifetime_;
84     grpc_millis renewal_grace_period_;
85     uint32_t key_size_;
86     std::string location_;
87   };
88
89   const char* name() const override;
90
91   RefCountedPtr<CertificateProviderFactory::Config>
92   CreateCertificateProviderConfig(const Json& config_json,
93                                   grpc_error** error) override;
94
95   RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider(
96       RefCountedPtr<CertificateProviderFactory::Config> config) override {
97     // TODO(yashykt) : To be implemented
98     return nullptr;
99   }
100 };
101
102 }  // namespace grpc_core
103
104 #endif  // GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H