puppet-debugger 0.17.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +12 -26
  3. data/.rubocop.yml +64 -232
  4. data/.rubocop_todo.yml +89 -147
  5. data/.vscode/launch.json +15 -0
  6. data/CHANGELOG.md +29 -0
  7. data/Gemfile +9 -6
  8. data/README.md +27 -14
  9. data/Rakefile +11 -12
  10. data/bin/pdb +1 -1
  11. data/lib/awesome_print/ext/awesome_puppet.rb +10 -8
  12. data/lib/plugins/puppet-debugger/input_responders/benchmark.rb +5 -4
  13. data/lib/plugins/puppet-debugger/input_responders/classes.rb +14 -2
  14. data/lib/plugins/puppet-debugger/input_responders/classification.rb +4 -2
  15. data/lib/plugins/puppet-debugger/input_responders/commands.rb +18 -18
  16. data/lib/plugins/puppet-debugger/input_responders/datatypes.rb +22 -6
  17. data/lib/plugins/puppet-debugger/input_responders/environment.rb +4 -2
  18. data/lib/plugins/puppet-debugger/input_responders/exit.rb +5 -3
  19. data/lib/plugins/puppet-debugger/input_responders/facterdb_filter.rb +4 -2
  20. data/lib/plugins/puppet-debugger/input_responders/facts.rb +4 -2
  21. data/lib/plugins/puppet-debugger/input_responders/functions.rb +34 -32
  22. data/lib/plugins/puppet-debugger/input_responders/help.rb +4 -2
  23. data/lib/plugins/puppet-debugger/input_responders/krt.rb +4 -2
  24. data/lib/plugins/puppet-debugger/input_responders/play.rb +22 -24
  25. data/lib/plugins/puppet-debugger/input_responders/reset.rb +5 -3
  26. data/lib/plugins/puppet-debugger/input_responders/resources.rb +16 -7
  27. data/lib/plugins/puppet-debugger/input_responders/set.rb +34 -32
  28. data/lib/plugins/puppet-debugger/input_responders/stacktrace.rb +31 -0
  29. data/lib/plugins/puppet-debugger/input_responders/types.rb +6 -2
  30. data/lib/plugins/puppet-debugger/input_responders/vars.rb +8 -7
  31. data/lib/plugins/puppet-debugger/input_responders/whereami.rb +5 -3
  32. data/lib/puppet-debugger/cli.rb +129 -91
  33. data/lib/puppet-debugger/code/code_file.rb +13 -14
  34. data/lib/puppet-debugger/code/code_range.rb +5 -3
  35. data/lib/puppet-debugger/code/loc.rb +1 -1
  36. data/lib/puppet-debugger/debugger_code.rb +2 -0
  37. data/lib/puppet-debugger/hooks.rb +15 -16
  38. data/lib/puppet-debugger/input_responder_plugin.rb +54 -52
  39. data/lib/puppet-debugger/monkey_patches.rb +4 -1
  40. data/lib/puppet-debugger/plugin_test_helper.rb +9 -8
  41. data/lib/puppet-debugger/support.rb +44 -18
  42. data/lib/puppet-debugger/support/environment.rb +6 -5
  43. data/lib/puppet-debugger/support/errors.rb +25 -27
  44. data/lib/puppet-debugger/support/facts.rb +5 -5
  45. data/lib/puppet-debugger/support/node.rb +4 -7
  46. data/lib/puppet-debugger/support/scope.rb +29 -0
  47. data/lib/puppet-debugger/trollop.rb +38 -31
  48. data/lib/puppet-debugger/version.rb +1 -1
  49. data/lib/puppet/application/debugger.rb +151 -126
  50. data/output.json +1 -0
  51. data/puppet-debugger.gemspec +18 -15
  52. data/spec/awesome_print/ext/awesome_puppet_spec.rb +30 -30
  53. data/spec/fixtures/pe-xl-core-0.puppet.vm.json +1 -0
  54. data/spec/fixtures/sample_start_debugger.pp +3 -2
  55. data/spec/hooks_spec.rb +33 -35
  56. data/spec/input_responder_plugin_spec.rb +7 -6
  57. data/spec/input_responders/benchmark_spec.rb +3 -1
  58. data/spec/input_responders/classes_spec.rb +12 -13
  59. data/spec/input_responders/classification_spec.rb +4 -2
  60. data/spec/input_responders/commands_spec.rb +2 -0
  61. data/spec/input_responders/datatypes_spec.rb +8 -2
  62. data/spec/input_responders/environment_spec.rb +2 -0
  63. data/spec/input_responders/exit_spec.rb +9 -11
  64. data/spec/input_responders/facterdb_filter_spec.rb +2 -0
  65. data/spec/input_responders/facts_spec.rb +2 -0
  66. data/spec/input_responders/functions_spec.rb +30 -28
  67. data/spec/input_responders/help_spec.rb +5 -3
  68. data/spec/input_responders/krt_spec.rb +3 -1
  69. data/spec/input_responders/play_spec.rb +10 -20
  70. data/spec/input_responders/reset_spec.rb +2 -0
  71. data/spec/input_responders/resources_spec.rb +7 -1
  72. data/spec/input_responders/set_spec.rb +3 -1
  73. data/spec/input_responders/stacktrace_spec.rb +15 -0
  74. data/spec/input_responders/types_spec.rb +2 -0
  75. data/spec/input_responders/vars_spec.rb +4 -4
  76. data/spec/input_responders/whereami_spec.rb +2 -0
  77. data/spec/pdb_spec.rb +0 -9
  78. data/spec/puppet/application/debugger_spec.rb +35 -17
  79. data/spec/puppet_debugger_spec.rb +81 -84
  80. data/spec/remote_node_spec.rb +1 -5
  81. data/spec/spec_helper.rb +22 -18
  82. data/spec/support_spec.rb +3 -5
  83. data/test_matrix.rb +1 -1
  84. metadata +54 -21
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "chrome",
9
+ "request": "launch",
10
+ "name": "Launch Chrome against localhost",
11
+ "url": "http://localhost:8080",
12
+ "webRoot": "${workspaceFolder}"
13
+ }
14
+ ]
15
+ }
data/CHANGELOG.md CHANGED
@@ -1,4 +1,33 @@
1
+ # Puppet Debugger Changelog
2
+
1
3
  ## Unreleased
