bolt 2.18.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +3 -1
  3. data/bolt-modules/boltlib/lib/puppet/functions/download_file.rb +123 -0
  4. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +6 -0
  5. data/bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb +12 -6
  6. data/bolt-modules/dir/lib/puppet/functions/dir/children.rb +35 -0
  7. data/bolt-modules/out/lib/puppet/functions/out/message.rb +1 -1
  8. data/lib/bolt/analytics.rb +1 -1
  9. data/lib/bolt/bolt_option_parser.rb +74 -24
  10. data/lib/bolt/catalog.rb +12 -3
  11. data/lib/bolt/cli.rb +305 -108
  12. data/lib/bolt/config.rb +18 -10
  13. data/lib/bolt/config/options.rb +14 -0
  14. data/lib/bolt/executor.rb +26 -5
  15. data/lib/bolt/inventory/group.rb +3 -2
  16. data/lib/bolt/inventory/inventory.rb +4 -3
  17. data/lib/bolt/logger.rb +9 -0
  18. data/lib/bolt/module.rb +2 -1
  19. data/lib/bolt/outputter.rb +56 -0
  20. data/lib/bolt/outputter/human.rb +0 -9
  21. data/lib/bolt/outputter/json.rb +0 -4
  22. data/lib/bolt/outputter/rainbow.rb +9 -2
  23. data/lib/bolt/pal.rb +11 -9
  24. data/lib/bolt/pal/yaml_plan/evaluator.rb +23 -2
  25. data/lib/bolt/pal/yaml_plan/step.rb +24 -2
  26. data/lib/bolt/pal/yaml_plan/step/download.rb +38 -0
  27. data/lib/bolt/pal/yaml_plan/step/message.rb +30 -0
  28. data/lib/bolt/pal/yaml_plan/step/upload.rb +3 -3
  29. data/lib/bolt/plugin/module.rb +2 -4
  30. data/lib/bolt/plugin/prompt.rb +3 -3
  31. data/lib/bolt/plugin/puppetdb.rb +3 -2
  32. data/lib/bolt/project.rb +14 -9
  33. data/lib/bolt/puppetdb/client.rb +2 -0
  34. data/lib/bolt/puppetdb/config.rb +16 -0
  35. data/lib/bolt/result.rb +7 -0
  36. data/lib/bolt/shell/bash.rb +24 -4
  37. data/lib/bolt/shell/powershell.rb +10 -4
  38. data/lib/bolt/transport/base.rb +24 -0
  39. data/lib/bolt/transport/docker.rb +8 -0
  40. data/lib/bolt/transport/docker/connection.rb +20 -2
  41. data/lib/bolt/transport/local/connection.rb +14 -1
  42. data/lib/bolt/transport/orch.rb +12 -0
  43. data/lib/bolt/transport/simple.rb +6 -0
  44. data/lib/bolt/transport/ssh/connection.rb +9 -1
  45. data/lib/bolt/transport/ssh/exec_connection.rb +22 -1
  46. data/lib/bolt/transport/winrm/connection.rb +118 -8
  47. data/lib/bolt/util.rb +26 -11
  48. data/lib/bolt/version.rb +1 -1
  49. data/lib/bolt_server/pe/pal.rb +1 -1
  50. data/lib/bolt_server/transport_app.rb +3 -2
  51. data/lib/bolt_spec/bolt_context.rb +7 -2
  52. data/lib/bolt_spec/plans.rb +15 -2
  53. data/lib/bolt_spec/plans/action_stubs.rb +3 -2
  54. data/lib/bolt_spec/plans/action_stubs/download_stub.rb +66 -0
  55. data/lib/bolt_spec/plans/mock_executor.rb +14 -1
  56. data/lib/bolt_spec/run.rb +22 -0
  57. data/libexec/apply_catalog.rb +2 -2
  58. data/libexec/bolt_catalog +4 -3
  59. data/libexec/custom_facts.rb +1 -1
  60. data/libexec/query_resources.rb +1 -1
  61. data/modules/secure_env_vars/plans/init.pp +20 -0
  62. metadata +8 -2
