// Copyright 2025 Envoy Project 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.

syntax = "proto3";

package envoy.extensions.filters.network.generic_proxy.v3;

import "xds/annotations/v3/status.proto";
import "xds/type/matcher/v3/matcher.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.network.generic_proxy.v3";
option java_outer_classname = "RouteProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/generic_proxy/v3;generic_proxyv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;
option (xds.annotations.v3.file_status).work_in_progress = true;

// [#protodoc-title: Generic Proxy Route Configuration]

message VirtualHost {
  // The name of the virtual host.
  string name = 1 [(validate.rules).string = {min_len: 1}];

  // A list of hosts that will be matched to this virtual host. Wildcard hosts are supported in
  // the suffix or prefix form.
  //
  // Host search order:
  //  1. Exact names: ``www.foo.com``.
  //  2. Suffix wildcards: ``*.foo.com`` or ``*-bar.foo.com``.
  //  3. Prefix wildcards: ``foo.*`` or ``foo-*``.
  //  4. Special wildcard ``*`` matching any host and will be the default virtual host.
  //
  // .. note::
  //
  //   The wildcard will not match the empty string.
  //   e.g. ``*-bar.foo.com`` will match ``baz-bar.foo.com`` but not ``-bar.foo.com``.
  //   The longest wildcards match first.
  //   Only a single virtual host in the entire route configuration can match on ``*``. A domain
  //   must be unique across all virtual hosts or the config will fail to load.
  repeated string hosts = 2 [(validate.rules).repeated = {min_items: 1}];

  // The match tree to use when resolving route actions for incoming requests.
  xds.type.matcher.v3.Matcher routes = 3 [(validate.rules).message = {required: true}];
}

// The generic proxy makes use of the xDS matching API for routing configurations.
//
// In the below example, we combine a top level tree matcher with a linear matcher to match
// the incoming requests, and send the matching requests to v1 of the upstream service.
//
// .. code-block:: yaml
//
//   name: example
//   routes:
//     matcher_tree:
//       input:
//         name: request-service
//         typed_config:
//           "@type": type.googleapis.com/envoy.extensions.filters.network.generic_proxy.matcher.v3.ServiceMatchInput
//       exact_match_map:
//         map:
//           service_name_0:
//             matcher:
//               matcher_list:
//                 matchers:
//                 - predicate:
//                     and_matcher:
//                       predicate:
//                       - single_predicate:
//                           input:
//                             name: request-properties
//                             typed_config:
//                               "@type": type.googleapis.com/envoy.extensions.filters.network.generic_proxy.matcher.v3.PropertyMatchInput
//                               property_name: version
//                           value_match:
//                             exact: v1
//                       - single_predicate:
//                           input:
//                             name: request-properties
//                             typed_config:
//                               "@type": type.googleapis.com/envoy.extensions.filters.network.generic_proxy.matcher.v3.PropertyMatchInput
//                               property_name: user
//                           value_match:
//                             exact: john
//                   on_match:
//                     action:
//                       name: route
//                       typed_config:
//                         "@type": type.googleapis.com/envoy.extensions.filters.network.generic_proxy.action.v3.routeAction
//                         cluster: cluster_0
message RouteConfiguration {
  // The name of the route configuration. For example, it might match route_config_name in
  // envoy.extensions.filters.network.generic_proxy.v3.Rds.
  string name = 1 [(validate.rules).string = {min_len: 1}];

  // The match tree to use when resolving route actions for incoming requests.
  // If no any virtual host is configured in the ``virtual_hosts`` field or no special wildcard
  // virtual host is configured, the ``routes`` field will be used as the default route table.
  // If both the wildcard virtual host and ``routes`` are configured, the configuration will fail
  // to load.
  xds.type.matcher.v3.Matcher routes = 2;

  // An array of virtual hosts that make up the route table.
  repeated VirtualHost virtual_hosts = 3;
}