4
+ ## 1.2
5
+ - Fix puppetdb_query errors when bolt_pdb_client was not loaded
6
+ ## 1.1
7
+ - Catch signals and allow control-d for quitting.
8
+ ## 1.0
9
+ Released: 8/3/2020
10
+
11
+ This is a major revision with breaking changes, notably the requirement of ruby 2.4 and puppet 5.5.
12
+
13
+ - Bump required ruby version to 2.4
14
+ - Bump required puppet version to puppet 5.5
15
+ - Add stacktrace plugin
16
+ - Add a pager for long output
17
+ - Remove puppet4 and older work arounds
18
+ - Use rubocop for better code quality
19
+ - Fix issue when the debugger was not loading the manifest properly
20
+
21
+ ## 0.19.0
22
+ - Search datatypes with filter
23
+ - Fix #8 - trusted_server_facts' as a setting is deprecated
24
+
25
+ ## 0.18.0
26
+ - Add bundler as a dependency
27
+ - Add ability to filter out classes
28
+ - Add ability to filter out resources
29
+ - Add ability to supply a catalog
30
+ - Add vendormoduledir to module paths
2
31
 
3
32
  ## 0.17.0
4
33
  - Fix bolt issue when the catalog is referenced
data/Gemfile CHANGED
@@ -1,23 +1,26 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'http://rubygems.org'
3
4
  gem 'awesome_print', '~> 1.7'
4
5
  gem 'facterdb', '>= 0.5.0'
5
- gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4.10.1'
6
6
  gem 'pluginator', '~> 1.5.0'
7
+ gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 5.5'
7
8
  gem 'rb-readline'
8
9
  gem 'table_print'
10
+ gem 'tty-pager'
11
+ #gem 'bolt' if Gem::Version(ENV['PUPPET_GEM_VERSION'])
12
+
9
13
  group :test, :development do
10
14
  # ruby versions prior to 2.0 cannot install json_pure 2.0.2+
11
15
  gem 'bundler'
12
- gem 'CFPropertyList'
13
16
  gem 'pry'
14
17
  gem 'puppet-debugger', path: './'
15
- gem 'rake', '= 12.3.3'
18
+ gem 'rake', '~> 13.0'
16
19
  gem 'rdoc', '~> 3.12'
17
20
  gem 'release_me'
18
21
  gem 'rspec', '~> 3.6'
22
+ gem 'rubocop'
23
+ gem 'rubocop-performance'
24
+ gem 'rubocop-rspec'
19
25
  gem 'simplecov', '>= 0'
20
- gem 'rubocop', '= 0.48.0'
21
-
22
26
  end
