Class: Bolt::Plugin::PluginContext

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, pal) ⇒ PluginContext

Returns a new instance of PluginContext.



42
43
44
45
# File 'lib/bolt/plugin.rb', line 42

def initialize(config, pal)
  @pal = pal
  @config = config
end

Instance Method Details

#boltdirObject



116
117
118
# File 'lib/bolt/plugin.rb', line 116

def boltdir
  @config.boltdir.path
end

#get_validated_task(task_name, params = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/bolt/plugin.rb', line 78

def get_validated_task(task_name, params = nil)
  with_a_compiler do |compiler|
    tasksig = compiler.task_signature(task_name)

    raise Bolt::Error.unknown_task(task_name) unless tasksig

    Bolt::Task::Run.validate_params(tasksig, params) if params
    Bolt::Task.new(tasksig.task_hash)
  end
end

#run_local_task(task, params, options) ⇒ Object

By passing ‘_` keys in params the caller can send metaparams directly to the task _catch_errors must be passed as an executor option not a param



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bolt/plugin.rb', line 102

def run_local_task(task, params, options)
  # Make sure we're in a compiler to use the sensitive type
  with_a_compiler do |_comp|
    params = Bolt::Task::Run.wrap_sensitive(task, params)
    Bolt::Task::Run.run_task(
      task,
      empty_inventory.get_targets('localhost'),
      params,
      options,
      serial_executor
    )
  end
end

#validate_params(task_name, params) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/bolt/plugin.rb', line 89

def validate_params(task_name, params)
  with_a_compiler do |compiler|
    tasksig = compiler.task_signature(task_name)

    raise Bolt::Error.new("#{task_name} could not be found", 'bolt/plugin-error') unless tasksig

    Bolt::Task::Run.validate_params(tasksig, params)
  end
  nil
end