pdk-akerl 1.9.1.1 → 1.14.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -0
  3. data/README.md +43 -4
  4. data/lib/pdk.rb +4 -2
  5. data/lib/pdk/analytics.rb +44 -0
  6. data/lib/pdk/analytics/client/google_analytics.rb +141 -0
  7. data/lib/pdk/analytics/client/noop.rb +23 -0
  8. data/lib/pdk/analytics/util.rb +17 -0
  9. data/lib/pdk/answer_file.rb +4 -1
  10. data/lib/pdk/cli.rb +50 -3
  11. data/lib/pdk/cli/build.rb +10 -4
  12. data/lib/pdk/cli/bundle.rb +10 -8
  13. data/lib/pdk/cli/config.rb +20 -0
  14. data/lib/pdk/cli/config/get.rb +24 -0
  15. data/lib/pdk/cli/console.rb +148 -0
  16. data/lib/pdk/cli/convert.rb +7 -2
  17. data/lib/pdk/cli/exec.rb +22 -190
  18. data/lib/pdk/cli/exec/command.rb +238 -0
  19. data/lib/pdk/cli/exec/interactive_command.rb +114 -0
  20. data/lib/pdk/cli/exec_group.rb +6 -6
  21. data/lib/pdk/cli/module/build.rb +0 -2
  22. data/lib/pdk/cli/module/generate.rb +4 -2
  23. data/lib/pdk/cli/new.rb +2 -0
  24. data/lib/pdk/cli/new/class.rb +2 -2
  25. data/lib/pdk/cli/new/defined_type.rb +4 -2
  26. data/lib/pdk/cli/new/module.rb +5 -0
  27. data/lib/pdk/cli/new/provider.rb +4 -2
  28. data/lib/pdk/cli/new/task.rb +4 -1
  29. data/lib/pdk/cli/new/test.rb +53 -0
  30. data/lib/pdk/cli/new/transport.rb +27 -0
  31. data/lib/pdk/cli/test.rb +0 -1
  32. data/lib/pdk/cli/test/unit.rb +18 -13
  33. data/lib/pdk/cli/update.rb +25 -3
  34. data/lib/pdk/cli/util.rb +111 -14
  35. data/lib/pdk/cli/util/interview.rb +10 -2
  36. data/lib/pdk/cli/util/option_validator.rb +4 -0
  37. data/lib/pdk/cli/util/spinner.rb +13 -0
  38. data/lib/pdk/cli/validate.rb +16 -5
  39. data/lib/pdk/config.rb +121 -0
  40. data/lib/pdk/config/analytics_schema.json +26 -0
  41. data/lib/pdk/config/errors.rb +5 -0
  42. data/lib/pdk/config/json.rb +34 -0
  43. data/lib/pdk/config/json_schema_namespace.rb +143 -0
  44. data/lib/pdk/config/json_schema_setting.rb +53 -0
  45. data/lib/pdk/config/json_with_schema.rb +50 -0
  46. data/lib/pdk/config/namespace.rb +332 -0
  47. data/lib/pdk/config/setting.rb +132 -0
  48. data/lib/pdk/config/yaml.rb +43 -0
  49. data/lib/pdk/config/yaml_with_schema.rb +59 -0
  50. data/lib/pdk/generate.rb +10 -3
  51. data/lib/pdk/generate/defined_type.rb +1 -0
  52. data/lib/pdk/generate/module.rb +62 -35
  53. data/lib/pdk/generate/provider.rb +0 -5
  54. data/lib/pdk/generate/puppet_class.rb +1 -0
  55. data/lib/pdk/generate/puppet_object.rb +88 -41
  56. data/lib/pdk/generate/transport.rb +87 -0
  57. data/lib/pdk/logger.rb +21 -1
  58. data/lib/pdk/module.rb +2 -2
  59. data/lib/pdk/module/build.rb +103 -10
  60. data/lib/pdk/module/convert.rb +85 -19
  61. data/lib/pdk/module/metadata.rb +17 -12
  62. data/lib/pdk/module/templatedir.rb +108 -40
  63. data/lib/pdk/module/update.rb +27 -15
  64. data/lib/pdk/module/update_manager.rb +23 -15
  65. data/lib/pdk/report.rb +4 -3
  66. data/lib/pdk/report/event.rb +8 -6
  67. data/lib/pdk/template_file.rb +1 -1
  68. data/lib/pdk/tests/unit.rb +48 -21
  69. data/lib/pdk/util.rb +29 -63
  70. data/lib/pdk/util/bundler.rb +19 -15
  71. data/lib/pdk/util/filesystem.rb +64 -1
  72. data/lib/pdk/util/git.rb +52 -1
  73. data/lib/pdk/util/puppet_strings.rb +123 -0
  74. data/lib/pdk/util/puppet_version.rb +27 -12
  75. data/lib/pdk/util/ruby_version.rb +30 -7
  76. data/lib/pdk/util/template_uri.rb +281 -0
  77. data/lib/pdk/util/vendored_file.rb +28 -24
  78. data/lib/pdk/util/version.rb +7 -8
  79. data/lib/pdk/util/windows.rb +1 -0
  80. data/lib/pdk/util/windows/api_types.rb +0 -7
  81. data/lib/pdk/util/windows/file.rb +1 -1
  82. data/lib/pdk/util/windows/string.rb +1 -1
  83. data/lib/pdk/validate/base_validator.rb +12 -14
  84. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -4
  85. data/lib/pdk/validate/metadata/metadata_syntax.rb +5 -3
  86. data/lib/pdk/validate/metadata_validator.rb +0 -2
  87. data/lib/pdk/validate/puppet/puppet_epp.rb +137 -0
  88. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
  89. data/lib/pdk/validate/puppet/puppet_syntax.rb +5 -5
  90. data/lib/pdk/validate/puppet_validator.rb +2 -3
  91. data/lib/pdk/validate/ruby/rubocop.rb +1 -6
  92. data/lib/pdk/validate/ruby_validator.rb +0 -2
  93. data/lib/pdk/validate/tasks/metadata_lint.rb +9 -5
  94. data/lib/pdk/validate/tasks/name.rb +5 -3
  95. data/lib/pdk/validate/tasks_validator.rb +0 -2
  96. data/lib/pdk/validate/yaml/syntax.rb +6 -4
  97. data/lib/pdk/validate/yaml_validator.rb +0 -2
  98. data/lib/pdk/version.rb +1 -1
  99. data/locales/pdk.pot +634 -307
  100. metadata +100 -45
