-module(glm_encrypted_file). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/glm_encrypted_file.gleam"). -export([main/0]). -export_type([args/0]). -type args() :: {encrypt_args, binary(), binary(), binary(), binary(), boolean()} | {decrypt_args, binary(), binary(), binary(), binary(), boolean()}. -file("src/glm_encrypted_file.gleam", 31). -spec plaintext_file_path_opt() -> clip@opt:opt(binary()). plaintext_file_path_opt() -> _pipe = clip@opt:new(<<"plaintext"/utf8>>), clip@opt:help(_pipe, <<"path to the plaintext input file"/utf8>>). -file("src/glm_encrypted_file.gleam", 36). -spec decrypted_file_path_opt() -> clip@opt:opt(binary()). decrypted_file_path_opt() -> _pipe = clip@opt:new(<<"decrypted"/utf8>>), clip@opt:help(_pipe, <<"path to the decrypted file"/utf8>>). -file("src/glm_encrypted_file.gleam", 41). -spec encrypted_file_path_opt() -> clip@opt:opt(binary()). encrypted_file_path_opt() -> _pipe = clip@opt:new(<<"encrypted"/utf8>>), clip@opt:help(_pipe, <<"path to the encrypted file"/utf8>>). -file("src/glm_encrypted_file.gleam", 46). -spec password_file_path_opt() -> clip@opt:opt(binary()). password_file_path_opt() -> _pipe = clip@opt:new(<<"password"/utf8>>), clip@opt:help(_pipe, <<"path to the password file"/utf8>>). -file("src/glm_encrypted_file.gleam", 51). -spec dry_run_opt() -> clip@flag:flag(). dry_run_opt() -> _pipe = clip@flag:new(<<"dryrun"/utf8>>), clip@flag:help(_pipe, <<"dry run, don't actually do anything"/utf8>>). -file("src/glm_encrypted_file.gleam", 56). -spec log_level_opt() -> clip@opt:opt(binary()). log_level_opt() -> _pipe = clip@opt:new(<<"log_level"/utf8>>), _pipe@1 = clip@opt:default(_pipe, <<"info"/utf8>>), clip@opt:help( _pipe@1, <<"log output verbosity, debug|info|warn|error"/utf8>> ). -file("src/glm_encrypted_file.gleam", 62). -spec encrypt_command() -> clip:command(args()). encrypt_command() -> _pipe = clip:command( begin clip:parameter( fun(Plaintext_input_file_path) -> clip:parameter( fun(Encrypted_output_file_path) -> clip:parameter( fun(Password_file_path) -> clip:parameter( fun(Log_level) -> clip:parameter( fun(Dry_run) -> {encrypt_args, Plaintext_input_file_path, Encrypted_output_file_path, Password_file_path, Log_level, Dry_run} end ) end ) end ) end ) end ) end ), _pipe@1 = clip:opt(_pipe, plaintext_file_path_opt()), _pipe@2 = clip:opt(_pipe@1, encrypted_file_path_opt()), _pipe@3 = clip:opt(_pipe@2, password_file_path_opt()), _pipe@4 = clip:opt(_pipe@3, log_level_opt()), _pipe@5 = clip:flag(_pipe@4, dry_run_opt()), clip:help( _pipe@5, clip@help:simple( <<"subcommand generate"/utf8>>, <<"generate all the files"/utf8>> ) ). -file("src/glm_encrypted_file.gleam", 86). -spec decrypt_command() -> clip:command(args()). decrypt_command() -> _pipe = clip:command( begin clip:parameter( fun(Encrypted_input_file_path) -> clip:parameter( fun(Decrypted_output_file_path) -> clip:parameter( fun(Password_file_path) -> clip:parameter( fun(Log_level) -> clip:parameter( fun(Dry_run) -> {decrypt_args, Encrypted_input_file_path, Decrypted_output_file_path, Password_file_path, Log_level, Dry_run} end ) end ) end ) end ) end ) end ), _pipe@1 = clip:opt(_pipe, encrypted_file_path_opt()), _pipe@2 = clip:opt(_pipe@1, decrypted_file_path_opt()), _pipe@3 = clip:opt(_pipe@2, password_file_path_opt()), _pipe@4 = clip:opt(_pipe@3, log_level_opt()), _pipe@5 = clip:flag(_pipe@4, dry_run_opt()), clip:help( _pipe@5, clip@help:simple( <<"subcommand runscript"/utf8>>, <<"runscript with the artifact directory on target server"/utf8>> ) ). -file("src/glm_encrypted_file.gleam", 113). -spec command() -> clip:command(args()). command() -> _pipe = clip:subcommands( [{<<"encrypt"/utf8>>, encrypt_command()}, {<<"decrypt"/utf8>>, decrypt_command()}] ), clip:help( _pipe, clip@help:simple( <<"glm_encrypted_file"/utf8>>, <<"encrypt and decrypt files, using shell and openssl."/utf8>> ) ). -file("src/glm_encrypted_file.gleam", 124). -spec configure_logging(binary()) -> nil. configure_logging(Level) -> _ = logging_ffi:configure(), Level@1 = begin _pipe = Level, string:lowercase(_pipe) end, Logging_level = case Level@1 of <<"debug"/utf8>> -> debug; <<"info"/utf8>> -> info; <<"warn"/utf8>> -> warning; <<"error"/utf8>> -> error; _ -> debug end, _ = logging:set_level(Logging_level). -file("src/glm_encrypted_file.gleam", 137). -spec main() -> nil. main() -> case begin _pipe = command(), _pipe@1 = clip:help( _pipe, clip@help:simple( <<"subcommands"/utf8>>, <<"encrypt, decrypt"/utf8>> ) ), clip:run(_pipe@1, erlang:element(4, argv:load())) end of {error, E} -> _pipe@2 = E, _pipe@3 = gleam@string:inspect(_pipe@2), _pipe@4 = gleam@string:split(_pipe@3, <<"\\n"/utf8>>), gleam@list:map(_pipe@4, fun gleam_stdlib:println_error/1), nil; {ok, {encrypt_args, Plaintext_file_path, Encrypted_file_path, Password_file_path, Log_level, Dry_run}} -> configure_logging(Log_level), Plaintext_file = glm_encrypted_file@encfile:new_plaintext_file( Plaintext_file_path ), Encrypted_file = glm_encrypted_file@encfile:new_encrypted_file( Encrypted_file_path ), Password_file = glm_encrypted_file@encfile:new_password_file( Password_file_path ), logging:log( debug, <<<<<<<<<<"cli encrypt, plaintext_file_path:"/utf8, Plaintext_file_path/binary>>/binary, ", encrypted_file_path: "/utf8>>/binary, Encrypted_file_path/binary>>/binary, ", password_file_path: "/utf8>>/binary, Password_file_path/binary>> ), case Dry_run of true -> erlang:error(#{gleam_error => panic, message => <<"`panic` expression evaluated."/utf8>>, file => <>, module => <<"glm_encrypted_file"/utf8>>, function => <<"main"/utf8>>, line => 169}); false -> case glm_encrypted_file@encfile:encrypt( Plaintext_file, Encrypted_file, Password_file ) of {error, E@1} -> pprint:debug( <<<<<<<<<<"failed to encrypt file, plaintext file: "/utf8, Plaintext_file_path/binary>>/binary, ", encrypted file: "/utf8>>/binary, Encrypted_file_path/binary>>/binary, ", password file: "/utf8>>/binary, Password_file_path/binary>> ), pprint:debug(E@1), erlang:error(#{gleam_error => panic, message => <<"`panic` expression evaluated."/utf8>>, file => <>, module => <<"glm_encrypted_file"/utf8>>, function => <<"main"/utf8>>, line => 182}); {ok, _} -> gleam_stdlib:println( <<"successfully wrote encrypted file: "/utf8, Encrypted_file_path/binary>> ), nil end end; {ok, {decrypt_args, Encrypted_input_file_path, Decrypted_output_file_path, Password_file_path@1, Log_level@1, Dry_run@1}} -> configure_logging(Log_level@1), Encrypted_file@1 = glm_encrypted_file@encfile:new_encrypted_file( Encrypted_input_file_path ), Password_file@1 = glm_encrypted_file@encfile:new_password_file( Password_file_path@1 ), logging:log( debug, <<<<<<<<<<"cli decrypt, encrypted_input_file_path: "/utf8, Encrypted_input_file_path/binary>>/binary, ", password_file_path: "/utf8>>/binary, Password_file_path@1/binary>>/binary, ", decrypted_output_file_path: "/utf8>>/binary, Decrypted_output_file_path/binary>> ), case Dry_run@1 of true -> erlang:error(#{gleam_error => panic, message => <<"`panic` expression evaluated."/utf8>>, file => <>, module => <<"glm_encrypted_file"/utf8>>, function => <<"main"/utf8>>, line => 215}); false -> case glm_encrypted_file@encfile:decrypt( Encrypted_file@1, Password_file@1 ) of {error, E@2} -> pprint:debug( <<<<<<"failed to decrypt, encrypted file: "/utf8, Encrypted_input_file_path/binary>>/binary, ", password file: "/utf8>>/binary, Password_file_path@1/binary>> ), pprint:debug(E@2), erlang:error(#{gleam_error => panic, message => <<"`panic` expression evaluated."/utf8>>, file => <>, module => <<"glm_encrypted_file"/utf8>>, function => <<"main"/utf8>>, line => 226}); {ok, Data} -> case simplifile:write( Decrypted_output_file_path, Data ) of {error, E@3} -> pprint:debug( <<"failed to write decrypted file to: "/utf8, Decrypted_output_file_path/binary>> ), pprint:debug(E@3), erlang:error(#{gleam_error => panic, message => <<"`panic` expression evaluated."/utf8>>, file => <>, module => <<"glm_encrypted_file"/utf8>>, function => <<"main"/utf8>>, line => 236}); {ok, _} -> gleam_stdlib:println( <<"successfully wrote decrypted file to: "/utf8, Decrypted_output_file_path/binary>> ), nil end end end end.