diff --git a/Gemfile.lock b/Gemfile.lock index 572ec38..882f8ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,7 @@ PATH remote: . specs: console1984 (0.1.31) + irb (~> 1.13) parser rails (>= 7.0) rainbow @@ -98,6 +99,10 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.22.0) @@ -135,6 +140,8 @@ GEM ast (~> 2.4.1) racc pg (1.5.3) + psych (5.1.2) + stringio racc (1.7.1) rack (2.2.7) rack-test (2.1.0) @@ -169,7 +176,11 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.1.0) + rdoc (6.6.3.1) + psych (>= 4.0.0) regexp_parser (2.8.1) + reline (0.5.7) + io-console (~> 0.5) rexml (3.2.5) rubocop (1.54.1) json (~> 2.3) @@ -200,6 +211,7 @@ GEM rubyzip (2.3.2) sqlite3 (1.6.3) mini_portile2 (~> 2.8.0) + stringio (3.1.0) thor (1.3.1) timeout (0.4.1) tzinfo (2.0.6) diff --git a/console1984.gemspec b/console1984.gemspec index b1c6cd6..d35ce19 100644 --- a/console1984.gemspec +++ b/console1984.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'rainbow' spec.add_dependency 'parser' spec.add_dependency 'rails', '>= 7.0' + spec.add_dependency 'irb', '~> 1.13' spec.add_development_dependency 'benchmark-ips' spec.add_development_dependency 'mocha' diff --git a/lib/console1984/command_validator/.command_parser.rb b/lib/console1984/command_validator/.command_parser.rb index 1088e15..af572d7 100644 --- a/lib/console1984/command_validator/.command_parser.rb +++ b/lib/console1984/command_validator/.command_parser.rb @@ -1,4 +1,4 @@ -# Naming class with dot so that it doesn't get loaded eagerly by Zeitwork. We want to load +# Naming class with dot so that it doesn't get loaded eagerly by Zeitwerk. We want to load # only when a console session is started, when +parser+ is loaded. # # See +Console1984::Supervisor#require_dependencies+ diff --git a/lib/console1984/commands/decrypt.rb b/lib/console1984/commands/decrypt.rb new file mode 100644 index 0000000..f31b8a4 --- /dev/null +++ b/lib/console1984/commands/decrypt.rb @@ -0,0 +1,12 @@ +module Console1984::Commands + class Decrypt < IRB::Command::Base + include Console1984::Ext::Irb::Commands + + category "Console1984" + description "go back to protected mode, without access to encrypted information" + + def execute(*) + decrypt! + end + end +end diff --git a/lib/console1984/commands/encrypt.rb b/lib/console1984/commands/encrypt.rb new file mode 100644 index 0000000..b2899aa --- /dev/null +++ b/lib/console1984/commands/encrypt.rb @@ -0,0 +1,12 @@ +module Console1984::Commands + class Encrypt < IRB::Command::Base + include Console1984::Ext::Irb::Commands + + category "Console1984" + description "go back to protected mode, without access to encrypted information" + + def execute(*) + encrypt! + end + end +end diff --git a/lib/console1984/ext/irb/commands.rb b/lib/console1984/ext/irb/commands.rb index a2dd588..a852989 100644 --- a/lib/console1984/ext/irb/commands.rb +++ b/lib/console1984/ext/irb/commands.rb @@ -13,13 +13,4 @@ def decrypt! def encrypt! shield.enable_protected_mode end - - # This returns the last error that prevented a command execution in the console - # or nil if there isn't any. - # - # This is meant for internal usage when debugging legit commands that are wrongly - # prevented. - def _console_last_suspicious_command_error - Console1984.command_executor.last_suspicious_command_error - end end diff --git a/lib/console1984/shield.rb b/lib/console1984/shield.rb index 8a58c3d..b5663ed 100644 --- a/lib/console1984/shield.rb +++ b/lib/console1984/shield.rb @@ -34,7 +34,8 @@ def extend_protected_systems def extend_irb IRB::Context.prepend(Console1984::Ext::Irb::Context) - Rails::ConsoleMethods.include(Console1984::Ext::Irb::Commands) + IRB::Command.register :decrypt!, Console1984::Commands::Decrypt + IRB::Command.register :encrypt!, Console1984::Commands::Encrypt end def extend_core_ruby diff --git a/lib/console1984/supervisor.rb b/lib/console1984/supervisor.rb index f4c0086..f789d9b 100644 --- a/lib/console1984/supervisor.rb +++ b/lib/console1984/supervisor.rb @@ -1,11 +1,5 @@ require "active_support/all" -if Rails.version >= "8" - require "rails/console/methods" -else - require "rails/console/app" -end - # Entry point to the system. In charge of installing everything # and starting and stopping sessions. class Console1984::Supervisor