23
-
data/README.md CHANGED
@@ -35,7 +35,7 @@ A interactive command line tool for evaluating and debugging the puppet language
35
35
  Please visit https://docs.puppet-debugger.com for more info.
36
36
 
37
37
  ## Compatibility
38
- Requires Puppet 3.8+ and only uses the future parser. Works with puppet 4-6.
38
+ Requires Puppet 5.5+, ruby 2.4+
39
39
 
40
40
  ## Production usage
41
41
  The puppet debugger is a developer tool that should only be used when writing puppet code. Although it might seem useful
@@ -63,22 +63,35 @@ and see what it would actual do when compiling a resource.
63
63
 
64
64
  Example Usage
65
65
  ```
66
- MacBook-Pro-2/tmp % puppet debugger
67
- Ruby Version: 2.0.0
68
- Puppet Version: 4.8.1
69
- Puppet Debugger Version: 0.4.3
66
+ Ruby Version: 2.6.5
67
+ Puppet Version: 6.17.0
68
+ Puppet Debugger Version: 1.0.0
70
69
  Created by: NWOps <corey@nwops.io>
71
- Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
72
- "play", "classification", "reset", or "help" for more information.
73
-
74
- 1:>> ['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }
75
- => [
76
- [0] "/tmp/test3",
77
- [1] "/tmp/test4"
78
- ]
70
+ Type "commands" for a list of debugger commands
71
+ or "help" to show the help screen.
72
+
73
+
74
+ 1:>> $os
75
+ => {
76
+ "architecture" => "x86_64",
77
+ "family" => "RedHat",
78
+ "hardware" => "x86_64",
79
+ "name" => "Fedora",
80
+ "release" => {
81
+ "full" => "23",
82
+ "major" => "23"
83
+ },
84
+ "selinux" => {
85
+ "config_mode" => "permissive",
86
+ "config_policy" => "targeted",
87
+ "current_mode" => "permissive",
88
+ "enabled" => true,
89
+ "enforced" => false,
90
+ "policy_version" => "29"
91
+ }
92
+ }
79
93
  2:>>
80
94
 
81
-
82
95
  ```
83
96
 
84
97
  ## Copyright
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'rubygems'
@@ -9,8 +8,8 @@ require 'rake/testtask'
9
8
  begin
10
9
  Bundler.setup(:default, :development, :test)
11
10
  rescue Bundler::BundlerError => e
12
- $stderr.puts e.message
13
- $stderr.puts 'Run `bundle install` to install missing gems'
11
+ warn e.message
12
+ warn 'Run `bundle install` to install missing gems'
14
13
  exit e.status_code
15
14
  end
16
15
  require 'rake'
@@ -34,13 +33,14 @@ end
34
33
 
35
34
  desc 'Creates generic input_responder spec files'
36
35
  task :make_input_responder_tests do
37
- files = Dir.glob("lib/plugins/**/*.rb")
38
- new_files = files.collect do |pathname|
39
- orig_file = File.basename(pathname, ".*")
36
+ files = Dir.glob('lib/plugins/**/*.rb')
37
+ files.collect do |pathname|
38
+ orig_file = File.basename(pathname, '.*')
40
39
  test_file = File.join('spec', 'input_responders', "#{orig_file}_spec.rb")
41
- unless File.exist?(test_file)
42
- new_file = File.new(test_file, "w")
43
- contents = <<-EOS
40
+ next if File.exist?(test_file)
41
+
42
+ # new_file = File.new(test_file, "w")
43
+ contents = <<-OUT
44
44
  require 'spec_helper'
45
45
  require 'puppet-debugger'
46
46
  require 'puppet-debugger/plugin_test_helper'
@@ -50,8 +50,7 @@ task :make_input_responder_tests do
50
50
  let(:args) { [] }
51
51
 
52
52
  end
53
- EOS
54
- File.write(test_file, contents)
55
- end
53
+ OUT
54
+ File.write(test_file, contents)
56
55
  end
57
56
  end
data/bin/pdb CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  require 'puppet-debugger'
5
5
 
6
- puts "The debugger pdb command will be removed in a future release please use puppet-debugger or puppet debugger instead".warning
6
+ puts 'The debugger pdb command will be removed in a future release please use puppet-debugger or puppet debugger instead'.warning
7
7
  PuppetDebugger::Cli.start
@@ -52,6 +52,7 @@ module AwesomePrint
52
52
 
53
53
  def awesome_puppet_resource(object)
54
54
  return '' if object.nil?
55
+
55
56
  resource_object = object.to_ral
56
57
  awesome_puppet_type(resource_object)
57
58
  end
@@ -59,16 +60,17 @@ module AwesomePrint
59
60
  def awesome_puppet_type(object)
60
61
  return '' if object.nil?
61
62
  return object.to_s unless object.respond_to?(:name) && object.respond_to?(:title) && object.respond_to?(:to_hash)
62
- if Array.new.respond_to?(:to_h)
63
- # to_h is only supported in ruby 2.1+
64
- h = object.to_hash.merge(name: object.name, title: object.title).sort.to_h
65
- else
66
- h = object.to_hash.merge(name: object.name, title: object.title)
67
- end
68
- res_str = awesome_hash(JSON.parse(h.to_json)) #converting to json removes symbols
63
+
64
+ h = if [].respond_to?(:to_h)
65
+ # to_h is only supported in ruby 2.1+
66
+ object.to_hash.merge(name: object.name, title: object.title).sort.to_h
67
+ else
68
+ object.to_hash.merge(name: object.name, title: object.title)
69
+ end
70
+ res_str = awesome_hash(JSON.parse(h.to_json)) # converting to json removes symbols
69
71
  "#{object.class} #{res_str}"
70
72
  end
71
73
  end
72
74
  end
73
75
 
74
- AwesomePrint::Formatter.send(:include, AwesomePrint::Puppet)
76
+ AwesomePrint::Formatter.include AwesomePrint::Puppet
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'benchmark'
2
4
  require 'puppet-debugger/input_responder_plugin'
3
5
  module PuppetDebugger
4
6
  module InputResponders
5
7
  class Benchmark < InputResponderPlugin
6
- COMMAND_WORDS = %w(benchmark bm)
8
+ COMMAND_WORDS = %w[benchmark bm].freeze
7
9
  SUMMARY = 'Benchmark your Puppet code.'
8
10
  COMMAND_GROUP = :tools
9
11
 
10
12
  def run(args = [])
11
- if args.count > 0
13
+ if args.count.positive?
12
14
  enable(false)
13
15
  out = debugger.handle_input(args.first)
14
16
  disable
@@ -34,7 +36,6 @@ module PuppetDebugger
34
36
  'On'
35
37
  end
36
38
  end
37
-
38
39
  end
39
40
  end
40
- end
41
+ end
@@ -1,15 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Classes < InputResponderPlugin
5
- COMMAND_WORDS = %w(classes)
7
+ COMMAND_WORDS = %w[classes].freeze
6
8
  SUMMARY = 'List all the classes current in the catalog.'
7
9
  COMMAND_GROUP = :scope
8
10
 
9
11
  def run(args = [])
10
- debugger.scope.compiler.catalog.classes.ai
12
+ filter = args
13
+ classes = find_classes(debugger.catalog.classes, filter)
14
+ classes.ai
11
15
  end
12
16
 
17
+ def find_classes(classes, filter = [])
18
+ return classes if filter.nil? || filter.empty?
19
+
20
+ filter_string = filter.join(' ').downcase
21
+ classes.find_all do |klass|
22
+ klass.downcase.include?(filter_string)
23
+ end
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Classification < InputResponderPlugin
5
- COMMAND_WORDS = %w(classification)
7
+ COMMAND_WORDS = %w[classification].freeze
6
8
  SUMMARY = 'Show the classification details of the node.'
7
9
  COMMAND_GROUP = :node
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  debugger.node.classes.ai
11
13
  end
12
14
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Commands < InputResponderPlugin
5
- COMMAND_WORDS = %w(commands)
7
+ COMMAND_WORDS = %w[commands].freeze
6
8
  SUMMARY = 'List all available commands, aka. this screen'
7
9
  COMMAND_GROUP = :help
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  commands_list
11
13
  end
12
14
 
@@ -31,9 +33,9 @@ module PuppetDebugger
31
33
  def command_groups
32
34
  unless @command_groups
33
35
  @command_groups = {}
34
- self.class.command_output.each do | item|
36
+ self.class.command_output.each do |item|
35
37
  if @command_groups[item[:group]]
36
- @command_groups[item[:group]].merge!({ item[:words].first => item[:summary] })
38
+ @command_groups[item[:group]].merge!(item[:words].first => item[:summary])
37
39
  else
38
40
  @command_groups[item[:group]] = { item[:words].first => item[:summary] }
39
41
  end
@@ -43,12 +45,12 @@ module PuppetDebugger
43
45
  end
44
46
 
45
47
  def self.command_list_regex
