Class: Bolt::Plugin::PluginContext

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

Instance Method Summary collapse

Constructor Details

#initialize(config, pal, plugins) ⇒ PluginContext

Returns a new instance of PluginContext.


50
51
52
53
54
# File 'lib/bolt/plugin.rb', line 50

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

Instance Method Details

#boltdirObject


125
126
127
# File 'lib/bolt/plugin.rb', line 125

def boltdir
  @config.project.path
end

#get_validated_task(task_name, params = nil) ⇒ Object


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

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.from_task_signature(tasksig)
  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


111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/bolt/plugin.rb', line 111

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


98
99
100
101
102
103
104
105
106
107
# File 'lib/bolt/plugin.rb', line 98

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