syntax = "proto3";

package envoy.extensions.filters.http.lua.v3;

import "envoy/config/core/v3/base.proto";

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

option java_package = "io.envoyproxy.envoy.extensions.filters.http.lua.v3";
option java_outer_classname = "LuaProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/lua/v3;luav3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Lua]
// Lua :ref:`configuration overview <config_http_filters_lua>`.
// [#extension: envoy.filters.http.lua]

message Lua {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.http.lua.v2.Lua";

  // The Lua code that Envoy will execute. This can be a very small script that
  // further loads code from disk if desired. Note that if JSON configuration is used, the code must
  // be properly escaped. YAML configuration may be easier to read since YAML supports multi-line
  // strings so complex scripts can be easily expressed inline in the configuration.
  string inline_code = 1 [(validate.rules).string = {min_len: 1}];

  // Map of named Lua source codes that can be referenced in :ref:`LuaPerRoute
  // <envoy_v3_api_msg_extensions.filters.http.lua.v3.LuaPerRoute>`. The Lua source codes can be
  // loaded from inline string or local files.
  //
  // Example:
  //
  // .. code-block:: yaml
  //
  //   source_codes:
  //     hello.lua:
  //       inline_string: |
  //         function envoy_on_response(response_handle)
  //           -- Do something.
  //         end
  //     world.lua:
  //       filename: /etc/lua/world.lua
  //
  map<string, config.core.v3.DataSource> source_codes = 2;
}

message LuaPerRoute {
  oneof override {
    option (validate.required) = true;

    // Disable the Lua filter for this particular vhost or route. If disabled is specified in
    // multiple per-filter-configs, the most specific one will be used.
    bool disabled = 1 [(validate.rules).bool = {const: true}];

    // A name of a Lua source code stored in
    // :ref:`Lua.source_codes <envoy_v3_api_field_extensions.filters.http.lua.v3.Lua.source_codes>`.
    string name = 2 [(validate.rules).string = {min_len: 1}];

    // A configured per-route Lua source code that can be served by RDS or provided inline.
    config.core.v3.DataSource source_code = 3;
  }
}