@@ -1,12 +1,9 @@
1
- require 'pdk/version'
2
- require 'pdk/cli/exec'
3
- require 'pdk/util/git'
4
- require 'pdk/logger'
5
-
6
1
  module PDK
7
2
  module Util
8
3
  module Version
9
4
  def self.version_string
5
+ require 'pdk/version'
6
+
10
7
  "#{PDK::VERSION} #{pdk_ref}".strip.freeze
11
8
  end
12
9
 
@@ -25,15 +22,17 @@ module PDK
25
22
  end
26
23
 
27
24
  def self.git_ref
25
+ require 'pdk/util/git'
28
26
  source_git_dir = File.join(File.expand_path('../../..', File.dirname(__FILE__)), '.git')
29
27
 
30
- return nil unless File.directory?(source_git_dir)
28
+ return unless File.directory?(source_git_dir)
31
29
 
32
- ref_result = PDK::Util::Git.git('--git-dir', source_git_dir, 'describe', '--all', '--long')
33
- return ref_result[:stdout].strip if ref_result[:exit_code].zero?
30
+ PDK::Util::Git.describe(source_git_dir)
34
31
  end
35
32
 
36
33
  def self.version_file
34
+ require 'pdk/util'
35
+
37
36
  # FIXME: this gets called a LOT and doesn't currently get cached
