Current section
Files
Jump to
Current section
Files
src/testcontainer@internal@config.erl
-module(testcontainer@internal@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/testcontainer/internal/config.gleam").
-export([parse_pull_policy/1, load/0]).
-export_type([pull_policy/0, registry_auth/0, config/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type pull_policy() :: always | if_missing | never.
-type registry_auth() :: {registry_auth, binary(), cowl:secret(binary())}.
-type config() :: {config,
binary(),
boolean(),
pull_policy(),
gleam@option:option(binary()),
gleam@option:option(registry_auth()),
integer()}.
-file("src/testcontainer/internal/config.gleam", 38).
?DOC(false).
-spec parse_pull_policy(binary()) -> pull_policy().
parse_pull_policy(Value) ->
case string:lowercase(Value) of
<<"always"/utf8>> ->
always;
<<"never"/utf8>> ->
never;
_ ->
if_missing
end.
-file("src/testcontainer/internal/config.gleam", 48).
?DOC(false).
-spec load() -> config().
load() ->
Docker_host = envie:get_string(
<<"DOCKER_HOST"/utf8>>,
<<"unix:///var/run/docker.sock"/utf8>>
),
Keep = envie:get_bool(<<"TESTCONTAINERS_KEEP"/utf8>>, false),
Pull_policy = parse_pull_policy(
envie:get_string(
<<"TESTCONTAINERS_PULL_POLICY"/utf8>>,
<<"missing"/utf8>>
)
),
Host_override = case envie:get_string(
<<"TESTCONTAINERS_HOST_OVERRIDE"/utf8>>,
<<""/utf8>>
) of
<<""/utf8>> ->
none;
H ->
{some, H}
end,
Registry_auth = case {envie:get_string(
<<"TESTCONTAINERS_REGISTRY_USER"/utf8>>,
<<""/utf8>>
),
envie:get_string(
<<"TESTCONTAINERS_REGISTRY_PASSWORD"/utf8>>,
<<""/utf8>>
)} of
{<<""/utf8>>, _} ->
none;
{_, <<""/utf8>>} ->
none;
{User, Pass} ->
{some, {registry_auth, User, cowl:secret(Pass)}}
end,
Stop_timeout_sec = envie:get_int(<<"TESTCONTAINERS_STOP_TIMEOUT"/utf8>>, 10),
{config,
Docker_host,
Keep,
Pull_policy,
Host_override,
Registry_auth,
Stop_timeout_sec}.