View Source KubeProbex.Plug.PathValidator (Kube Probex v1.0.0)
A helper module for validating HTTP paths of incoming Kubernetes probe requests.
It provides functionality to check if an HTTP request matches the expected path for a Kubernetes probe (e.g., liveness, readiness).
Note
This is an internal module and is not intended for direct use.
Summary
Functions
Validates if the request's path matches the expected path for a Kubernetes probe.
Functions
@spec valid_path?(Plug.Conn.t(), keyword(), String.t()) :: boolean()
Validates if the request's path matches the expected path for a Kubernetes probe.
This function checks the request_path of an incoming Plug.Conn against a list
of allowed paths. If a custom path is provided in the plug_opts argument, it will use
that for validation. Otherwise, it falls back to the default_path.
Parameters
conn- The%Plug.Conn{}struct representing the incoming request.plug_opts- A keyword list of options passed to the probe plug, which may contain a:pathkey specifying custom paths.default_path- A string representing the default probe path to validate against.
Example
Assuming the default path:
iex> conn = %Plug.Conn{request_path: "/health/liveness"}
iex> opts = []
iex> KubeProbex.Plug.PathValidator.valid_path?(conn, opts, "/health/liveness")
trueWith a customized path:
iex> conn = %Plug.Conn{request_path: "/custom/liveness"}
iex> opts = [path: ["/custom/liveness"]]
iex> KubeProbex.Plug.PathValidator.valid_path?(conn, opts, "/health/liveness")
true