38
37
  PDK::Util.find_upwards('PDK_VERSION', File.dirname(__FILE__))
39
38
  end
@@ -1,6 +1,7 @@
1
1
  module PDK
2
2
  module Util
3
3
  module Windows
4
+ WIN32_FALSE = 0
4
5
  module File; end
5
6
 
6
7
  if Gem.win_platform?
@@ -2,13 +2,6 @@ require 'ffi'
2
2
  require 'pdk/util/windows/string'
3
3
 
4
4
  module PDK::Util::Windows::APITypes
5
- module ::FFI
6
- WIN32_FALSE = 0
7
-
8
- # standard Win32 error codes
9
- ERROR_SUCCESS = 0
10
- end
11
-
12
5
  class ::FFI::Pointer
13
6
  def self.from_string_to_wide_string(str, &_block)
14
7
  str = PDK::Util::Windows::String.wide_string(str)
@@ -11,7 +11,7 @@ module PDK::Util::Windows::File
11
11
  # includes terminating NULL
12
12
  buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
13
13
  FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
14
- if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == FFI::WIN32_FALSE
14
+ if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE
15
15
  raise _('Failed to call GetLongPathName')
16
16
  end
17
17
 
@@ -3,7 +3,7 @@ require 'pdk/util/windows'
3
3
  module PDK::Util::Windows::String
4
4
  def wide_string(str)
5
5
  # if given a nil string, assume caller wants to pass a nil pointer to win32
6
- return nil if str.nil?
6
+ return if str.nil?
7
7
  # ruby (< 2.1) does not respect multibyte terminators, so it is possible
8
8
  # for a string to contain a single trailing null byte, followed by garbage
9
9
  # causing buffer overruns.
@@ -1,7 +1,3 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
- require 'pdk/module'
4
-
5
1
  module PDK
6
2
  module Validate
7
3
  class BaseValidator
@@ -49,25 +45,22 @@ module PDK
49
45
  invalid = []
