-module(go_over). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([main/0]). -export_type([flags/0]). -type flags() :: {flags, boolean(), boolean(), boolean(), boolean(), gleam@option:option(go_over@config:format())}. -file("/home/bwireman/src/go-over/src/go_over.gleam", 30). -spec merge_flags_and_config(flags(), go_over@config:config()) -> go_over@config:config(). merge_flags_and_config(Flgs, Cfg) -> {config, erlang:element(2, Cfg), erlang:element(3, Cfg), erlang:element(4, Cfg) orelse erlang:element(4, Flgs), erlang:element(5, Cfg) orelse erlang:element(5, Flgs), erlang:element(2, Flgs), erlang:element(3, Flgs), gleam@option:unwrap(erlang:element(6, Flgs), erlang:element(8, Cfg)), erlang:element(9, Cfg), erlang:element(10, Cfg), erlang:element(11, Cfg), erlang:element(12, Cfg)}. -file("/home/bwireman/src/go-over/src/go_over.gleam", 46). -spec spin_up(go_over@config:config()) -> go_over@config:config(). spin_up(Cfg) -> Args = shellout_ffi:start_arguments(), Format = begin _pipe = gleam@list:find( Args, fun(Arg) -> gleam@string:starts_with(Arg, <<"--format"/utf8>>) end ), _pipe@1 = gleam@result:'try'( _pipe, fun(Arg@1) -> gleam@string:split_once(Arg@1, <<"="/utf8>>) end ), _pipe@2 = gleam@result:map(_pipe@1, fun(Arg@2) -> case Arg@2 of {_, Val} -> Val end end), _pipe@3 = gleam@result:map( _pipe@2, fun go_over@config:parse_config_format/1 ), gleam@option:from_result(_pipe@3) end, Flags = {flags, go_over@util@util:has_flag(Args, <<"force"/utf8>>), go_over@util@util:has_flag(Args, <<"fake"/utf8>>), go_over@util@util:has_flag(Args, <<"outdated"/utf8>>), go_over@util@util:has_flag(Args, <<"ignore-indirect"/utf8>>), Format}, merge_flags_and_config(Flags, Cfg). -file("/home/bwireman/src/go-over/src/go_over.gleam", 72). -spec get_vulnerable_packages( list(go_over@packages:package()), go_over@config:config() ) -> list(go_over@warning:warning()). get_vulnerable_packages(Pkgs, Conf) -> _pipe = go_over@advisories@advisories:check_for_advisories( Pkgs, erlang:element(6, Conf) orelse not erlang:element(3, Conf) ), _pipe@1 = gleam@list:map( _pipe, fun(P) -> {Pkg, Adv} = P, {Pkg, go_over@config:filter_advisory_ids(Conf, Adv)} end ), _pipe@2 = gleam@list:filter(_pipe@1, fun(P@1) -> case P@1 of {_, []} -> false; _ -> true end end), gleam@list:flat_map( _pipe@2, fun(P@2) -> {Pkg@1, Adv@1} = P@2, go_over@warning:adv_to_warning(Pkg@1, Adv@1) end ). -file("/home/bwireman/src/go-over/src/go_over.gleam", 95). -spec get_retired_packges( list(go_over@packages:package()), go_over@config:config() ) -> list(go_over@warning:warning()). get_retired_packges(Pkgs, Conf) -> _pipe = Pkgs, _pipe@1 = gleam@list:map( _pipe, fun(Pkg) -> case go_over@retired@retired:check_retired( Pkg, erlang:element(6, Conf) orelse not erlang:element(3, Conf) ) of {some, Ret} -> {some, {Pkg, Ret}}; none -> none end end ), _pipe@2 = gleam@option:values(_pipe@1), gleam@list:map( _pipe@2, fun(P) -> {Pkg@1, Ret@1} = P, go_over@warning:retired_to_warning(Pkg@1, Ret@1) end ). -file("/home/bwireman/src/go-over/src/go_over.gleam", 113). -spec get_outdated_packages( list(go_over@packages:package()), go_over@config:config() ) -> list(go_over@warning:warning()). get_outdated_packages(Pkgs, Conf) -> _pipe = Pkgs, _pipe@1 = gleam@list:map( _pipe, fun(Pkg) -> case go_over@retired@outdated:check_outdated( Pkg, erlang:element(6, Conf) orelse not erlang:element(3, Conf) ) of {some, Ret} -> {some, {Pkg, Ret}}; none -> none end end ), _pipe@2 = gleam@option:values(_pipe@1), gleam@list:map( _pipe@2, fun(P) -> {Pkg@1, Ret@1} = P, go_over@warning:outdated_to_warning(Pkg@1, Ret@1) end ). -file("/home/bwireman/src/go-over/src/go_over.gleam", 131). -spec print_warnings_count(list(go_over@warning:warning())) -> nil. print_warnings_count(Vulns) -> _pipe = (<<<<<<"⛔ "/utf8, (gleam@int:to_string(erlang:length(Vulns)))/binary>>/binary, " WARNING(s) FOUND!"/utf8>>/binary, (<<"\n-----------------------------------------------\n"/utf8>>)/binary>>), gleam@io:print_error(_pipe). -file("/home/bwireman/src/go-over/src/go_over.gleam", 141). -spec print_warnings(list(go_over@warning:warning()), go_over@config:config()) -> nil. print_warnings(Vulns, Conf) -> case erlang:element(8, Conf) of minimal -> print_warnings_count(Vulns), _pipe = Vulns, _pipe@1 = gleam@list:map( _pipe, fun go_over@warning:format_as_string_minimal/1 ), _pipe@2 = gleam@string:join(_pipe@1, <<""/utf8>>), gleam@io:print_error(_pipe@2); json -> _pipe@3 = Vulns, _pipe@4 = gleam@list:map( _pipe@3, fun go_over@warning:format_as_json/1 ), _pipe@5 = gleam@json:preprocessed_array(_pipe@4), _pipe@6 = gleam@json:to_string(_pipe@5), gleam@io:print_error(_pipe@6); _ -> print_warnings_count(Vulns), _pipe@7 = Vulns, _pipe@8 = gleam@list:map( _pipe@7, fun go_over@warning:format_as_string/1 ), _pipe@9 = gleam@string:join( _pipe@8, <<"\n-----------------------------------------------\n"/utf8>> ), gleam@io:print_error(_pipe@9) end, shellout_ffi:os_exit(1). -file("/home/bwireman/src/go-over/src/go_over.gleam", 172). -spec main() -> nil. main() -> Conf = spin_up(go_over@config:read_config(<<"./gleam.toml"/utf8>>)), go_over@util@util:throwaway( not erlang:element(3, Conf), go_over@util@util:freeze1( fun simplifile_erl:delete/1, go_over@util@constants:go_over_path() ) ), Pkgs = begin _pipe = go_over@packages:read_manifest(<<"./manifest.toml"/utf8>>), _pipe@1 = go_over@config:filter_dev_dependencies(Conf, _pipe), _pipe@2 = go_over@config:filter_packages(Conf, _pipe@1), go_over@config:filter_indirect(Conf, _pipe@2) end, Vulnerable_packages = get_vulnerable_packages(Pkgs, Conf), Retired_packages = get_retired_packges(Pkgs, Conf), Outdated_packages = case erlang:element(4, Conf) of true -> get_outdated_packages(Pkgs, Conf); false -> [] end, go_over@util@util:iff_nil( erlang:element(7, Conf), go_over@util@util:freeze2( fun print_warnings/2, [{warning, none, <<"fake"/utf8>>, <<"x.y.z"/utf8>>, <<"Retired"/utf8>>, vulnerable, <<"Critical"/utf8>>, direct}, {warning, none, <<"another_fake"/utf8>>, <<"1.2.3"/utf8>>, <<"Vulnerable"/utf8>>, vulnerable, <<"High"/utf8>>, direct}, {warning, none, <<"and_another"/utf8>>, <<"4.5.6"/utf8>>, <<"Vulnerable"/utf8>>, vulnerable, <<"Moderate"/utf8>>, direct}, {warning, none, <<"one_more"/utf8>>, <<"7.8.9"/utf8>>, <<"Vulnerable"/utf8>>, vulnerable, <<"LOW"/utf8>>, indirect}, {warning, none, <<"this_one_was_retired"/utf8>>, <<"10.11.12"/utf8>>, <<"Retired"/utf8>>, retired, <<"Package Retired"/utf8>>, indirect}], Conf ) ), Warnings = begin _pipe@3 = lists:append(Retired_packages, Vulnerable_packages), _pipe@4 = lists:append(_pipe@3, Outdated_packages), go_over@config:filter_severity(Conf, _pipe@4) end, case Warnings of [] -> go_over@util@print:success(<<"✅ All good! ✨"/utf8>>); Vulns -> print_warnings(Vulns, Conf) end.