@@ -58,7 +58,7 @@ module BoltServer
58
58
  # Bolt::PAL::MODULES_PATH which would be more complex if we tried to use @modulepath since
59
59
  # we need to append our modulepaths and exclude modules shiped in bolt gem code
60
60
  modulepath_dirs = environment.modulepath
61
- @original_modulepath = modulepath_dirs
61
+ @user_modulepath = modulepath_dirs
62
62
  @modulepath = [PE_BOLTLIB_PATH, Bolt::PAL::BOLTLIB_PATH, *modulepath_dirs]
63
63
  end
64
64
  end
@@ -151,13 +151,14 @@ module BoltServer
151
151
  sha256 = file['sha256']
152
152
  kind = file['kind']
153
153
  path = File.join(cache_dir, relative_path)
154
- if kind == 'file'
154
+ case kind
155
+ when 'file'
155
156
  # The parent should already be created by `directory` entries,
156
157
  # but this is to be on the safe side.
157
158
  parent = File.dirname(path)
158
159
  FileUtils.mkdir_p(parent)
159
160
  @file_cache.serial_execute { @file_cache.download_file(path, sha256, uri) }
160
- elsif kind == 'directory'
161
+ when 'directory'
161
162
  # Create directory in cache so we can move files in.
162
163
  FileUtils.mkdir_p(path)
163
164
  else
@@ -41,6 +41,7 @@ require 'bolt/plugin'
41
41
  # - allow_command(cmd), expect_command(cmd): expect the exact command
42
42
  # - allow_script(script), expect_script(script): expect the script as <module>/path/to/file
43
43
  # - allow_task(task), expect_task(task): expect the named task
44
+ # - allow_download(file), expect_download(file): expect the identified source file
44
45
  # - allow_upload(file), expect_upload(file): expect the identified source file
45
46
  # - allow_out_message, expect_out_message: expect a message to be passed to out::message (only modifiers are
46
47
  # be_called_times(n), with_params(params), and not_be_called)
@@ -52,19 +53,22 @@ require 'bolt/plugin'
52
53
  # - with_targets(targets): target or list of targets that you expect to be passed to the action
53
54
  # - with_params(params): list of params and metaparams (or options) that you expect to be passed to the action.
54
55
  # Corresponds to the action's last argument.
55
- # - with_destination(dest): for upload_file, the expected destination path
56
+ # - with_destination(dest): for upload_file and download_file, the expected destination path
56
57
  # - always_return(value): return a Bolt::ResultSet of Bolt::Result objects with the specified value Hash
57
58
  # command and script: only accept 'stdout' and 'stderr' keys
58
59
  # upload: does not support this modifier
60
+ # download: does not support this modifier
59
61
  # - return_for_targets(targets_to_values): return a Bolt::ResultSet of Bolt::Result objects from the Hash mapping
60
62
  # targets to their value Hashes
61
63
  # command and script: only accept 'stdout' and 'stderr' keys
62
64
  # upload: does not support this modifier
65
+ # download: does not support this modifier
63
66
  # - return(&block): invoke the block to construct a Bolt::ResultSet. The blocks parameters differ based on action
64
67
  # command: `{ |targets:, command:, params:| ... }`
65
68
  # script: `{ |targets:, script:, params:| ... }`
66
69
  # task: `{ |targets:, task:, params:| ... }`
67
70
  # upload: `{ |targets:, source:, destination:, params:| ... }`
71
+ # download: `{ |targets:, source:, destination:, params:| ... }`
68
72
  # - error_with(err): return a failing Bolt::ResultSet, with Bolt::Result objects with the identified err hash
69
73
  #
70
74
  # Example:
@@ -190,8 +194,9 @@ module BoltSpec
190
194
  # so it probably should be set separately
191
195
  # def allow_script(script_name)
