Class: MCollective::Agent::Bolt_tasks

Inherits:
RPC::Agent
  • Object
show all
Defined in:
lib/mcollective/agent/bolt_tasks.rb

Instance Attribute Summary

Attributes inherited from RPC::Agent

#agent_name, #config, #ddl, #logger, #meta, #reply, #request, #timeout

Instance Method Summary collapse

Methods inherited from RPC::Agent

action, actions, activate?, activate_when, #after_processing_hook, #audit_request, authorized_by, #handlemsg, #implemented_by, #initialize, #load_ddl, metadata, #run, #shellescape, #startup_hook, #validate

Constructor Details

This class inherits a constructor from MCollective::RPC::Agent

Instance Method Details

#before_processing_hook(msg, connection) ⇒ Object

Performs an additional authorization and audit using the task name as action



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/mcollective/agent/bolt_tasks.rb', line 139

def before_processing_hook(msg, connection)
  original_action = request.action
  task = request[:task]

  begin
    if ["run_and_wait", "run_no_wait"].include?(original_action) && task
      request.action = task

      begin
        authorization_hook(request) if respond_to?("authorization_hook")
      rescue
        raise(RPCAborted, "You are not authorized to run Bolt Task %s" % task)
      end

      audit_request(request, connection)
    end
  ensure
    request.action = original_action
  end
end

#caller_only_status?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/mcollective/agent/bolt_tasks.rb', line 120

def caller_only_status?
  Util.str_to_bool(@config.pluginconf.fetch("choria.tasks.own_status_only", "true"))
end

#make_error(msg, kind, detail) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/mcollective/agent/bolt_tasks.rb', line 124

def make_error(msg, kind, detail)
  {
    "_error" => {
      "msg" => msg,
      "kind" => kind,
      "details" => detail
    }
  }
end

#reply_task_status(status) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/mcollective/agent/bolt_tasks.rb', line 160

def reply_task_status(status)
  reply[:exitcode] = status["exitcode"]
  reply[:stdout] = status["stdout"].to_json
  reply[:stderr] = status["stderr"]
  reply[:completed] = status["completed"]
  reply[:runtime] = status["runtime"]
  reply[:start_time] = status["start_time"].to_i
  reply[:task] = status["task"]
  reply[:callerid] = status["caller"]

  if status["stdout"]["_error"]
    reply.fail("%s: %s" % [status["stdout"]["_error"]["kind"], status["stdout"]["_error"]["msg"]])
  elsif support_factory.task_failed?(status)
    reply.fail("Task failed without any error details", 1)
  end
end

#support_factoryObject



134
135
136
# File 'lib/mcollective/agent/bolt_tasks.rb', line 134

def support_factory
  Util::Choria.new.tasks_support
end