syntax = "proto3";

package envoy.type.matcher.v3;

import "envoy/type/matcher/v3/regex.proto";

import "xds/core/v3/extension.proto";

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

option java_package = "io.envoyproxy.envoy.type.matcher.v3";
option java_outer_classname = "StringProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3;matcherv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: String matcher]

// Specifies the way to match a string.
// [#next-free-field: 9]
message StringMatcher {
  option (udpa.annotations.versioning).previous_message_type = "envoy.type.matcher.StringMatcher";

  reserved 4;

  reserved "regex";

  oneof match_pattern {
    option (validate.required) = true;

    // The input string must match exactly the string specified here.
    //
    // Examples:
    //
    // * ``abc`` only matches the value ``abc``.
    string exact = 1;

    // The input string must have the prefix specified here.
    //
    // .. note::
    //
    //  Empty prefix match is not allowed, please use ``safe_regex`` instead.
    //
    // Examples:
    //
    // * ``abc`` matches the value ``abc.xyz``
    string prefix = 2 [(validate.rules).string = {min_len: 1}];

    // The input string must have the suffix specified here.
    //
    // .. note::
    //
    //  Empty suffix match is not allowed, please use ``safe_regex`` instead.
    //
    // Examples:
    //
    // * ``abc`` matches the value ``xyz.abc``
    string suffix = 3 [(validate.rules).string = {min_len: 1}];

    // The input string must match the regular expression specified here.
    RegexMatcher safe_regex = 5 [(validate.rules).message = {required: true}];

    // The input string must have the substring specified here.
    //
    // .. note::
    //
    //  Empty contains match is not allowed, please use ``safe_regex`` instead.
    //
    // Examples:
    //
    // * ``abc`` matches the value ``xyz.abc.def``
    string contains = 7 [(validate.rules).string = {min_len: 1}];

    // Use an extension as the matcher type.
    // [#extension-category: envoy.string_matcher]
    xds.core.v3.TypedExtensionConfig custom = 8;
  }

  // If ``true``, indicates the exact/prefix/suffix/contains matching should be case insensitive. This
  // has no effect for the ``safe_regex`` match.
  // For example, the matcher ``data`` will match both input string ``Data`` and ``data`` if this option
  // is set to ``true``.
  bool ignore_case = 6;
}

// Specifies a list of ways to match a string.
message ListStringMatcher {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.type.matcher.ListStringMatcher";

  repeated StringMatcher patterns = 1 [(validate.rules).repeated = {min_items: 1}];
}