192
196
  #
193
- # file uploads have a single destination and no arguments
197
+ # file uploads and downloads have a single destination and no arguments
194
198
  # def allow_file_upload(source_name)
199
+ # def allow_file_download(source_name)
195
200
  #
196
201
  # Most of the information in commands is in the command string itself
197
202
  # we may need more flexible allows than just the name/command string
@@ -80,6 +80,7 @@ require 'bolt/pal'
80
80
  # - allow_plan(plan), expect_plan(plan): expect the named plan
81
81
  # - allow_script(script), expect_script(script): expect the script as <module>/path/to/file
82
82
  # - allow_task(task), expect_task(task): expect the named task
83
+ # - allow_download(file), expect_download(file): expect the identified source file
83
84
  # - allow_upload(file), expect_upload(file): expect the identified source file
84
85
  # - allow_apply_prep: allows `apply_prep` to be invoked in the plan but does not allow modifiers
85
86
  # - allow_apply: allows `apply` to be invoked in the plan but does not allow modifiers
@@ -94,15 +95,17 @@ require 'bolt/pal'
94
95
  # plan: does not support this modifier
95
96
  # - with_params(params): list of params and metaparams (or options) that you expect to be passed to the action.
96
97
  # Corresponds to the action's last argument.
97
- # - with_destination(dest): for upload_file, the expected destination path
98
+ # - with_destination(dest): for upload_file and download_file, the expected destination path
98
99
  # - always_return(value): return a Bolt::ResultSet of Bolt::Result objects with the specified value Hash
99
100
  # plan: returns a Bolt::PlanResult with the specified value with a status of 'success'
100
101
  # command and script: only accept 'stdout' and 'stderr' keys
101
102
  # upload: does not support this modifier
103
+ # download: does not support this modifier
102
104
  # - return_for_targets(targets_to_values): return a Bolt::ResultSet of Bolt::Result objects from the Hash mapping
103
105
  # targets to their value Hashes
104
106
  # command and script: only accept 'stdout' and 'stderr' keys
105
107
  # upload: does not support this modifier
108
+ # download: does not support this modifier
106
109
  # plan: does not support this modifier
107
110
  # - return(&block): invoke the block to construct a Bolt::ResultSet. The blocks parameters differ based on action
108
111
  # command: `{ |targets:, command:, params:| ... }`
@@ -110,6 +113,7 @@ require 'bolt/pal'
110
113
  # script: `{ |targets:, script:, params:| ... }`
111
114
  # task: `{ |targets:, task:, params:| ... }`
112
115
  # upload: `{ |targets:, source:, destination:, params:| ... }`
116
+ # download: `{ |targets:, source:, destination:, params:| ... }`
113
117
  # - error_with(err): return a failing Bolt::ResultSet, with Bolt::Result objects with the identified err hash
114
118
  # plans will throw a Bolt::PlanFailure that will be returned as the value of
115
119
  # the Bolt::PlanResult object with a status of 'failure'.
@@ -219,7 +223,16 @@ module BoltSpec
219
223
  end
220
224
 
221
225
  def run_plan(name, params)
222
- pal = Bolt::PAL.new(config.modulepath, config.hiera_config, config.project.resource_types)
226
+ pal = Bolt::PAL.new(
227
+ config.modulepath,
228
+ config.hiera_config,
229
+ config.project.resource_types,
230
+ config.compile_concurrency,
231
+ config.trusted_external,
232
+ config.apply_settings,
233
+ config.project
234
+ )
235
+
223
236
  result = executor.with_plan_allowed_exec(name, params) do
224
237
  pal.run_plan(name, params, executor, inventory, puppetdb_client)
225
238
  end
@@ -118,7 +118,7 @@ module BoltSpec
118
118
  # Restricts the stub to only match invocations with
119
119
  # the correct targets
120
120
  def with_targets(targets)
121
- targets = [targets] unless targets.is_a? Array
121
+ targets = Array(targets)
122
122
  @invocation[:targets] = targets.map do |target|
