Packages
altworx_runbox
21.2.0
25.0.0
24.0.0
23.1.0
23.0.0
22.2.0
22.1.0
22.0.0
21.2.0
21.1.2
21.1.1
21.1.0
21.0.0
20.0.0
19.0.0
18.0.0
17.2.0
17.1.0
17.0.1
17.0.0
16.2.0
16.1.0
16.0.0
15.0.0
14.1.0
14.0.1
14.0.0
13.0.3
13.0.2
13.0.1
13.0.0
12.1.0
12.0.0
11.0.1
11.0.0
10.0.0
9.0.0
8.0.0
7.0.1
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.1.3
0.1.2
0.1.1
0.1.0
Runbox is a library for running Altworx scenarios.
Current section
Files
Jump to
Current section
Files
lib/runbox/scenario/config.ex
defmodule Runbox.Scenario.Config do
@moduledoc """
Provides configuration to a scenario.
"""
alias Runbox.Utils.Path, as: PathUtils
@doc """
Read file from the config dir.
The file is located in the configuration directory, in a folder matching the `scenario_id` param.
The file is read if it exists and content is returned as `{:ok, content}`, otherwise `{:error,
reason}` is returned.
"""
@spec read_file(String.t() | atom(), String.t()) :: {:ok, binary()} | {:error, File.posix()}
def read_file(scenario_id, file_path) do
path = resolve_file(scenario_id, file_path)
File.read(path)
end
@doc """
Resolves a path to a file in scenario config.
The file is located in the configuration directory, in a folder matching the `scenario_id` param.
This function resolves the path so that it can be used with `File` functions directly. The
existence of the file is not verified. Note if you want to just read the file, you can use
`read_file/2`, this function should be used when you need to handle the file in a special manner
(e.g. streaming).
"""
@spec resolve_file(String.t() | atom(), String.t()) :: String.t()
def resolve_file(scenario_id, file_path) do
config_dir = PathUtils.resolve_path(Application.fetch_env!(:runbox, :scenario_config_dir))
Path.join([config_dir, to_string(scenario_id), file_path])
end
end