syntax = "proto3";

package envoy.type.matcher;

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

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

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

// [#protodoc-title: String matcher]

// Specifies the way to match a string.
// [#next-free-field: 7]
message StringMatcher {
  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 is not allowed, please use 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 prefix is not allowed, please use 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.
    // The regex grammar is defined `here
    // <https://en.cppreference.com/w/cpp/regex/ecmascript>`_.
    //
    // Examples:
    //
    // * The regex ``\d{3}`` matches the value *123*
    // * The regex ``\d{3}`` does not match the value *1234*
    // * The regex ``\d{3}`` does not match the value *123.456*
    //
    // .. attention::
    //   This field has been deprecated in favor of `safe_regex` as it is not safe for use with
    //   untrusted input in all cases.
    string regex = 4 [
      deprecated = true,
      (validate.rules).string = {max_bytes: 1024},
      (envoy.annotations.disallowed_by_default) = true
    ];

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

  // If true, indicates the exact/prefix/suffix 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 set to true.
  bool ignore_case = 6;
}

// Specifies a list of ways to match a string.
message ListStringMatcher {
  repeated StringMatcher patterns = 1 [(validate.rules).repeated = {min_items: 1}];
}