123
123
  if target.is_a? String
124
124
  target
@@ -177,7 +177,7 @@ module BoltSpec
177
177
  if data['msg'] && data['kind'] && (data.keys - %w[msg kind details issue_code]).empty?
178
178
  @data[:default] = clazz.new(data['msg'], data['kind'], data['details'], data['issue_code'])
179
179
  else
180
- STDERR.puts "In the future 'error_with()' may require msg and kind, and " \
180
+ $stderr.puts "In the future 'error_with()' may require msg and kind, and " \
181
181
  "optionally accept only details and issue_code."
182
182
  @data[:default] = data
183
183
  end
@@ -193,3 +193,4 @@ require_relative 'action_stubs/plan_stub'
193
193
  require_relative 'action_stubs/script_stub'
194
194
  require_relative 'action_stubs/task_stub'
195
195
  require_relative 'action_stubs/upload_stub'
196
+ require_relative 'action_stubs/download_stub'
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoltSpec
4
+ module Plans
5
+ class DownloadStub < ActionStub
6
+ def matches(targets, _source, destination, options)
7
+ if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets.map(&:name))
8
+ return false
9
+ end
10
+
11
+ if @invocation[:destination] && destination != @invocation[:destination]
12
+ return false
13
+ end
14
+
15
+ if @invocation[:options] && options != @invocation[:options]
16
+ return false
17
+ end
18
+
19
+ true
20
+ end
21
+
22
+ def call(targets, source, destination, options)
23
+ @calls += 1
24
+ if @return_block
25
+ results = @return_block.call(targets: targets, source: source, destination: destination, params: options)
26
+ check_resultset(results, source)
27
+ else
28
+ results = targets.map do |target|
29
+ if @data[:default].is_a?(Bolt::Error)
30
+ default_for(target)
31
+ else
32
+ download = File.join(destination, Bolt::Util.windows_basename(source))
33
+ Bolt::Result.for_download(target, source, destination, download)
34
+ end
35
+ end
36
+ Bolt::ResultSet.new(results)
37
+ end
38
+ end
39
+
40
+ def parameters
41
+ @invocation[:options]
42
+ end
43
+
44
+ def result_for(_target, _data)
45
+ raise 'Download result cannot be changed'
46
+ end
47
+
48
+ # Public methods
49
+
50
+ def always_return(_data)
51
+ raise 'Download result cannot be changed'
52
+ end
53
+
54
+ def with_destination(destination)
55
+ @invocation[:destination] = destination
56
+ self
57
+ end
58
+
59
+ def with_params(params)
60
+ @invocation[:options] = params.select { |k, _v| k.start_with?('_') }
61
+ .transform_keys { |k| k.sub(/^_/, '').to_sym }
62
+ self
63
+ end
64
+ end
65
+ end
66
+ end
@@ -11,7 +11,7 @@ require 'set'
11
11
 
12
12
  module BoltSpec
13
13
  module Plans
14
- MOCKED_ACTIONS = %i[command plan script task upload].freeze
14
+ MOCKED_ACTIONS = %i[command download plan script task upload].freeze
15
15
 
16
16
  class UnexpectedInvocation < ArgumentError; end
17
17
 
@@ -90,6 +90,19 @@ module BoltSpec
90
90
  result
91
91
  end
92
92
 
93
+ def download_file(targets, source, destination, options = {})
94
+ result = nil
95
+ if (doub = @download_doubles[source] || @download_doubles[:default])
96
+ result = doub.process(targets, source, destination, options)
97
+ end
98
+ unless result
99
+ targets = targets.map(&:name)
100
+ @error_message = "Unexpected call to 'download_file(#{source}, #{destination}, #{targets}, #{options})'"
101
+ raise UnexpectedInvocation, @error_message
102
+ end
103
+ result
104
+ end
105
+
93
106
  def upload_file(targets, source_path, destination, options = {})
