GRPC C++  1.39.1
xds_bootstrap.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_CORE_EXT_XDS_XDS_BOOTSTRAP_H
18 #define GRPC_CORE_EXT_XDS_XDS_BOOTSTRAP_H
19 
21 
22 #include <memory>
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include "absl/container/inlined_vector.h"
28 
29 #include <grpc/slice.h>
30 
35 #include "src/core/lib/json/json.h"
37 
38 namespace grpc_core {
39 
40 class XdsClient;
41 
43  public:
44  static bool IsSupported(const std::string& creds_type);
45  static bool IsValidConfig(const std::string& creds_type, const Json& config);
47  const std::string& creds_type, const Json& config);
48 };
49 
50 class XdsBootstrap {
51  public:
52  struct Node {
53  std::string id;
54  std::string cluster;
55  std::string locality_region;
56  std::string locality_zone;
57  std::string locality_sub_zone;
59  };
60 
61  struct XdsServer {
62  std::string server_uri;
63  std::string channel_creds_type;
65  std::set<std::string> server_features;
66 
67  bool ShouldUseV3() const;
68  };
69 
70  // Creates bootstrap object from json_string.
71  // If *error is not GRPC_ERROR_NONE after returning, then there was an
72  // error parsing the contents.
73  static std::unique_ptr<XdsBootstrap> Create(absl::string_view json_string,
75 
76  // Do not instantiate directly -- use Create() above instead.
78 
79  std::string ToString() const;
80 
81  // TODO(roth): We currently support only one server. Fix this when we
82  // add support for fallback for the xds channel.
83  const XdsServer& server() const { return servers_[0]; }
84  const Node* node() const { return node_.get(); }
85  const std::string& server_listener_resource_name_template() const {
86  return server_listener_resource_name_template_;
87  }
88 
90  const {
91  return certificate_providers_;
92  }
93 
94  private:
95  grpc_error_handle ParseXdsServerList(Json* json);
96  grpc_error_handle ParseXdsServer(Json* json, size_t idx);
97  grpc_error_handle ParseChannelCredsArray(Json* json, XdsServer* server);
98  grpc_error_handle ParseChannelCreds(Json* json, size_t idx,
99  XdsServer* server);
100  grpc_error_handle ParseServerFeaturesArray(Json* json, XdsServer* server);
101  grpc_error_handle ParseNode(Json* json);
102  grpc_error_handle ParseLocality(Json* json);
103  grpc_error_handle ParseCertificateProviders(Json* json);
104  grpc_error_handle ParseCertificateProvider(const std::string& instance_name,
105  Json* certificate_provider_json);
106 
107  absl::InlinedVector<XdsServer, 1> servers_;
108  std::unique_ptr<Node> node_;
109  std::string server_listener_resource_name_template_;
110  CertificateProviderStore::PluginDefinitionMap certificate_providers_;
111 };
112 
113 } // namespace grpc_core
114 
115 #endif /* GRPC_CORE_EXT_XDS_XDS_BOOTSTRAP_H */
std::map< std::string, PluginDefinition > PluginDefinitionMap
Definition: certificate_provider_store.h:46
Definition: json.h:38
Definition: xds_bootstrap.h:50
const Node * node() const
Definition: xds_bootstrap.h:84
const XdsServer & server() const
Definition: xds_bootstrap.h:83
static std::unique_ptr< XdsBootstrap > Create(absl::string_view json_string, grpc_error_handle *error)
Definition: xds_bootstrap.cc:83
const std::string & server_listener_resource_name_template() const
Definition: xds_bootstrap.h:85
const CertificateProviderStore::PluginDefinitionMap & certificate_providers() const
Definition: xds_bootstrap.h:89
std::string ToString() const
Definition: xds_bootstrap.cc:441
XdsBootstrap(Json json, grpc_error_handle *error)
Definition: xds_bootstrap.cc:97
Definition: xds_bootstrap.h:42
static bool IsValidConfig(const std::string &creds_type, const Json &config)
Definition: xds_bootstrap.cc:50
static RefCountedPtr< grpc_channel_credentials > MakeChannelCreds(const std::string &creds_type, const Json &config)
Definition: xds_bootstrap.cc:59
static bool IsSupported(const std::string &creds_type)
Definition: xds_bootstrap.cc:45
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
RefCountedPtr< LoadBalancingPolicy::Config > config
Definition: priority.cc:60
Definition: xds_bootstrap.h:52
std::string cluster
Definition: xds_bootstrap.h:54
std::string locality_sub_zone
Definition: xds_bootstrap.h:57
std::string locality_zone
Definition: xds_bootstrap.h:56
std::string locality_region
Definition: xds_bootstrap.h:55
std::string id
Definition: xds_bootstrap.h:53
Json metadata
Definition: xds_bootstrap.h:58
Definition: xds_bootstrap.h:61
std::set< std::string > server_features
Definition: xds_bootstrap.h:65
bool ShouldUseV3() const
Definition: xds_bootstrap.cc:75
std::string server_uri
Definition: xds_bootstrap.h:62
std::string channel_creds_type
Definition: xds_bootstrap.h:63
Json channel_creds_config
Definition: xds_bootstrap.h:64
Definition: error_internal.h:41