Class: Sqreen::RemoteCommand
- Inherits:
-
Object
- Object
- Sqreen::RemoteCommand
- Defined in:
- lib/sqreen/remote_command.rb,
lib/sqreen/remote_command/failure_output.rb
Overview
Execute and sanitize remote commands
Defined Under Namespace
Classes: FailureOutput
Constant Summary collapse
- KNOWN_COMMANDS =
{ :instrumentation_enable => :setup_instrumentation, :instrumentation_remove => :remove_instrumentation, :rules_reload => :reload_rules, :actions_reload => :reload_actions, :features_get => :features, :features_change => :change_features, :force_logout => :shutdown, :force_restart => :restart, :paths_whitelist => :change_whitelisted_paths, :ips_whitelist => :change_whitelisted_ips, :get_bundle => :upload_bundle, :performance_budget => :change_performance_budget, :tracing_enable => :tracing_enable, }.freeze
Instance Attribute Summary collapse
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
-
.coalesce_reloads(commands, res_list) ⇒ Object
will need changes if we ever distinguish forced/soft reloads (‘force’ parameter in the command).
- .process_list(runner, commands, context_infos = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(json_desc) ⇒ RemoteCommand
constructor
A new instance of RemoteCommand.
- #process(runner, context_infos = {}) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(json_desc) ⇒ RemoteCommand
Returns a new instance of RemoteCommand.
31 32 33 34 35 |
# File 'lib/sqreen/remote_command.rb', line 31 def initialize(json_desc) @name = json_desc['name'].to_sym @params = json_desc.fetch('params', []) @uuid = json_desc['uuid'] end |
Instance Attribute Details
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
29 30 31 |
# File 'lib/sqreen/remote_command.rb', line 29 def uuid @uuid end |
Class Method Details
.coalesce_reloads(commands, res_list) ⇒ Object
will need changes if we ever distinguish forced/soft reloads (‘force’ parameter in the command)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sqreen/remote_command.rb', line 75 def self.coalesce_reloads(commands, res_list) new_commands = [] saw_rules_reload = false commands.reverse_each do |cmd_json| name = cmd_json['name'] unless name == 'rules_reload' new_commands.unshift cmd_json next end if saw_rules_reload res_list[cmd_json['uuid']] = { :status => false, :reason => "redundant rules_reload ignored" } else saw_rules_reload = true new_commands.unshift cmd_json next end end new_commands end |
.process_list(runner, commands, context_infos = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sqreen/remote_command.rb', line 52 def self.process_list(runner, commands, context_infos = {}) res_list = {} return res_list unless commands unless commands.is_a? Array Sqreen.log.debug { format('Wrong commands type %s', commands.class) } Sqreen.log.debug { commands.inspect } return res_list end commands = coalesce_reloads(commands, res_list) commands.each do |cmd_json| Sqreen.log.debug { cmd_json } cmd = RemoteCommand.new(cmd_json) Sqreen.log.debug { cmd.inspect } uuid = cmd.uuid res_list[uuid] = cmd.process(runner, context_infos) end res_list end |
Instance Method Details
#process(runner, context_infos = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sqreen/remote_command.rb', line 37 def process(runner, context_infos = {}) failing = validate_command(runner) return failing if failing Sqreen.log.debug { format('processing command %s', @name) } begin output = runner.send(KNOWN_COMMANDS[@name], *@params, context_infos) rescue => e Sqreen.log.warn { "Command failed with #{e}" } Sqreen.log.debug { e.backtrace.map { |x| " #{x}" }.join("\n") } Sqreen::RemoteException.record(e) return { :status => false, :reason => "error: #{e.inspect}" } end format_output(output) end |
#to_h ⇒ Object
98 99 100 101 102 |
# File 'lib/sqreen/remote_command.rb', line 98 def to_h { :name => @name, } end |