94
107
  source = module_file_id(source_path)
95
108
  result = nil
@@ -80,6 +80,22 @@ module BoltSpec
80
80
  Bolt::Util.walk_keys(result, &:to_s)
81
81
  end
82
82
 
83
+ def download_file(source, dest, targets, options: {}, config: nil, inventory: nil)
84
+ if config.nil? && defined?(bolt_config)
85
+ config = bolt_config
86
+ end
87
+
88
+ if inventory.nil? && defined?(bolt_inventory)
89
+ inventory = bolt_inventory
90
+ end
91
+
92
+ result = BoltRunner.with_runner(config, inventory) do |runner|
93
+ runner.download_file(source, dest, targets, options)
94
+ end
95
+ result = result.to_a
96
+ Bolt::Util.walk_keys(result, &:to_s)
97
+ end
98
+
83
99
  def upload_file(source, dest, targets, options: {}, config: nil, inventory: nil)
84
100
  if config.nil? && defined?(bolt_config)
85
101
  config = bolt_config
@@ -194,6 +210,12 @@ module BoltSpec
194
210
  executor.run_script(targets, script, arguments, options)
195
211
  end
196
212
 
213
+ def download_file(source, dest, targets, options = {})
214
+ executor = Bolt::Executor.new(config.concurrency, @analytics)
215
+ targets = inventory.get_targets(targets)
216
+ executor.download_file(targets, source, dest, options)
217
+ end
218
+
197
219
  def upload_file(source, dest, targets, options = {})
198
220
  executor = Bolt::Executor.new(config.concurrency, @analytics)
199
221
  targets = inventory.get_targets(targets)
@@ -9,7 +9,7 @@ require 'puppet/module_tool/tar'
9
9
  require 'securerandom'
10
10
  require 'tempfile'
11
11
 
12
- args = JSON.parse(ARGV[0] ? File.read(ARGV[0]) : STDIN.read)
12
+ args = JSON.parse(ARGV[0] ? File.read(ARGV[0]) : $stdin.read)
13
13
 
14
14
  # Create temporary directories for all core Puppet settings so we don't clobber
15
15
  # existing state or read from puppet.conf. Also create a temporary modulepath.
@@ -110,7 +110,7 @@ ensure
110
110
  begin
111
111
  FileUtils.remove_dir(puppet_root)
112
112
  rescue Errno::ENOTEMPTY => e
113
- STDERR.puts("Could not cleanup temporary directory: #{e}")
113
+ $stderr.puts("Could not cleanup temporary directory: #{e}")
114
114
  end
115
115
  end
116
116
 
@@ -32,14 +32,15 @@ require 'json'
32
32
  # }
33
33
 
34
34
  command = ARGV[0]
35
- if command == "parse"
35
+ case command
36
+ when "parse"
36
37
  code = File.open(ARGV[1], &:read)
37
38
  puts JSON.pretty_generate(Bolt::Catalog.new.generate_ast(code, ARGV[1]))
38
- elsif command == "compile"
39
+ when "compile"
39
40
  request = if ARGV[1]
40
41
  File.open(ARGV[1]) { |fh| JSON.parse(fh.read) }
41
42
  else
42
- JSON.parse(STDIN.read)
43
+ JSON.parse($stdin.read)
43
44
  end
44
45
  begin
45
46
  catalog = Bolt::Catalog.new.compile_catalog(request)
@@ -6,7 +6,7 @@ require 'puppet'
6
6
  require 'puppet/module_tool/tar'
7
7
  require 'tempfile'
8
8
 
9
- args = JSON.parse(STDIN.read)
9
+ args = JSON.parse($stdin.read)
10
10
 
11
11
  Dir.mktmpdir do |puppet_root|
12
12
  # Create temporary directories for all core Puppet settings so we don't clobber
@@ -6,7 +6,7 @@ require 'puppet'
6
6
  require 'puppet/module_tool/tar'
7
7
  require 'tempfile'
8
8
 
