-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2024 gRPC authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from envoy.config.listener.v3 import api_listener_pb2 | ||
from envoy.config.listener.v3 import listener_pb2 | ||
from envoy.config.route.v3 import route_components_pb2 | ||
from envoy.config.route.v3 import route_pb2 | ||
from envoy.extensions.filters.http.router.v3 import router_pb2 | ||
from envoy.extensions.filters.network.http_connection_manager.v3 import ( | ||
http_connection_manager_pb2, | ||
) | ||
from google.protobuf import any_pb2 | ||
from google.protobuf import message | ||
|
||
|
||
def wrap_in_any(message: message.Message) -> any_pb2.Any: | ||
any_msg = any_pb2.Any() | ||
any_msg.Pack(message) | ||
return any_msg | ||
|
||
|
||
def build_listener(listener_name: str, cluster_name: str): | ||
hcm = http_connection_manager_pb2.HttpConnectionManager( | ||
route_config=route_pb2.RouteConfiguration( | ||
virtual_hosts=[ | ||
route_components_pb2.VirtualHost( | ||
domains=["*"], | ||
routes=[ | ||
route_components_pb2.Route( | ||
match=route_components_pb2.RouteMatch(prefix=""), | ||
route=route_components_pb2.RouteAction( | ||
cluster=cluster_name | ||
), | ||
) | ||
], | ||
) | ||
] | ||
), | ||
http_filters=[ | ||
http_connection_manager_pb2.HttpFilter( | ||
name="router", typed_config=wrap_in_any(router_pb2.Router()) | ||
) | ||
], | ||
) | ||
return listener_pb2.Listener( | ||
api_listener=api_listener_pb2.ApiListener( | ||
api_listener=wrap_in_any(hcm) | ||
), | ||
name=listener_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters