2 // Copyright 2019 gRPC authors.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H
20 #include <grpc/support/port_platform.h>
24 #include <grpc/impl/codegen/slice.h>
26 #include "src/core/lib/gprpp/inlined_vector.h"
27 #include "src/core/lib/gprpp/map.h"
28 #include "src/core/lib/gprpp/memory.h"
29 #include "src/core/lib/iomgr/error.h"
30 #include "src/core/lib/json/json.h"
36 struct MetadataValue {
37 enum class Type { MD_NULL, DOUBLE, STRING, BOOL, STRUCT, LIST };
38 Type type = Type::MD_NULL;
39 // TODO(roth): Once we can use C++17, these can be in a std::variant.
41 const char* string_value;
43 std::map<const char*, MetadataValue, StringLess> struct_value;
44 std::vector<MetadataValue> list_value;
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;
57 const char* type = nullptr;
58 grpc_json* config = nullptr;
62 const char* server_uri = nullptr;
63 InlinedVector<ChannelCreds, 1> channel_creds;
66 // If *error is not GRPC_ERROR_NONE after returning, then there was an
67 // error reading the file.
68 static std::unique_ptr<XdsBootstrap> ReadFromFile(grpc_error** error);
70 // Do not instantiate directly -- use ReadFromFile() above instead.
71 XdsBootstrap(grpc_slice contents, grpc_error** error);
74 // TODO(roth): We currently support only one server. Fix this when we
75 // add support for fallback for the xds channel.
76 const XdsServer& server() const { return servers_[0]; }
77 const Node* node() const { return node_.get(); }
80 grpc_error* ParseXdsServerList(grpc_json* json);
81 grpc_error* ParseXdsServer(grpc_json* json, size_t idx);
82 grpc_error* ParseChannelCredsArray(grpc_json* json, XdsServer* server);
83 grpc_error* ParseChannelCreds(grpc_json* json, size_t idx, XdsServer* server);
84 grpc_error* ParseNode(grpc_json* json);
85 grpc_error* ParseLocality(grpc_json* json);
87 InlinedVector<grpc_error*, 1> ParseMetadataStruct(
89 std::map<const char*, MetadataValue, StringLess>* result);
90 InlinedVector<grpc_error*, 1> ParseMetadataList(
91 grpc_json* json, std::vector<MetadataValue>* result);
92 grpc_error* ParseMetadataValue(grpc_json* json, size_t idx,
93 MetadataValue* result);
96 grpc_json* tree_ = nullptr;
98 InlinedVector<XdsServer, 1> servers_;
99 std::unique_ptr<Node> node_;
102 } // namespace grpc_core
104 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_XDS_XDS_BOOTSTRAP_H */