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 <algorithm>
23 #include <map>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
29 #include "absl/strings/string_view.h"
30 
33 #include "src/core/lib/json/json.h"
34 
35 namespace grpc_core {
36 
38 
39 class XdsClient;
40 
41 class XdsBootstrap {
42  public:
43  struct Node {
50  };
51 
52  struct XdsServer {
56  std::set<std::string> server_features;
57 
58  static XdsServer Parse(const Json& json, grpc_error_handle* error);
59 
60  bool operator==(const XdsServer& other) const {
61  return (server_uri == other.server_uri &&
65  }
66 
67  bool operator<(const XdsServer& other) const {
68  if (server_uri < other.server_uri) return true;
69  if (channel_creds_type < other.channel_creds_type) return true;
71  return true;
72  }
73  if (server_features < other.server_features) return true;
74  return false;
75  }
76 
77  Json::Object ToJson() const;
78 
79  bool ShouldUseV3() const;
80  bool IgnoreResourceDeletion() const;
81  };
82 
83  struct Authority {
85  std::vector<XdsServer> xds_servers;
86  };
87 
88  // Creates bootstrap object from json_string.
89  // If *error is not GRPC_ERROR_NONE after returning, then there was an
90  // error parsing the contents.
91  static std::unique_ptr<XdsBootstrap> Create(absl::string_view json_string,
93 
94  // Do not instantiate directly -- use Create() above instead.
96 
97  std::string ToString() const;
98 
99  // TODO(roth): We currently support only one server. Fix this when we
100  // add support for fallback for the xds channel.
101  const XdsServer& server() const { return servers_[0]; }
102  const Node* node() const { return node_.get(); }
105  }
108  }
109  const std::map<std::string, Authority>& authorities() const {
110  return authorities_;
111  }
112  const Authority* LookupAuthority(const std::string& name) const;
114  const {
115  return certificate_providers_;
116  }
117  // A util method to check that an xds server exists in this bootstrap file.
118  bool XdsServerExists(const XdsServer& server) const;
119 
120  private:
122  std::vector<XdsServer>* servers);
129  Json* certificate_provider_json);
130 
131  std::vector<XdsServer> servers_;
132  std::unique_ptr<Node> node_;
135  std::map<std::string, Authority> authorities_;
137 };
138 
139 } // namespace grpc_core
140 
141 #endif // GRPC_CORE_EXT_XDS_XDS_BOOTSTRAP_H
grpc_core::XdsBootstrap::Node::locality_region
std::string locality_region
Definition: xds_bootstrap.h:46
grpc_core::XdsBootstrap::certificate_providers_
CertificateProviderStore::PluginDefinitionMap certificate_providers_
Definition: xds_bootstrap.h:136
grpc_core::XdsBootstrap::XdsServer::ToJson
Json::Object ToJson() const
Definition: xds_bootstrap.cc:147
grpc_core::XdsBootstrap::ParseAuthority
grpc_error_handle ParseAuthority(Json *json, const std::string &name)
Definition: xds_bootstrap.cc:327
grpc_core::XdsBootstrap::Create
static std::unique_ptr< XdsBootstrap > Create(absl::string_view json_string, grpc_error_handle *error)
Definition: xds_bootstrap.cc:180
grpc_core::XdsBootstrap::XdsServer::operator==
bool operator==(const XdsServer &other) const
Definition: xds_bootstrap.h:60
certificate_provider_store.h
grpc_core::XdsBootstrap::client_default_listener_resource_name_template
const std::string & client_default_listener_resource_name_template() const
Definition: xds_bootstrap.h:103
grpc_core::XdsBootstrap::XdsServer::channel_creds_type
std::string channel_creds_type
Definition: xds_bootstrap.h:54
grpc_core::XdsBootstrap::servers_
std::vector< XdsServer > servers_
Definition: xds_bootstrap.h:131
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::XdsBootstrap::node_
std::unique_ptr< Node > node_
Definition: xds_bootstrap.h:132
grpc_core::XdsBootstrap::ParseNode
grpc_error_handle ParseNode(Json *json)
Definition: xds_bootstrap.cc:368
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::XdsBootstrap::XdsServer::IgnoreResourceDeletion
bool IgnoreResourceDeletion() const
Definition: xds_bootstrap.cc:171
grpc_core::XdsBootstrap::ParseXdsServerList
grpc_error_handle ParseXdsServerList(Json *json, std::vector< XdsServer > *servers)
Definition: xds_bootstrap.cc:290
setup.name
name
Definition: setup.py:542
grpc_core::XdsBootstrap::Node
Definition: xds_bootstrap.h:43
grpc_core::XdsBootstrap::XdsBootstrap
XdsBootstrap(Json json, grpc_error_handle *error)
Definition: xds_bootstrap.cc:194
grpc_core::XdsBootstrap::XdsServer::server_features
std::set< std::string > server_features
Definition: xds_bootstrap.h:56
grpc_core::CertificateProviderStore::PluginDefinitionMap
std::map< std::string, PluginDefinition > PluginDefinitionMap
Definition: certificate_provider_store.h:55
grpc_core::XdsBootstrap::server_listener_resource_name_template_
std::string server_listener_resource_name_template_
Definition: xds_bootstrap.h:134
grpc_core::XdsBootstrap::Node::id
std::string id
Definition: xds_bootstrap.h:44
grpc_core::XdsBootstrap::server_listener_resource_name_template
const std::string & server_listener_resource_name_template() const
Definition: xds_bootstrap.h:106
grpc_core::XdsBootstrap::node
const Node * node() const
Definition: xds_bootstrap.h:102
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
grpc_core::XdsBootstrap::XdsServer::operator<
bool operator<(const XdsServer &other) const
Definition: xds_bootstrap.h:67
grpc_core::XdsBootstrap::server
const XdsServer & server() const
Definition: xds_bootstrap.h:101
grpc_core::XdsBootstrap::certificate_providers
const CertificateProviderStore::PluginDefinitionMap & certificate_providers() const
Definition: xds_bootstrap.h:113
grpc_core::XdsBootstrap::XdsServer::ShouldUseV3
bool ShouldUseV3() const
Definition: xds_bootstrap.cc:166
grpc_core::XdsBootstrap::ParseCertificateProvider
grpc_error_handle ParseCertificateProvider(const std::string &instance_name, Json *certificate_provider_json)
Definition: xds_bootstrap.cc:461
grpc_core::XdsBootstrap::ParseCertificateProviders
grpc_error_handle ParseCertificateProviders(Json *json)
Definition: xds_bootstrap.cc:445
grpc_core::XdsBootstrap::Authority::client_listener_resource_name_template
std::string client_listener_resource_name_template
Definition: xds_bootstrap.h:84
error.h
json.h
grpc_core::XdsFederationEnabled
bool XdsFederationEnabled()
Definition: xds_bootstrap.cc:48
grpc_core::XdsBootstrap::ToString
std::string ToString() const
Definition: xds_bootstrap.cc:510
grpc_core::Json::Object
std::map< std::string, Json > Object
Definition: src/core/lib/json/json.h:54
grpc_core::XdsBootstrap::XdsServerExists
bool XdsServerExists(const XdsServer &server) const
Definition: xds_bootstrap.cc:279
grpc_core::XdsBootstrap::authorities
const std::map< std::string, Authority > & authorities() const
Definition: xds_bootstrap.h:109
grpc_core::XdsBootstrap::XdsServer
Definition: xds_bootstrap.h:52
server
Definition: examples/python/async_streaming/server.py:1
grpc_core::XdsBootstrap::ParseLocality
grpc_error_handle ParseLocality(Json *json)
Definition: xds_bootstrap.cc:412
grpc_core::XdsBootstrap::client_default_listener_resource_name_template_
std::string client_default_listener_resource_name_template_
Definition: xds_bootstrap.h:133
grpc_core::XdsBootstrap::XdsServer::server_uri
std::string server_uri
Definition: xds_bootstrap.h:53
grpc_core::XdsBootstrap
Definition: xds_bootstrap.h:41
grpc_core::XdsBootstrap::Node::locality_zone
std::string locality_zone
Definition: xds_bootstrap.h:47
grpc_core::XdsBootstrap::Authority::xds_servers
std::vector< XdsServer > xds_servers
Definition: xds_bootstrap.h:85
grpc_core::XdsBootstrap::Node::metadata
Json metadata
Definition: xds_bootstrap.h:49
grpc_core::XdsBootstrap::authorities_
std::map< std::string, Authority > authorities_
Definition: xds_bootstrap.h:135
grpc_core::XdsBootstrap::LookupAuthority
const Authority * LookupAuthority(const std::string &name) const
Definition: xds_bootstrap.cc:270
grpc_core::XdsBootstrap::XdsServer::channel_creds_config
Json channel_creds_config
Definition: xds_bootstrap.h:55
grpc_core::XdsBootstrap::Authority
Definition: xds_bootstrap.h:83
grpc_error
Definition: error_internal.h:42
grpc_core::XdsBootstrap::Node::locality_sub_zone
std::string locality_sub_zone
Definition: xds_bootstrap.h:48
grpc_core::XdsBootstrap::ParseAuthorities
grpc_error_handle ParseAuthorities(Json *json)
Definition: xds_bootstrap.cc:312
grpc_core::XdsBootstrap::XdsServer::Parse
static XdsServer Parse(const Json &json, grpc_error_handle *error)
Definition: xds_bootstrap.cc:115
grpc_core::Json::Dump
std::string Dump(int indent=0) const
Definition: json_writer.cc:336
run_interop_tests.servers
servers
Definition: run_interop_tests.py:1288
grpc_core::XdsBootstrap::Node::cluster
std::string cluster
Definition: xds_bootstrap.h:45
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:55