lib/bolt/plugin/module.rb in bolt-1.49.0 vs lib/bolt/plugin/module.rb in bolt-2.0.0

- old
+ new

@@ -4,11 +4,11 @@ module Bolt class Plugin class Module class InvalidPluginData < Bolt::Plugin::PluginError - def initialize(plugin, msg) + def initialize(msg, plugin) msg = "Invalid Plugin Data for #{plugin}: #{msg}" super(msg, 'bolt/invalid-plugin-data') end end @@ -34,22 +34,22 @@ # This method interacts with the module on disk so it's separate from initialize def setup @data = load_data @hook_map = find_hooks(@data['hooks'] || {}) - # If there is a config section in bolt_plugin.json, validate against that and send - # validated values nested under `_config` key. Otherwise validate againsts the intersection - # of all task schemas. - # TODO: remove @send_config when deprecated - schema = if @data['config'] - @send_config = true - @data['config'] - else - extract_task_parameter_schema - end - @config_schema = process_schema(schema) + if @data['config'] + msg = <<~MSG.chomp + Found unsupported key 'config' in bolt_plugin.json. Config for a plugin is inferred + from task parameters, with config values passed as parameters. + MSG + raise InvalidPluginData.new(msg, name) + end + + # Validate againsts the intersection of all task schemas. + @config_schema = process_schema(extract_task_parameter_schema) + validate_config(@config, @config_schema) end def name @module.name @@ -57,14 +57,10 @@ def hooks (@hook_map.keys + [:validate_resolve_reference]).uniq end - def config? - @data.include?('config') && !@data['config'].empty? - end - def load_data JSON.parse(File.read(@module.plugin_data_file)) rescue JSON::ParserError => e raise InvalidPluginData.new(e.message, name) end @@ -157,22 +153,14 @@ def process_params(task, opts) # opts are passed directly from inventory but all of the _ options are # handled previously. That may not always be the case so filter them # out now. meta, params = opts.partition { |key, _val| key.start_with?('_') }.map(&:to_h) + params = config.merge(params) + validate_params(task, params) - # Send config with `_config` when config is defined in bolt_plugin.json - # Otherwise, merge config with params - # TODO: remove @send_config when deprecated - if @send_config - validate_params(task, params) - params['_config'] = config if config? - else - params = @config ? config.merge(params) : params - validate_params(task, params) - end - params['_boltdir'] = @context.boltdir.to_s + meta['_boltdir'] = @context.boltdir.to_s [params, meta] end def extract_task_parameter_schema @@ -230,18 +218,13 @@ result['value'] end end def validate_resolve_reference(opts) - # Send config with `_config` when config is defined in bolt_plugin.json - # Otherwise, merge config with params - # TODO: remove @send_config when deprecated - if @send_config - params = opts.reject { |k, _v| k.start_with?('_') } - else - merged = @config.merge(opts) - params = merged.reject { |k, _v| k.start_with?('_') } - end + # Merge config with params + merged = @config.merge(opts) + params = merged.reject { |k, _v| k.start_with?('_') } + sig = @hook_map[:resolve_reference]['task'] if sig validate_params(sig, params) end