50
46
  matched = targets.map { |target|
51
47
  if respond_to?(:pattern)
52
- if File.directory?(target)
48
+ if PDK::Util::Filesystem.directory?(target)
53
49
  target_root = PDK::Util.module_root
54
- pattern_glob = Array(pattern).map { |p| Dir.glob(File.join(target_root, p), File::FNM_DOTMATCH) }
55
-
56
- target_list = pattern_glob.flatten.map do |file|
57
- if File.fnmatch(File.join(File.expand_path(target), '*'), file, File::FNM_DOTMATCH)
58
- Pathname.new(file).relative_path_from(Pathname.new(PDK::Util.module_root)).to_s
59
- end
60
- end
50
+ pattern_glob = Array(pattern).map { |p| PDK::Util::Filesystem.glob(File.join(target_root, p), File::FNM_DOTMATCH) }
51
+ target_list = pattern_glob.flatten
52
+ .select { |glob| PDK::Util::Filesystem.fnmatch(File.join(PDK::Util::Filesystem.expand_path(PDK::Util.canonical_path(target)), '*'), glob, File::FNM_DOTMATCH) }
53
+ .map { |glob| Pathname.new(glob).relative_path_from(Pathname.new(PDK::Util.module_root)).to_s }
61
54
 
62
55
  ignore_list = ignore_pathspec
63
56
  target_list = target_list.reject { |file| ignore_list.match(file) }
64
57
 
65
58
  skipped << target if target_list.flatten.empty?
66
59
  target_list
67
- elsif File.file?(target)
60
+ elsif PDK::Util::Filesystem.file?(target)
68
61
  if Array(pattern).include? target
69
62
  target
70
- elsif Array(pattern).any? { |p| File.fnmatch(File.expand_path(p), File.expand_path(target), File::FNM_DOTMATCH) }
63
+ elsif Array(pattern).any? { |p| PDK::Util::Filesystem.fnmatch(PDK::Util::Filesystem.expand_path(p), PDK::Util::Filesystem.expand_path(target), File::FNM_DOTMATCH) }
71
64
  target
72
65
  else
73
66
  skipped << target
@@ -85,6 +78,8 @@ module PDK
85
78
  end
86
79
 
87
80
  def self.ignore_pathspec
81
+ require 'pdk/module'
82
+
88
83
  ignore_pathspec = PDK::Module.default_ignored_pathspec(ignore_dotfiles?)
89
84
 
90
85
  if respond_to?(:pattern_ignore)
@@ -139,6 +134,8 @@ module PDK
139
134
  end
140
135
 
141
136
  def self.invoke(report, options = {})
137
+ require 'pdk/cli/exec/command'
138
+
142
139
  targets, skipped, invalid = parse_targets(options)
143
140
 
144
141
  process_skipped(report, skipped)
@@ -157,6 +154,7 @@ module PDK
157
154
  if self::INVOKE_STYLE == :per_target
158
155
  targets = targets.combination(1).to_a
159
156
  else
157
+ require 'pdk/cli/exec_group'
160
158
  targets = targets.each_slice(1000).to_a
161
159
  options[:split_exec] = PDK::CLI::ExecGroup.new(spinner_text(targets), parallel: false)
162
160
  end
@@ -1,8 +1,4 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
- require 'pdk/util/bundler'
5
- require 'pathname'
6
2
 
7
3
  module PDK
8
4
  module Validate
@@ -1,7 +1,4 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
- require 'pathname'
5
2
 
6
3
  module PDK
7
4
  module Validate
@@ -21,13 +18,18 @@ module PDK
21
18
  end
22
19
 
23
20
  def self.create_spinner(targets = [], options = {})
21
+ require 'pdk/cli/util'
22
+
24
23
  return unless PDK::CLI::Util.interactive?
24
+
25
25
  options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
26
26
 
27
27
  exec_group = options[:exec_group]
28
28
  @spinner = if exec_group
29
29
  exec_group.add_spinner(spinner_text(targets), options)
30
30
  else
31
+ require 'pdk/cli/util/spinner'
32
+
31
33
  TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
32
34
  end
33
35
  @spinner.auto_spin
@@ -1,5 +1,3 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
2
  require 'pdk/validate/metadata/metadata_json_lint'
5
3
  require 'pdk/validate/metadata/metadata_syntax'
@@ -0,0 +1,137 @@
1
+ require 'pdk/validate/base_validator'
2
+
3
+ module PDK
4
+ module Validate
5
+ class PuppetEPP < BaseValidator
6
+ # In Puppet >= 5.3.4, the error context formatting was changed to facilitate localization
7
+ ERROR_CONTEXT = %r{(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))}
8
+ # In Puppet < 5.3.3, the error context was formatted in these variations:
9
+ # - "at file_path:line_num:col_num"
10
+ # - "at file_path:line_num"
11
+ # - "at line line_num"
12
+ # - "in file_path"
13
+ ERROR_CONTEXT_LEGACY = %r{(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))}
14
+
15
+ PUPPET_LOGGER_PREFIX = %r{^(debug|info|notice|warning|error|alert|critical):\s.+?$}i
16
+ PUPPET_SYNTAX_PATTERN = %r{^
17
+ (?<severity>.+?):\s
18
+ (?<message>.+?)
19
+ (?:
20
+ \s\(#{ERROR_CONTEXT}(,\s#{ERROR_CONTEXT})*\)| # attempt to match the new localisation friendly location
21
+ \s#{ERROR_CONTEXT_LEGACY}| # attempt to match the old " at file:line:column" location
22
+ $ # handle cases where the output has no location
23
+ )
24
+ $}x
25
+
26
+ def self.name
27
+ 'puppet-epp'
28
+ end
29
+
30
+ def self.cmd
31
+ 'puppet'
32
+ end
33
+
34
+ def self.pattern
35
+ '**/*.epp'
36
+ end
37
+
38
+ def self.pattern_ignore
39
+ ''
40
+ end
41
+
42
+ def self.spinner_text(_targets = nil)
43
+ _('Checking Puppet EPP syntax (%{pattern}).') % { pattern: pattern }
44
+ end
45
+
46
+ def self.parse_options(_options, targets)
47
+ # Due to PDK-1266 we need to run `puppet parser validate` with an empty
48
+ # modulepath. On *nix, Ruby treats `/dev/null` as an empty directory
49
+ # however it doesn't do so with `NUL` on Windows. The workaround for
50
+ # this to ensure consistent behaviour is to create an empty temporary
51
+ # directory and use that as the modulepath.
52
+ ['epp', 'validate', '--config', null_file, '--modulepath', validate_tmpdir].concat(targets)
53
+ end
54
+
55
+ def self.invoke(report, options)
56
+ super
57
+ ensure
58
+ remove_validate_tmpdir
59
+ end
60
+
61
+ def self.validate_tmpdir
62
+ require 'tmpdir'
63
+
64
+ @validate_tmpdir ||= Dir.mktmpdir('puppet-epp-validate')
65
+ end
66
+
67
+ def self.remove_validate_tmpdir
68
+ return unless @validate_tmpdir
69
+ return unless File.directory?(@validate_tmpdir)
70
+
71
+ require 'fileutils'
72
+
73
+ FileUtils.remove_entry_secure(@validate_tmpdir)
74
+ @validate_tmpdir = nil
75
+ end
76
+
77
+ def self.null_file
78
+ Gem.win_platform? ? 'NUL' : '/dev/null'
79
+ end
80
+
81
+ def self.parse_output(report, result, targets)
82
+ # Due to PUP-7504, we will have to programmatically construct the json
83
+ # object from the text output for now.
84
+ output = result[:stderr].split("\n").reject { |entry| entry.empty? }
85
+
86
+ results_data = []
87
+ output.each do |offense|
88
+ offense_data = parse_offense(offense)
89
+ results_data << offense_data
90
+ end
91
+
92
+ # puppet parser validate does not include files without problems in its
93
+ # output, so we need to go through the list of targets and add passing
94
+ # events to the report for any target not listed in the output.
95
+ targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
96
+ report.add_event(
97
+ file: target,
98
+ source: name,
99
+ severity: :ok,
100
+ state: :passed,
101
+ )
102
+ end
103
+
104
+ results_data.each do |offense|
105
+ report.add_event(offense)
106
+ end
107
+ end
108
+
109
+ def self.parse_offense(offense)
110
+ sanitize_console_output(offense)
111
+
112
+ offense_data = {
113
+ source: name,
114
+ state: :failure,
115
+ }
116
+
117
+ if offense.match(PUPPET_LOGGER_PREFIX)
118
+ attributes = offense.match(PUPPET_SYNTAX_PATTERN)
119
+
120
+ unless attributes.nil?
121
+ attributes.names.each do |name|
122
+ offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
123
+ end
124
+ end
125
+ else
126
+ offense_data[:message] = offense
127
+ end
128
+
129
+ offense_data
130
+ end
131
+
132
+ def self.sanitize_console_output(line)
133
+ line.gsub!(%r{\e\[([;\d]+)?m}, '')
134
+ end
135
+ end
136
+ end
137
+ end
@@ -1,6 +1,3 @@
1
- require 'pdk'
2
- require 'pdk/util'
3
- require 'pdk/cli/exec'
4
1
  require 'pdk/validate/base_validator'
5
2
 
6
3
  module PDK
@@ -1,8 +1,4 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
- require 'fileutils'
5
- require 'tmpdir'
6
2
 
7
3
  module PDK
8
4
  module Validate
@@ -36,7 +32,7 @@ module PDK
36
32
  end
37
33
 
38
34
  def self.pattern
39
- '**/**.pp'
35
+ '**/*.pp'
40
36
  end
41
37
 
42
38
  def self.pattern_ignore
@@ -63,6 +59,8 @@ module PDK
63
59
  end
64
60
 
65
61
  def self.validate_tmpdir
62
+ require 'tmpdir'
63
+
66
64
  @validate_tmpdir ||= Dir.mktmpdir('puppet-parser-validate')
67
65
  end
68
66
 
@@ -70,6 +68,8 @@ module PDK
70
68
  return unless @validate_tmpdir
71
69
  return unless File.directory?(@validate_tmpdir)
72
70
 
71
+ require 'fileutils'
72
+
73
73
  FileUtils.remove_entry_secure(@validate_tmpdir)
74
74
  @validate_tmpdir = nil
75
75
  end
@@ -1,8 +1,7 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
2
  require 'pdk/validate/puppet/puppet_lint'
5
3
  require 'pdk/validate/puppet/puppet_syntax'
4
+ require 'pdk/validate/puppet/puppet_epp'
6
5
 
7
6
  module PDK
8
7
  module Validate
@@ -12,7 +11,7 @@ module PDK
12
11
  end
13
12
 
14
13
  def self.puppet_validators
15
- [PuppetSyntax, PuppetLint]
14
+ [PuppetSyntax, PuppetLint, PuppetEPP]
16
15
  end
17
16
 
18
17
  def self.invoke(report, options = {})
@@ -1,9 +1,4 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
- require 'pdk/util'
4
- require 'pdk/util/bundler'
5
1
  require 'pdk/validate/base_validator'
6
- require 'pdk/validate/ruby_validator'
7
2
 
8
3
  module PDK
9
4
  module Validate
@@ -63,7 +58,7 @@ module PDK
63
58
  line: offense['location']['line'],
64
59
  column: offense['location']['column'],
65
60
  message: offense['message'],
66
- severity: (offense['corrected']) ? 'corrected' : offense['severity'],
61
+ severity: offense['corrected'] ? 'corrected' : offense['severity'],
67
62
  test: offense['cop_name'],
68
63
  state: :failure,
69
64
  ),
@@ -1,5 +1,3 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
2
  require 'pdk/validate/ruby/rubocop'
5
3
 
@@ -1,9 +1,4 @@
1
- require 'pdk'
2
- require 'pdk/cli/exec'
3
1
  require 'pdk/validate/base_validator'
4
- require 'pdk/util'
5
- require 'pathname'
6
- require 'json-schema'
7
2
 
8
3
  module PDK
9
4
  module Validate
@@ -26,13 +21,18 @@ module PDK
26
21
  end
27
22
 
28
23
  def self.create_spinner(targets = [], options = {})
24
+ require 'pdk/cli/util'
25
+
29
26
  return unless PDK::CLI::Util.interactive?
27
+
30
28
  options = options.merge(PDK::CLI::Util.spinner_opts_for_platform)
31
29
 
32
30
  exec_group = options[:exec_group]
33
31
  @spinner = if exec_group
34
32
  exec_group.add_spinner(spinner_text(targets), options)
35
33
  else
34
+ require 'pdk/cli/util/spinner'
35
+
36
36
  TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", options)
37
37
  end
38
38
  @spinner.auto_spin
@@ -47,6 +47,8 @@ module PDK
47
47
  end
48
48
 
49
49
  def self.schema_file
50
+ require 'pdk/util/vendored_file'
51
+
50
52
  schema = PDK::Util::VendoredFile.new('task.json', FORGE_SCHEMA_URL).read
51
53
 
52
54
  JSON.parse(schema)
@@ -67,6 +69,8 @@ module PDK
67
69
  return_val = 0
68
70
  create_spinner(targets, options)
69
71
 
72
+ require 'json-schema'
73
+
70
74
  targets.each do |target|
71
75
  unless File.readable?(target)
72
76
  report.add_event(