GRPC Core  9.0.0
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_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H
19 
21 
22 #include <vector>
23 
25 
27 #include "src/core/lib/gprpp/map.h"
30 #include "src/core/lib/json/json.h"
31 
32 namespace grpc_core {
33 
34 class XdsBootstrap {
35  public:
36  struct MetadataValue {
37  enum class Type { MD_NULL, DOUBLE, STRING, BOOL, STRUCT, LIST };
39  // TODO(roth): Once we can use C++17, these can be in a std::variant.
40  double double_value;
41  const char* string_value;
42  bool bool_value;
43  std::map<const char*, MetadataValue, StringLess> struct_value;
44  std::vector<MetadataValue> list_value;
45  };
46 
47  struct Node {
48  const char* id = nullptr;
49  const char* cluster = nullptr;
50  const char* locality_region = nullptr;
51  const char* locality_zone = nullptr;
52  const char* locality_subzone = nullptr;
53  std::map<const char*, MetadataValue, StringLess> metadata;
54  };
55 
56  struct ChannelCreds {
57  const char* type = nullptr;
58  grpc_json* config = nullptr;
59  };
60 
61  // If *error is not GRPC_ERROR_NONE after returning, then there was an
62  // error reading the file.
63  static std::unique_ptr<XdsBootstrap> ReadFromFile(grpc_error** error);
64 
65  // Do not instantiate directly -- use ReadFromFile() above instead.
66  XdsBootstrap(grpc_slice contents, grpc_error** error);
67  ~XdsBootstrap();
68 
69  const char* server_uri() const { return server_uri_; }
71  return channel_creds_;
72  }
73  const Node* node() const { return node_.get(); }
74 
75  private:
76  grpc_error* ParseXdsServer(grpc_json* json);
77  grpc_error* ParseChannelCredsArray(grpc_json* json);
78  grpc_error* ParseChannelCreds(grpc_json* json, size_t idx);
79  grpc_error* ParseNode(grpc_json* json);
80  grpc_error* ParseLocality(grpc_json* json);
81 
82  InlinedVector<grpc_error*, 1> ParseMetadataStruct(
83  grpc_json* json,
84  std::map<const char*, MetadataValue, StringLess>* result);
85  InlinedVector<grpc_error*, 1> ParseMetadataList(
86  grpc_json* json, std::vector<MetadataValue>* result);
87  grpc_error* ParseMetadataValue(grpc_json* json, size_t idx,
88  MetadataValue* result);
89 
90  grpc_slice contents_;
91  grpc_json* tree_ = nullptr;
92 
93  const char* server_uri_ = nullptr;
94  InlinedVector<ChannelCreds, 1> channel_creds_;
95  std::unique_ptr<Node> node_;
96 };
97 
98 } // namespace grpc_core
99 
100 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H */
Definition: inlined_vector.h:60
Definition: xds_bootstrap.h:34
const char * server_uri() const
Definition: xds_bootstrap.h:69
const InlinedVector< ChannelCreds, 1 > & channel_creds() const
Definition: xds_bootstrap.h:70
const Node * node() const
Definition: xds_bootstrap.h:73
static std::unique_ptr< XdsBootstrap > ReadFromFile(grpc_error **error)
Definition: xds_bootstrap.cc:32
~XdsBootstrap()
Definition: xds_bootstrap.cc:101
XdsBootstrap(grpc_slice contents, grpc_error **error)
Definition: xds_bootstrap.cc:45
Round Robin Policy.
Definition: backend_metric.cc:24
Definition: xds_bootstrap.h:56
grpc_json * config
Definition: xds_bootstrap.h:58
const char * type
Definition: xds_bootstrap.h:57
Definition: xds_bootstrap.h:36
Type
Definition: xds_bootstrap.h:37
double double_value
Definition: xds_bootstrap.h:40
bool bool_value
Definition: xds_bootstrap.h:42
const char * string_value
Definition: xds_bootstrap.h:41
std::map< const char *, MetadataValue, StringLess > struct_value
Definition: xds_bootstrap.h:43
std::vector< MetadataValue > list_value
Definition: xds_bootstrap.h:44
Type type
Definition: xds_bootstrap.h:38
Definition: xds_bootstrap.h:47
const char * locality_subzone
Definition: xds_bootstrap.h:52
const char * locality_zone
Definition: xds_bootstrap.h:51
const char * locality_region
Definition: xds_bootstrap.h:50
std::map< const char *, MetadataValue, StringLess > metadata
Definition: xds_bootstrap.h:53
const char * cluster
Definition: xds_bootstrap.h:49
Definition: error_internal.h:39
Definition: json.h:32
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice.h:60