Packages

A tool to audit Erlang & Elixir dependencies, to make sure your Gleam ✨ projects really sparkle!

Retired package: Security issue - Vulnerability warnings were never emitted due to an inverted advisory filter. Upgrade to 3.3.1 or 4.0.0-rc2+.

Current section

Files

Jump to
go_over src go_over@config.erl
Raw

src/go_over@config.erl

-module(go_over@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([filter_packages/2, filter_indirect/2, filter_dev_dependencies/2, filter_advisory_ids/2, filter_severity/2, parse_config_format/1, read_config/1, merge_flags_and_config/2, spin_up/2]).
-export_type([format/0, config/0, flags/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 format() :: minimal | detailed | json.
-type config() :: {config,
list(binary()),
boolean(),
boolean(),
boolean(),
boolean(),
format(),
boolean(),
boolean(),
go_over@hex@puller:puller(),
list(binary()),
list(binary()),
list(binary()),
list(binary()),
boolean()}.
-type flags() :: {flags,
boolean(),
boolean(),
boolean(),
boolean(),
boolean(),
boolean(),
gleam@option:option(format())}.
-file("src/go_over/config.gleam", 147).
?DOC(false).
-spec filter_packages(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_packages(Conf, Pkgs) ->
gxyz@list:reject_contains_tap(
Pkgs,
fun(Pkg) -> erlang:element(2, Pkg) end,
erlang:element(12, Conf)
).
-file("src/go_over/config.gleam", 151).
?DOC(false).
-spec filter_indirect(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_indirect(Conf, Pkgs) ->
case erlang:element(4, Conf) of
false ->
Pkgs;
true ->
gleam@list:filter(Pkgs, fun(Pkg) -> erlang:element(5, Pkg) end)
end.
-file("src/go_over/config.gleam", 158).
?DOC(false).
-spec filter_dev_dependencies(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_dev_dependencies(Conf, Pkgs) ->
case erlang:element(15, Conf) of
false ->
Pkgs;
true ->
gxyz@list:reject_contains_tap(
Pkgs,
fun(Pkg) -> erlang:element(2, Pkg) end,
erlang:element(2, Conf)
)
end.
-file("src/go_over/config.gleam", 168).
?DOC(false).
-spec filter_advisory_ids(
config(),
list(go_over@advisories@advisories:advisory())
) -> list(go_over@advisories@advisories:advisory()).
filter_advisory_ids(Conf, Advisories) ->
gxyz@list:reject_contains_tap(
Advisories,
fun(Adv) -> erlang:element(2, Adv) end,
erlang:element(14, Conf)
).
-file("src/go_over/config.gleam", 175).
?DOC(false).
-spec filter_severity(config(), list(go_over@warning:warning())) -> list(go_over@warning:warning()).
filter_severity(Conf, Warnings) ->
gxyz@list:reject_contains_tap(
Warnings,
fun(W) -> go_over@warning:severity_as_string(erlang:element(7, W)) end,
erlang:element(13, Conf)
).
-file("src/go_over/config.gleam", 183).
?DOC(false).
-spec parse_config_format(binary()) -> gleam@option:option(format()).
parse_config_format(Val) ->
case string:lowercase(Val) of
<<"json"/utf8>> ->
{some, json};
<<"detailed"/utf8>> ->
{some, detailed};
<<"minimal"/utf8>> ->
{some, minimal};
Format ->
go_over@util@print:warning(
<<<<"Invalid format '"/utf8, Format/binary>>/binary,
"' valid options are ['json', 'detailed', 'minimal'], defaulting to minimal"/utf8>>
),
none
end.
-file("src/go_over/config.gleam", 199).
?DOC(false).
-spec parse_puller(binary()) -> gleam@option:option(go_over@hex@puller:puller()).
parse_puller(Name) ->
case Name of
<<"curl"/utf8>> ->
{some, curl};
<<"wget"/utf8>> ->
{some, wget};
<<"httpie"/utf8>> ->
{some, httpie};
_ ->
go_over@util@print:warning(
<<<<"Invalid puller '"/utf8, Name/binary>>/binary,
"' valid options are ['curl', 'wget', 'httpie'], defaulting to curl"/utf8>>
),
none
end.
-file("src/go_over/config.gleam", 215).
?DOC(false).
-spec toml_as_string(tom:toml()) -> gleam@option:option(binary()).
toml_as_string(Toml) ->
case Toml of
{string, S} ->
{some, S};
_ ->
go_over@util@print:warning(
<<"could not parse config value "/utf8,
(gleam@string:inspect(Toml))/binary>>
),
shellout_ffi:os_exit(1),
erlang:error(#{gleam_error => panic,
message => <<"Unreachable, please create an issue in https://github.com/bwireman/go-over if you see this"/utf8>>,
module => <<"go_over/config"/utf8>>,
function => <<"toml_as_string"/utf8>>,
line => 221})
end.
-file("src/go_over/config.gleam", 59).
?DOC(false).
-spec read_config(binary()) -> config().
read_config(Path) ->
Res = begin
_pipe = simplifile:read(Path),
gxyz@cli:hard_fail_with_msg(
_pipe,
<<"could not read config file at "/utf8, Path/binary>>
)
end,
Gleam = begin
_pipe@1 = tom:parse(Res),
gxyz@cli:hard_fail_with_msg(
_pipe@1,
<<"could not read config file at "/utf8, Path/binary>>
)
end,
Dev_deps = begin
_pipe@2 = tom:get_table(Gleam, [<<"dev-dependencies"/utf8>>]),
_pipe@3 = gleam@result:unwrap(_pipe@2, maps:new()),
maps:keys(_pipe@3)
end,
Go_over = begin
_pipe@4 = tom:get_table(Gleam, [<<"go-over"/utf8>>]),
gleam@result:unwrap(_pipe@4, maps:new())
end,
Cache = begin
_pipe@5 = tom:get_bool(Go_over, [<<"cache"/utf8>>]),
gleam@result:unwrap(_pipe@5, true)
end,
Outdated = begin
_pipe@6 = tom:get_bool(Go_over, [<<"outdated"/utf8>>]),
gleam@result:unwrap(_pipe@6, false)
end,
Format = begin
_pipe@7 = tom:get_string(Go_over, [<<"format"/utf8>>]),
_pipe@8 = gleam@result:unwrap(_pipe@7, <<"minimal"/utf8>>),
_pipe@9 = string:lowercase(_pipe@8),
_pipe@10 = parse_config_format(_pipe@9),
gleam@option:unwrap(_pipe@10, minimal)
end,
Puller = begin
_pipe@11 = tom:get_string(Go_over, [<<"puller"/utf8>>]),
_pipe@12 = gleam@result:unwrap(_pipe@11, <<"curl"/utf8>>),
_pipe@13 = string:lowercase(_pipe@12),
_pipe@14 = parse_puller(_pipe@13),
gleam@option:unwrap(_pipe@14, curl)
end,
Global = begin
_pipe@15 = tom:get_bool(Go_over, [<<"global"/utf8>>]),
gleam@result:unwrap(_pipe@15, true)
end,
Allowed_licenses = begin
_pipe@16 = tom:get_array(Go_over, [<<"allowed_licenses"/utf8>>]),
_pipe@17 = gleam@result:map(
_pipe@16,
fun(_capture) -> gleam@list:map(_capture, fun toml_as_string/1) end
),
_pipe@18 = gleam@result:map(_pipe@17, fun gleam@option:values/1),
gleam@result:unwrap(_pipe@18, [])
end,
Ignore = begin
_pipe@19 = tom:get_table(Go_over, [<<"ignore"/utf8>>]),
gleam@result:unwrap(_pipe@19, maps:new())
end,
Ignore_indirect = begin
_pipe@20 = tom:get_bool(Ignore, [<<"indirect"/utf8>>]),
gleam@result:unwrap(_pipe@20, false)
end,
Ignore_packages = begin
_pipe@21 = tom:get_array(Ignore, [<<"packages"/utf8>>]),
_pipe@22 = gleam@result:unwrap(_pipe@21, []),
_pipe@23 = gleam@list:map(_pipe@22, fun toml_as_string/1),
gleam@option:values(_pipe@23)
end,
Ignore_severity = begin
_pipe@24 = tom:get_array(Ignore, [<<"severity"/utf8>>]),
_pipe@25 = gleam@result:unwrap(_pipe@24, []),
_pipe@26 = gleam@list:map(_pipe@25, fun toml_as_string/1),
gleam@option:values(_pipe@26)
end,
Ignore_ids = begin
_pipe@27 = tom:get_array(Ignore, [<<"ids"/utf8>>]),
_pipe@28 = gleam@result:unwrap(_pipe@27, []),
_pipe@29 = gleam@list:map(_pipe@28, fun toml_as_string/1),
gleam@option:values(_pipe@29)
end,
Ignore_dev_dependencies = begin
_pipe@30 = tom:get_bool(Ignore, [<<"dev_dependencies"/utf8>>]),
gleam@result:unwrap(_pipe@30, false)
end,
{config,
Dev_deps,
Outdated,
Ignore_indirect,
not Cache,
false,
Format,
false,
Global,
Puller,
Allowed_licenses,
Ignore_packages,
Ignore_severity,
Ignore_ids,
Ignore_dev_dependencies}.
-file("src/go_over/config.gleam", 227).
?DOC(false).
-spec help_message(clip@arg_info:arg_info()) -> binary().
help_message(Args) ->
_pipe = {arg_info,
erlang:element(2, Args),
erlang:element(3, Args),
gxyz@list:reject(
erlang:element(4, Args),
fun(F) -> erlang:element(2, F) =:= <<"fake"/utf8>> end
),
erlang:element(5, Args)},
_pipe@2 = clip@arg_info:help_text(
_pipe,
<<"go_over"/utf8>>,
<<(begin
_pipe@1 = <<" ____ ____ ____ _ _____ _____
/ __ `/ __ \\ / __ \\ | / / _ \\/ ___/
/ /_/ / /_/ / / /_/ / |/ / __/ /
\\__, /\\____/____\\____/|___/\\___/_/
/____/ /_____/
version 3.0.0
"/utf8>>,
go_over@util@print:format_high(_pipe@1)
end)/binary,
"🕵️ Audit Erlang & Elixir dependencies, to make sure your gleam projects really ✨ sparkle!"/utf8>>
),
gleam_stdlib:crop_string(_pipe@2, <<" "/utf8>>).
-file("src/go_over/config.gleam", 250).
?DOC(false).
-spec merge_flags_and_config(flags(), config()) -> config().
merge_flags_and_config(Flags, Cfg) ->
Global = case erlang:element(6, Flags) of
true ->
true;
false ->
erlang:element(9, Cfg)
end,
{config,
erlang:element(2, Cfg),
erlang:element(4, Flags) orelse erlang:element(3, Cfg),
erlang:element(4, Cfg) orelse erlang:element(5, Flags),
erlang:element(2, Flags) orelse erlang:element(5, Cfg),
erlang:element(3, Flags),
gleam@option:unwrap(erlang:element(8, Flags), erlang:element(7, Cfg)),
erlang:element(7, Flags),
Global,
erlang:element(10, Cfg),
erlang:element(11, Cfg),
erlang:element(12, Cfg),
erlang:element(13, Cfg),
erlang:element(14, Cfg),
erlang:element(15, Cfg)}.
-file("src/go_over/config.gleam", 274).
?DOC(false).
-spec spin_up(config(), list(binary())) -> {ok, config()} | {error, binary()}.
spin_up(Cfg, Argv) ->
_pipe = clip:command(
begin
clip:parameter(
fun(Force) ->
clip:parameter(
fun(Outdated) ->
clip:parameter(
fun(Ignore_indirect) ->
clip:parameter(
fun(Global) ->
clip:parameter(
fun(Fake) ->
clip:parameter(
fun(Verbose) ->
clip:parameter(
fun(Format) ->
merge_flags_and_config(
{flags,
Force,
Fake,
Outdated,
Ignore_indirect,
Global,
Verbose,
Format},
Cfg
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@1 = clip:flag(
_pipe,
clip@flag:help(
clip@flag:new(<<"force"/utf8>>),
<<"Force pulling new data even if the cached data is still valid"/utf8>>
)
),
_pipe@2 = clip:flag(
_pipe@1,
clip@flag:help(
clip@flag:new(<<"outdated"/utf8>>),
<<"Additionally check if newer versions of dependencies exist"/utf8>>
)
),
_pipe@3 = clip:flag(
_pipe@2,
clip@flag:help(
clip@flag:new(<<"ignore-indirect"/utf8>>),
<<"Ignore all warnings for indirect dependencies"/utf8>>
)
),
_pipe@4 = clip:flag(
_pipe@3,
clip@flag:help(
clip@flag:new(<<"global"/utf8>>),
<<"Cache data globally in user's home directory for use by multiple projects"/utf8>>
)
),
_pipe@5 = clip:flag(_pipe@4, clip@flag:new(<<"fake"/utf8>>)),
_pipe@6 = clip:flag(
_pipe@5,
clip@flag:help(
clip@flag:new(<<"verbose"/utf8>>),
<<"Print progress as packages are checked"/utf8>>
)
),
_pipe@10 = clip:opt(
_pipe@6,
begin
_pipe@7 = clip@opt:new(<<"format"/utf8>>),
_pipe@8 = clip@opt:help(
_pipe@7,
<<"Specify the output format of any warnings, [minimal, verbose, json]"/utf8>>
),
_pipe@9 = clip@opt:map(_pipe@8, fun parse_config_format/1),
clip@opt:default(_pipe@9, none)
end
),
_pipe@11 = clip:help(_pipe@10, clip@help:custom(fun help_message/1)),
clip:run(_pipe@11, gxyz@cli:strip_js_from_argv(Argv)).