Reqord.Config (reqord v0.4.0)

View Source

Configuration management for Reqord.

This module provides centralized access to all configurable settings, with sensible defaults and the ability to override via application config.

Configuration Options

Cassette Directory

config :reqord, :cassette_dir, "test/support/cassettes"

Cassette Path Builder

Configure a custom function to build cassette paths from test context:

config :reqord,
  cassette_path_builder: fn context ->
    provider = context.tags[:provider] || "default"
    model = context.tags[:model] || "default"
    test_name = context.test |> Atom.to_string() |> String.replace(~r/^test /, "")
    "#{provider}/#{model}/#{test_name}"
  end

The context map contains:

  • context.test - Test name as an atom
  • context.module - Test module name
  • context.tags - Map of test tags
  • Any other test context values

See Reqord.Case for more details on cassette naming strategies.

Auth Parameters (for redaction)

config :reqord, :auth_params, ~w[token apikey api_key access_token refresh_token jwt bearer password secret]

Auth Headers (for redaction)

config :reqord, :auth_headers, ~w[authorization auth x-api-key x-auth-token x-access-token cookie]

Volatile Headers (removed from responses)

config :reqord, :volatile_headers, ~w[date server set-cookie request-id x-request-id x-amzn-trace-id]

JSON Library

config :reqord, :json_library, Reqord.JSON.Jason

Default Record Mode

config :reqord, :default_mode, :none

Custom Filters (for additional redaction)

config :reqord, :filters, [
  {"<API_KEY>", fn -> System.get_env("API_KEY") end},
  {"<SHOPIFY_TOKEN>", fn -> Application.get_env(:my_app, :shopify_token) end}
]

Summary

Functions

Gets the list of auth header names that should be redacted.

Gets the list of auth parameter names that should be redacted.

Get the binary storage strategy.

Gets the configured cassette directory.

Gets the path for a given cassette name.

Gets custom filters for additional redaction.

Gets the default record mode.

Gets the configured JSON library module.

Get the maximum inline size for response bodies before using external storage.

Get the object directory for external storage.

Get the stream replay speed multiplier.

Validates the current configuration and returns any errors.

Gets the list of volatile headers that should be removed from responses.

Functions

auth_headers()

@spec auth_headers() :: [String.t()]

Gets the list of auth header names that should be redacted.

These headers will be replaced with "<REDACTED>" in cassette files.

Examples

iex> Reqord.Config.auth_headers()
["authorization", "auth", "x-api-key", "x-auth-token", "x-access-token", "cookie"]

auth_params()

@spec auth_params() :: [String.t()]

Gets the list of auth parameter names that should be redacted.

These parameters will be replaced with "<REDACTED>" in cassette files.

Examples

iex> Reqord.Config.auth_params()
["token", "apikey", "api_key", "access_token", "refresh_token", "jwt", "bearer", "password", "secret"]

binary_storage()

@spec binary_storage() :: :inline | :external | :auto

Get the binary storage strategy.

Returns

  • :inline - Always store inline as base64
  • :external - Always use external storage for binary content
  • :auto - Automatic based on size threshold (default)

Examples

iex> Reqord.Config.binary_storage()
:auto

iex> Application.put_env(:reqord, :binary_storage, :external)
iex> Reqord.Config.binary_storage()
:external

cassette_dir()

@spec cassette_dir() :: String.t()

Gets the configured cassette directory.

Defaults to "test/support/cassettes" if not configured.

Examples

iex> Reqord.Config.cassette_dir()
"test/support/cassettes"

# With custom config
iex> Application.put_env(:reqord, :cassette_dir, "test/cassettes")
iex> Reqord.Config.cassette_dir()
"test/cassettes"

cassette_path(cassette_name)

@spec cassette_path(String.t()) :: String.t()

Gets the path for a given cassette name.

Combines the cassette directory with the cassette name. Does NOT create directories - that's handled by storage backends when needed.

Examples

iex> Reqord.Config.cassette_path("my_test")
"test/support/cassettes/my_test.jsonl"

custom_filters()

@spec custom_filters() :: [{String.t(), (-> String.t() | nil)}]

Gets custom filters for additional redaction.

Returns a list of {replacement, value_function} tuples.

Examples

iex> Reqord.Config.custom_filters()
[]

# With custom filters configured
iex> Application.put_env(:reqord, :filters, [{"<API_KEY>", fn -> "secret123" end}])
iex> Reqord.Config.custom_filters()
[{"<API_KEY>", #Function<...>}]

default_mode()

@spec default_mode() :: :once | :new_episodes | :all | :none

Gets the default record mode.

Defaults to :none if not configured.

Examples

iex> Reqord.Config.default_mode()
:none

json_library()

@spec json_library() :: module()

Gets the configured JSON library module.

Defaults to Reqord.JSON.Jason if not configured.

Examples

iex> Reqord.Config.json_library()
Reqord.JSON.Jason

max_inline_size()

@spec max_inline_size() :: pos_integer()

Get the maximum inline size for response bodies before using external storage.

Examples

iex> Reqord.Config.max_inline_size()
1048576

iex> Application.put_env(:reqord, :max_inline_size, 2_000_000)
iex> Reqord.Config.max_inline_size()
2000000

object_directory()

@spec object_directory() :: String.t()

Get the object directory for external storage.

Examples

iex> Reqord.Config.object_directory()
"test/support/cassettes/objects"

iex> Application.put_env(:reqord, :object_directory, "custom/objects")
iex> Reqord.Config.object_directory()
"custom/objects"

stream_speed()

@spec stream_speed() :: number()

Get the stream replay speed multiplier.

Returns

  • 0 - Instant replay (default for tests)
  • 1.0 - Real-time replay
  • > 1.0 - Accelerated replay

Examples

iex> Reqord.Config.stream_speed()
0

iex> Application.put_env(:reqord, :stream_speed, 1.0)
iex> Reqord.Config.stream_speed()
1.0

validate()

@spec validate() :: :ok | {:error, [{atom(), String.t()}]}

Validates the current configuration and returns any errors.

Useful for debugging configuration issues.

Examples

iex> Reqord.Config.validate()
:ok

iex> Application.put_env(:reqord, :cassette_dir, "/nonexistent/readonly")
iex> Reqord.Config.validate()
{:error, [{:cassette_dir, "Directory /nonexistent/readonly is not writable"}]}

volatile_headers()

@spec volatile_headers() :: [String.t()]

Gets the list of volatile headers that should be removed from responses.

These headers change between requests and would make cassettes unreliable.

Examples

iex> Reqord.Config.volatile_headers()
["date", "server", "set-cookie", "request-id", "x-request-id", "x-amzn-trace-id"]