46
- out = command_list.map {|n| "^#{n}"}.join('|')
47
- %r(#{out})
48
+ out = command_list.map { |n| "^#{n}" }.join('|')
49
+ /#{out}/
48
50
  end
49
51
 
50
52
  def self.command_list
51
- command_output.map{|f| f[:words] }.flatten
53
+ command_output.map { |f| f[:words] }.flatten
52
54
  end
53
55
 
54
56
  def self.command_output
@@ -56,22 +58,20 @@ module PuppetDebugger
56
58
  end
57
59
 
58
60
  def self.plugins
59
- begin
60
- debug_plugins = Pluginator.find('puppet-debugger')
61
- debug_plugins["input_responders"]
62
- rescue NoMethodError => e
63
- raise PuppetDebugger::Exception::InvalidCommand.new(message: "Unsupported gem version. Please update with: gem update --system")
64
- end
61
+ debug_plugins = Pluginator.find('puppet-debugger')
62
+ debug_plugins['input_responders']
63
+ rescue NoMethodError
64
+ raise PuppetDebugger::Exception::InvalidCommand.new(message: 'Unsupported gem version. Please update with: gem update --system')
65
65
  end
66
66
 
67
67
  # @param name [String] - the name of the command that is associated with a plugin
68
68
  # @return [PuppetDebugger::InputResponders::InputResponderPlugin]
69
69
  def self.plugin_from_command(name)
70
- p = plugins.find {|p| p::COMMAND_WORDS.include?(name)}
71
- raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless p
72
- p
73
- end
70
+ plug = plugins.find { |p| p::COMMAND_WORDS.include?(name) }
71
+ raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless plug
74
72
 
73
+ plug
74
+ end
75
75
  end
76
76
  end
77
- end
77
+ end
@@ -1,13 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Datatypes < InputResponderPlugin
5
- COMMAND_WORDS = %w(datatypes)
7
+ COMMAND_WORDS = %w[datatypes].freeze
6
8
  SUMMARY = 'List all the datatypes available in the environment.'
7
9
  COMMAND_GROUP = :environment
8
10
 
9
11
  def run(args = [])
10
- all_data_types.sort.ai
12
+ filter = args
13
+ datatypes = find_datatypes(all_data_types.sort, filter)
14
+ datatypes.ai
15
+ end
16
+
17
+ def find_datatypes(datatypes, filter = [])
18
+ return datatypes if filter.nil? || filter.empty?
19
+
20
+ filter_string = filter.join(' ').downcase
21
+ datatypes.find_all do |datatype|
22
+ datatype.downcase.include?(filter_string)
23
+ end
11
24
  end
12
25
 
13
26
  # @return [Array[String]] - returns a list of all the custom data types found in all the modules in the environment
@@ -17,15 +30,19 @@ module PuppetDebugger
17
30
  files.map do |f|
18
31
  m = File.read(f).match(/type\s([a-z\d\:_]+)/i)
19
32
  next if m =~ /type|alias/ # can't figure out the best way to filter type and alias out
33
+
20
34
  m[1] if m && m[1] =~ /::/
21
35
  end.uniq.compact
22
36
  end
23
37
 
38
+ # loaders.instance_variable_get(:@loaders_by_name)['boltlib']
39
+ # [:func_4x, :func_4xpp, :func_3x, :datatype, :type_pp,
40
+ # :resource_type_pp, :plan, :task]
24
41
  # @return [Array[String]] - a list of core data types
25
42
  def core_datatypes
26
- loaders.implementation_registry
27
- .instance_variable_get(:'@implementations_per_type_name')
28
- .keys.find_all { |t| t !~ /::/ }
43
+ loaders.implementation_registry.instance_variable_get(:@parent)
44
+ .instance_variable_get(:@implementations_per_type_name)
45
+ .keys.find_all { |t| t !~ /::/ }
29
46
  end
30
47
 
31
48
  # @return [Array[String]] - combined list of core data types and environment data types
@@ -36,7 +53,6 @@ module PuppetDebugger
36
53
  end
37
54
  core_datatypes + environment_data_types
38
55
  end
39
-
40
56
  end
41
57
  end
42
58
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Environment < InputResponderPlugin
5
- COMMAND_WORDS = %w(environment)
7
+ COMMAND_WORDS = %w[environment].freeze
6
8
  SUMMARY = 'Show the current environment name'
7
9
  COMMAND_GROUP = :context
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  "Puppet Environment: #{debugger.puppet_env_name}"
11
13
  end
12
14
  end