9
- args = JSON.parse(STDIN.read)
9
+ args = JSON.parse($stdin.read)
10
10
 
11
11
  RESOURCE_INSTANCE = /^([^\[]+)\[([^\]]+)\]$/.freeze
12
12
 
@@ -0,0 +1,20 @@
1
+ plan secure_env_vars(
2
+ TargetSpec $targets,
3
+ Optional[String] $command = undef,
4
+ Optional[String] $script = undef
5
+ ) {
6
+ $env_vars = parsejson(system::env('BOLT_ENV_VARS'))
7
+ unless type($command) == Undef or type($script) == Undef {
8
+ fail_plan('Cannot specify both script and command for secure_env_vars')
9
+ }
10
+
11
+ return if $command {
12
+ run_command($command, $targets, '_env_vars' => $env_vars)
13
+ }
14
+ elsif $script {
15
+ run_script($script, $targets, '_env_vars' => $env_vars)
16
+ }
17
+ else {
18
+ fail_plan('Must specify either script or command for secure_env_vars')
19
+ }
20
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.0
4
+ version: 2.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-13 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -398,6 +398,7 @@ files:
398
398
  - bolt-modules/boltlib/lib/puppet/functions/add_to_group.rb
399
399
  - bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb
400
400
  - bolt-modules/boltlib/lib/puppet/functions/catch_errors.rb
401
+ - bolt-modules/boltlib/lib/puppet/functions/download_file.rb
401
402
  - bolt-modules/boltlib/lib/puppet/functions/facts.rb
402
403
  - bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb
403
404
  - bolt-modules/boltlib/lib/puppet/functions/get_resources.rb
@@ -426,6 +427,7 @@ files:
426
427
  - bolt-modules/boltlib/types/targetspec.pp
427
428
  - bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
428
429
  - bolt-modules/ctrl/lib/puppet/functions/ctrl/sleep.rb
430
+ - bolt-modules/dir/lib/puppet/functions/dir/children.rb
429
431
  - bolt-modules/file/lib/puppet/functions/file/exists.rb
430
432
  - bolt-modules/file/lib/puppet/functions/file/join.rb
431
433
  - bolt-modules/file/lib/puppet/functions/file/read.rb
@@ -479,7 +481,9 @@ files:
479
481
  - lib/bolt/pal/yaml_plan/parameter.rb
480
482
  - lib/bolt/pal/yaml_plan/step.rb
481
483
  - lib/bolt/pal/yaml_plan/step/command.rb
484
+ - lib/bolt/pal/yaml_plan/step/download.rb
482
485
  - lib/bolt/pal/yaml_plan/step/eval.rb
486
+ - lib/bolt/pal/yaml_plan/step/message.rb
483
487
  - lib/bolt/pal/yaml_plan/step/plan.rb
484
488
  - lib/bolt/pal/yaml_plan/step/resources.rb
485
489
  - lib/bolt/pal/yaml_plan/step/script.rb
@@ -550,6 +554,7 @@ files:
550
554
  - lib/bolt_spec/plans.rb
551
555
  - lib/bolt_spec/plans/action_stubs.rb
552
556
  - lib/bolt_spec/plans/action_stubs/command_stub.rb
557
+ - lib/bolt_spec/plans/action_stubs/download_stub.rb
553
558
  - lib/bolt_spec/plans/action_stubs/plan_stub.rb
554
559
  - lib/bolt_spec/plans/action_stubs/script_stub.rb
555
560
  - lib/bolt_spec/plans/action_stubs/task_stub.rb
@@ -573,6 +578,7 @@ files:
573
578
  - modules/canary/lib/puppet/functions/canary/skip.rb
574
579
  - modules/canary/plans/init.pp
575
580
  - modules/puppetdb_fact/plans/init.pp
581
+ - modules/secure_env_vars/plans/init.pp
576
582
  homepage: https://github.com/puppetlabs/bolt
577
583
  licenses:
578
584
  - Apache-2.0