Reqord.Config (reqord v0.4.0)
View SourceConfiguration 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}"
endThe context map contains:
context.test- Test name as an atomcontext.module- Test module namecontext.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.JasonDefault Record Mode
config :reqord, :default_mode, :noneCustom 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
@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"]
@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"]
@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
@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"
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"
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<...>}]
@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
@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
@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
@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"
@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
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"}]}
@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"]