pdk 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +11 -10
  4. data/lib/pdk/analytics/client/google_analytics.rb +4 -2
  5. data/lib/pdk/cli/build.rb +17 -21
  6. data/lib/pdk/cli/bundle.rb +4 -5
  7. data/lib/pdk/cli/config/get.rb +6 -6
  8. data/lib/pdk/cli/config.rb +3 -3
  9. data/lib/pdk/cli/console.rb +7 -7
  10. data/lib/pdk/cli/convert.rb +11 -11
  11. data/lib/pdk/cli/env.rb +3 -4
  12. data/lib/pdk/cli/errors.rb +1 -1
  13. data/lib/pdk/cli/exec/command.rb +12 -14
  14. data/lib/pdk/cli/exec/interactive_command.rb +11 -11
  15. data/lib/pdk/cli/exec.rb +4 -4
  16. data/lib/pdk/cli/exec_group.rb +1 -3
  17. data/lib/pdk/cli/get/config.rb +5 -5
  18. data/lib/pdk/cli/get.rb +2 -2
  19. data/lib/pdk/cli/module/build.rb +3 -3
  20. data/lib/pdk/cli/module/generate.rb +4 -4
  21. data/lib/pdk/cli/module.rb +3 -3
  22. data/lib/pdk/cli/new/class.rb +4 -4
  23. data/lib/pdk/cli/new/defined_type.rb +4 -4
  24. data/lib/pdk/cli/new/fact.rb +3 -3
  25. data/lib/pdk/cli/new/function.rb +4 -4
  26. data/lib/pdk/cli/new/module.rb +10 -11
  27. data/lib/pdk/cli/new/provider.rb +3 -3
  28. data/lib/pdk/cli/new/task.rb +5 -5
  29. data/lib/pdk/cli/new/test.rb +7 -7
  30. data/lib/pdk/cli/new/transport.rb +3 -3
  31. data/lib/pdk/cli/new.rb +3 -3
  32. data/lib/pdk/cli/release/prep.rb +9 -9
  33. data/lib/pdk/cli/release/publish.rb +7 -11
  34. data/lib/pdk/cli/release.rb +35 -39
  35. data/lib/pdk/cli/remove/config.rb +15 -15
  36. data/lib/pdk/cli/remove.rb +2 -2
  37. data/lib/pdk/cli/set/config.rb +16 -16
  38. data/lib/pdk/cli/set.rb +2 -2
  39. data/lib/pdk/cli/test/unit.rb +13 -13
  40. data/lib/pdk/cli/test.rb +2 -2
  41. data/lib/pdk/cli/update.rb +19 -29
  42. data/lib/pdk/cli/util/command_redirector.rb +1 -1
  43. data/lib/pdk/cli/util/interview.rb +4 -4
  44. data/lib/pdk/cli/util/option_normalizer.rb +2 -2
  45. data/lib/pdk/cli/util/option_validator.rb +1 -1
  46. data/lib/pdk/cli/util.rb +19 -20
  47. data/lib/pdk/cli/validate.rb +16 -18
  48. data/lib/pdk/cli.rb +16 -33
  49. data/lib/pdk/config/ini_file_setting.rb +2 -2
  50. data/lib/pdk/config/json_schema_namespace.rb +3 -3
  51. data/lib/pdk/config/json_schema_setting.rb +1 -1
  52. data/lib/pdk/config/json_with_schema.rb +1 -1
  53. data/lib/pdk/config/namespace.rb +4 -4
  54. data/lib/pdk/config/setting.rb +5 -5
  55. data/lib/pdk/config/validator.rb +2 -2
  56. data/lib/pdk/config/yaml.rb +2 -2
  57. data/lib/pdk/config/yaml_with_schema.rb +3 -3
  58. data/lib/pdk/config.rb +18 -20
  59. data/lib/pdk/context/control_repo.rb +1 -1
  60. data/lib/pdk/context/module.rb +1 -1
  61. data/lib/pdk/context/none.rb +1 -1
  62. data/lib/pdk/generate/module.rb +52 -64
  63. data/lib/pdk/generate/puppet_object.rb +6 -6
  64. data/lib/pdk/generate/task.rb +1 -1
  65. data/lib/pdk/module/build.rb +11 -16
  66. data/lib/pdk/module/convert.rb +14 -16
  67. data/lib/pdk/module/metadata.rb +12 -12
  68. data/lib/pdk/module/release.rb +20 -19
  69. data/lib/pdk/module/update.rb +5 -5
  70. data/lib/pdk/module/update_manager.rb +6 -6
  71. data/lib/pdk/report/event.rb +11 -11
  72. data/lib/pdk/template/fetcher/git.rb +4 -4
  73. data/lib/pdk/template/fetcher.rb +1 -1
  74. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +1 -1
  75. data/lib/pdk/template/renderer/v1/renderer.rb +5 -7
  76. data/lib/pdk/template/renderer/v1/template_file.rb +3 -1
  77. data/lib/pdk/template/template_dir.rb +1 -1
  78. data/lib/pdk/template.rb +2 -2
  79. data/lib/pdk/tests/unit.rb +12 -12
  80. data/lib/pdk/util/bundler.rb +14 -14
  81. data/lib/pdk/util/changelog_generator.rb +6 -8
  82. data/lib/pdk/util/filesystem.rb +2 -2
  83. data/lib/pdk/util/git.rb +5 -5
  84. data/lib/pdk/util/puppet_strings.rb +2 -2
  85. data/lib/pdk/util/puppet_version.rb +24 -17
  86. data/lib/pdk/util/ruby_version.rb +2 -5
  87. data/lib/pdk/util/template_uri.rb +8 -8
  88. data/lib/pdk/util/vendored_file.rb +3 -3
  89. data/lib/pdk/util/windows/api_types.rb +3 -4
  90. data/lib/pdk/util/windows/file.rb +1 -1
  91. data/lib/pdk/util/windows/process.rb +5 -8
  92. data/lib/pdk/util.rb +2 -2
  93. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +5 -5
  94. data/lib/pdk/validate/invokable_validator.rb +6 -6
  95. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +2 -2
  96. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +2 -2
  97. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +1 -1
  98. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +1 -1
  99. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
  100. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +1 -1
  101. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -0
  102. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +1 -1
  103. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +4 -4
  104. data/lib/pdk/validate/tasks/tasks_name_validator.rb +2 -5
  105. data/lib/pdk/validate/validator.rb +1 -1
  106. data/lib/pdk/validate/validator_group.rb +1 -1
  107. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +4 -4
  108. data/lib/pdk/validate.rb +2 -1
  109. data/lib/pdk/version.rb +2 -2
  110. data/lib/pdk.rb +0 -2
  111. metadata +32 -54
  112. data/lib/pdk/i18n.rb +0 -4
  113. data/locales/config.yaml +0 -21
  114. data/locales/pdk.pot +0 -2111
@@ -5,8 +5,8 @@ module PDK
5
5
  module Util
6
6
  module Filesystem
7
7
  def write_file(path, content)
8
- raise ArgumentError, _('content must be a String') unless content.is_a?(String)
9
- raise ArgumentError, _('path must be a String or Pathname') unless path.is_a?(String) || path.respond_to?(:to_path)
8
+ raise ArgumentError, 'content must be a String' unless content.is_a?(String)
9
+ raise ArgumentError, 'path must be a String or Pathname' unless path.is_a?(String) || path.respond_to?(:to_path)
10
10
 
11
11
  # Harmonize newlines across platforms.
12
12
  content = content.encode(universal_newline: true)
data/lib/pdk/util/git.rb CHANGED
@@ -14,7 +14,7 @@ module PDK
14
14
  @stderr = result[:stderr]
15
15
  @exit_code = result[:exit_code]
16
16
 
17
- super(_('Git command failed: git %{args}' % { args: args.join(' ') }))
17
+ super('Git command failed: git %{args}' % { args: args.join(' ') })
18
18
  end
19
19
  end
20
20
 
@@ -100,8 +100,8 @@ module PDK
100
100
  end
101
101
 
102
102
  def self.work_dir_clean?(repo)
103
- raise PDK::CLI::ExitWithError, _('Unable to locate git work dir "%{workdir}"') % { workdir: repo } unless PDK::Util::Filesystem.directory?(repo)
104
- raise PDK::CLI::ExitWithError, _('Unable to locate git dir "%{gitdir}"') % { gitdir: repo } unless PDK::Util::Filesystem.directory?(File.join(repo, '.git'))
103
+ raise PDK::CLI::ExitWithError, 'Unable to locate git work dir "%{workdir}"' % { workdir: repo } unless PDK::Util::Filesystem.directory?(repo)
104
+ raise PDK::CLI::ExitWithError, 'Unable to locate git dir "%{gitdir}"' % { gitdir: repo } unless PDK::Util::Filesystem.directory?(File.join(repo, '.git'))
105
105
 
106
106
  git('--work-tree', repo, '--git-dir', File.join(repo, '.git'), 'status', '--untracked-files=no', '--porcelain', repo)[:stdout].empty?
107
107
  end
@@ -116,14 +116,14 @@ module PDK
116
116
  unless output[:exit_code].zero?
117
117
  PDK.logger.error output[:stdout]
118
118
  PDK.logger.error output[:stderr]
119
- raise PDK::CLI::ExitWithError, _('Unable to access the template repository "%{repository}"') % {
119
+ raise PDK::CLI::ExitWithError, 'Unable to access the template repository "%{repository}"' % {
120
120
  repository: repo,
121
121
  }
122
122
  end
123
123
 
124
124
  matching_refs = output[:stdout].split(%r{\r?\n}).map { |r| r.split("\t") }
125
125
  matching_ref = matching_refs.find { |_sha, remote_ref| remote_ref == "refs/tags/#{ref}" || remote_ref == "refs/remotes/origin/#{ref}" || remote_ref == "refs/heads/#{ref}" }
126
- raise PDK::CLI::ExitWithError, _('Unable to find a branch or tag named "%{ref}" in %{repo}') % { ref: ref, repo: repo } if matching_ref.nil?
126
+ raise PDK::CLI::ExitWithError, 'Unable to find a branch or tag named "%{ref}" in %{repo}' % { ref: ref, repo: repo } if matching_ref.nil?
127
127
  matching_ref.first
128
128
  end
129
129
 
@@ -22,7 +22,7 @@ module PDK
22
22
 
23
23
  command = PDK::CLI::Exec::Command.new(*argv).tap do |c|
24
24
  c.context = :module
25
- c.add_spinner(_('Examining module contents'))
25
+ c.add_spinner('Examining module contents')
26
26
  end
27
27
 
28
28
  command.execute!
@@ -44,7 +44,7 @@ module PDK
44
44
  JSON.parse(result[:stdout])
45
45
  rescue JSON::ParserError => e
46
46
  PDK.logger.debug(e)
47
- raise RunError, _('Unable to parse puppet-strings output')
47
+ raise RunError, 'Unable to parse puppet-strings output'
48
48
  end
49
49
 
50
50
  # Searches the puppet-strings result to find the definition of the named
@@ -1,4 +1,6 @@
1
1
  require 'pdk'
2
+ require 'json'
3
+ require 'forwardable'
2
4
 
3
5
  module PDK
4
6
  module Util
@@ -38,7 +40,7 @@ module PDK
38
40
  latest = find_gem(Gem::Requirement.create('>= 0'))
39
41
 
40
42
  if latest.nil?
41
- raise ArgumentError, _('Unable to find a Puppet gem in current Ruby environment or from Rubygems.org.')
43
+ raise ArgumentError, 'Unable to find a Puppet gem in current Ruby environment or from Rubygems.org.'
42
44
  end
43
45
 
44
46
  latest
@@ -67,7 +69,7 @@ module PDK
67
69
 
68
70
  PDK.logger.error clone_result[:stdout]
69
71
  PDK.logger.error clone_result[:stderr]
70
- raise PDK::CLI::FatalError, _("Unable to clone git repository from '%{repo}'.") % { repo: DEFAULT_PUPPET_DEV_URL }
72
+ raise PDK::CLI::FatalError, "Unable to clone git repository from '%{repo}'." % { repo: DEFAULT_PUPPET_DEV_URL }
71
73
  end
72
74
 
73
75
  # Fetch Updates from remote repository
@@ -76,7 +78,7 @@ module PDK
76
78
  unless fetch_result[:exit_code].zero?
77
79
  PDK.logger.error fetch_result[:stdout]
78
80
  PDK.logger.error fetch_result[:stderr]
79
- raise PDK::CLI::FatalError, _("Unable to fetch from git remote at '%{repo}'.") % { repo: DEFAULT_PUPPET_DEV_URL }
81
+ raise PDK::CLI::FatalError, "Unable to fetch from git remote at '%{repo}'." % { repo: DEFAULT_PUPPET_DEV_URL }
80
82
  end
81
83
 
82
84
  # Reset local repo to latest
@@ -87,7 +89,7 @@ module PDK
87
89
 
88
90
  PDK.logger.error reset_result[:stdout]
89
91
  PDK.logger.error reset_result[:stderr]
90
- raise PDK::CLI::FatalError, _("Unable to update git repository at '%{cachedir}'.") % { repo: puppet_dev_path }
92
+ raise PDK::CLI::FatalError, "Unable to update git repository at '%{cachedir}'." % { cachedir: puppet_dev_path }
91
93
  end
92
94
 
93
95
  def find_gem_for(version_str)
@@ -104,18 +106,17 @@ module PDK
104
106
  requirement_string = version.approximate_recommendation
105
107
  requirement_string += '.0' unless version.segments.length == 1
106
108
  latest_requirement = Gem::Requirement.create(requirement_string)
107
-
108
109
  latest_available_gem = find_gem(latest_requirement)
109
110
 
110
111
  if latest_available_gem.nil?
111
- raise ArgumentError, _('Unable to find a Puppet gem matching %{requirement}.') % {
112
+ raise ArgumentError, 'Unable to find a Puppet gem matching %{requirement}.' % {
112
113
  requirement: latest_requirement,
113
114
  }
114
115
  end
115
116
 
116
117
  # Only issue this warning if they requested an exact version that isn't available.
117
118
  if version.segments.length == 3
118
- PDK.logger.warn(_('Puppet %{requested_version} is not available, activating %{found_version} instead.') % {
119
+ PDK.logger.warn('Puppet %{requested_version} is not available, activating %{found_version} instead.' % {
119
120
  requested_version: version_str,
120
121
  found_version: latest_available_gem[:gem_version].version,
121
122
  })
@@ -127,22 +128,28 @@ module PDK
127
128
  def from_pe_version(version_str)
128
129
  version = parse_specified_version(version_str)
129
130
 
130
- gem_version = pe_version_map.find do |version_map|
131
- version_map[:requirement].satisfied_by?(version)
132
- end
131
+ # Due to the issue with concurrent ruby in older puppet gems
132
+ # we are locking the pe to puppet version mapping to the latest
133
+ # puppet version that is compatible with the pe version.
134
+ safe_versions = {
135
+ 2023 => '7.23.0',
136
+ 2021 => '7.23.0',
137
+ 2019 => '6.29.0',
138
+ }
133
139
 
140
+ gem_version = safe_versions[version.segments[0]]
134
141
  if gem_version.nil?
135
- raise ArgumentError, _('Unable to map Puppet Enterprise version %{pe_version} to a Puppet version.') % {
142
+ raise ArgumentError, 'Unable to map Puppet Enterprise version %{pe_version} to a Puppet version.' % {
136
143
  pe_version: version_str,
137
144
  }
138
145
  end
139
146
 
140
- PDK.logger.info _('Puppet Enterprise %{pe_version} maps to Puppet %{puppet_version}.') % {
147
+ PDK.logger.info 'Puppet Enterprise %{pe_version} maps to Puppet %{puppet_version}.' % {
141
148
  pe_version: version_str,
142
- puppet_version: gem_version[:gem_version],
149
+ puppet_version: gem_version,
143
150
  }
144
151
 
145
- find_gem_for(gem_version[:gem_version])
152
+ find_gem_for(gem_version)
146
153
  end
147
154
 
148
155
  def from_module_metadata(metadata = nil)
@@ -153,7 +160,7 @@ module PDK
153
160
  metadata_file = PDK::Util.find_upwards('metadata.json')
154
161
 
155
162
  unless metadata_file
156
- PDK.logger.warn _('Unable to determine Puppet version for module: no metadata.json present in module.')
163
+ PDK.logger.warn 'Unable to determine Puppet version for module: no metadata.json present in module.'
157
164
  return
158
165
  end
159
166
 
@@ -179,7 +186,7 @@ module PDK
179
186
  def parse_specified_version(version_str)
180
187
  Gem::Version.new(version_str)
181
188
  rescue ArgumentError
182
- raise ArgumentError, _('%{version} is not a valid version number.') % {
189
+ raise ArgumentError, '%{version} is not a valid version number.' % {
183
190
  version: version_str,
184
191
  }
185
192
  end
@@ -215,7 +222,7 @@ module PDK
215
222
  rescue PDK::Util::VendoredFile::DownloadError => e
216
223
  raise PDK::CLI::FatalError, e.message
217
224
  rescue JSON::ParserError
218
- raise PDK::CLI::FatalError, _('Failed to parse Puppet Enterprise version map file.')
225
+ raise PDK::CLI::FatalError, 'Failed to parse Puppet Enterprise version map file.'
219
226
  end
220
227
 
221
228
  def requirement_from_forge_range(range_str)
@@ -34,7 +34,7 @@ module PDK
34
34
  if versions.key?(version)
35
35
  @active_ruby_version = version
36
36
  else
37
- raise ArgumentError, _('Unknown Ruby version "%{ruby_version}"') % {
37
+ raise ArgumentError, 'Unknown Ruby version "%{ruby_version}"' % {
38
38
  ruby_version: version,
39
39
  }
40
40
  end
@@ -61,10 +61,7 @@ module PDK
61
61
  # PDK::Util::PuppetVersion.find_gem_for('5.5.10')[:ruby_version]
62
62
  #
63
63
  # For using the latest puppet gem:
64
- # PDK::Util::PuppetVersion.latest_available[:ruby_version]
65
- #
66
- # Temporarily lock to Ruby 2.5.x as default until 2.7.x ecosystem is sorted
67
- versions.keys.detect { |v| v =~ %r{^2\.5} }
64
+ PDK::Util::PuppetVersion.latest_available[:ruby_version]
68
65
  else
69
66
  # TODO: may not be a safe assumption that highest available version should be default
70
67
  # WARNING Do NOT use PDK::Util::PuppetVersion.*** methods as it can recurse into this
@@ -48,7 +48,7 @@ module PDK
48
48
  Addressable::URI.parse(opts_or_uri)
49
49
  end
50
50
  rescue Addressable::URI::InvalidURIError
51
- raise PDK::CLI::FatalError, _('PDK::Util::TemplateURI attempted initialization with a non-uri string: {string}') % { string: opts_or_uri }
51
+ raise PDK::CLI::FatalError, 'PDK::Util::TemplateURI attempted initialization with a non-uri string: {string}' % { string: opts_or_uri }
52
52
  end
53
53
  elsif opts_or_uri.is_a?(Addressable::URI)
54
54
  opts_or_uri.dup
@@ -178,7 +178,7 @@ module PDK
178
178
  return url unless Pathname.new(url).relative? && scp_url
179
179
 
180
180
  uri = Addressable::URI.new(scheme: 'ssh', user: scp_url[:user], host: scp_url[:host], path: scp_url[:path])
181
- PDK.logger.warn _('%{scp_uri} appears to be an SCP style URL; it will be converted to an RFC compliant URI: %{rfc_uri}') % {
181
+ PDK.logger.warn '%{scp_uri} appears to be an SCP style URL; it will be converted to an RFC compliant URI: %{rfc_uri}' % {
182
182
  scp_uri: url,
183
183
  rfc_uri: uri.to_s,
184
184
  }
@@ -229,10 +229,10 @@ module PDK
229
229
  default_uri.fragment = default_template_ref(default_template_uri)
230
230
 
231
231
  ary = []
232
- ary << { type: _('--template-url'), uri: explicit_uri, allow_fallback: false } if explicit_url
233
- ary << { type: _('metadata.json'), uri: metadata_uri, allow_fallback: true } if metadata_uri
234
- ary << { type: _('PDK answers'), uri: answers_uri, allow_fallback: true } if answers_uri
235
- ary << { type: _('default'), uri: default_uri, allow_fallback: false }
232
+ ary << { type: '--template-url', uri: explicit_uri, allow_fallback: false } if explicit_url
233
+ ary << { type: 'metadata.json', uri: metadata_uri, allow_fallback: true } if metadata_uri
234
+ ary << { type: 'PDK answers', uri: answers_uri, allow_fallback: true } if answers_uri
235
+ ary << { type: 'default', uri: default_uri, allow_fallback: false }
236
236
  ary
237
237
  end
238
238
 
@@ -256,7 +256,7 @@ module PDK
256
256
  # 4. Leave updating answers/metadata to other code
257
257
  found_template = templates_array.find { |t| valid_template?(t) }
258
258
 
259
- raise PDK::CLI::FatalError, _('Unable to find a valid module template to use.') if found_template.nil?
259
+ raise PDK::CLI::FatalError, 'Unable to find a valid module template to use.' if found_template.nil?
260
260
  found_template[:uri]
261
261
  end
262
262
 
@@ -279,7 +279,7 @@ module PDK
279
279
  end
280
280
 
281
281
  unless template[:allow_fallback]
282
- raise PDK::CLI::FatalError, _('Unable to find a valid template at %{uri}') % {
282
+ raise PDK::CLI::FatalError, 'Unable to find a valid template at %{uri}' % {
283
283
  uri: template[:uri].to_s,
284
284
  }
285
285
  end
@@ -47,7 +47,7 @@ module PDK
47
47
  Timeout::Error,
48
48
  ]
49
49
 
50
- PDK.logger.debug _('%{file_name} was not found in the cache, downloading it from %{url}.') % {
50
+ PDK.logger.debug '%{file_name} was not found in the cache, downloading it from %{url}.' % {
51
51
  file_name: file_name,
52
52
  url: url,
53
53
  }
@@ -61,7 +61,7 @@ module PDK
61
61
  response = http.request(request)
62
62
 
63
63
  unless response.code == '200'
64
- raise DownloadError, _('Unable to download %{url}. %{code}: %{message}.') % {
64
+ raise DownloadError, 'Unable to download %{url}. %{code}: %{message}.' % {
65
65
  url: url,
66
66
  code: response.code,
67
67
  message: response.message,
@@ -70,7 +70,7 @@ module PDK
70
70
 
71
71
  response.body
72
72
  rescue *http_errors => e
73
- raise DownloadError, _('Unable to download %{url}. Check internet connectivity and try again. %{error}') % {
73
+ raise DownloadError, 'Unable to download %{url}. Check internet connectivity and try again. %{error}' % {
74
74
  url: url,
75
75
  error: e,
76
76
  }
@@ -28,7 +28,7 @@ module PDK::Util::Windows::APITypes
28
28
  str = get_bytes(0, char_length * 2).force_encoding('UTF-16LE')
29
29
  str.encode(dst_encoding, str.encoding, **encode_options)
30
30
  rescue StandardError => e
31
- PDK.logger.debug _('Unable to convert value %{string} to encoding %{encoding} due to %{error}') % {
31
+ PDK.logger.debug 'Unable to convert value %{string} to encoding %{encoding} due to %{error}' % {
32
32
  string: str.dump,
33
33
  encoding: dst_encoding,
34
34
  error: e.inspect,
@@ -38,9 +38,8 @@ module PDK::Util::Windows::APITypes
38
38
 
39
39
  def read_arbitrary_wide_string_up_to(max_char_length = 512, null_terminator = :single_null, encode_options = {})
40
40
  unless [:single_null, :double_null].include?(null_terminator)
41
- raise ArgumentError, _(
42
- 'Unable to read wide strings with %{null_terminator} terminal nulls',
43
- ) % { null_terminator: null_terminator }
41
+ raise ArgumentError,
42
+ 'Unable to read wide strings with %{null_terminator} terminal nulls' % { null_terminator: null_terminator }
44
43
  end
45
44
 
46
45
  terminator_width = (null_terminator == :single_null) ? 1 : 2
@@ -12,7 +12,7 @@ module PDK::Util::Windows::File
12
12
  buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
13
13
  FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
14
14
  if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE
15
- raise _('Failed to call GetLongPathName')
15
+ raise 'Failed to call GetLongPathName'
16
16
  end
17
17
 
18
18
  converted = converted_ptr.read_wide_string(buffer_size - 1)
@@ -11,10 +11,7 @@ module PDK::Util::Windows::Process
11
11
  contains_unicode_replacement = ->(string) do
12
12
  return false unless string.include?("\uFFFD")
13
13
 
14
- PDK.logger.warning _(
15
- 'Discarding environment variable %{string} which contains invalid ' \
16
- 'bytes',
17
- ) % { string: string }
14
+ PDK.logger.warning "Discarding environment variable #{string} which contains invalid bytes"
18
15
  true
19
16
  end
20
17
 
@@ -29,24 +26,24 @@ module PDK::Util::Windows::Process
29
26
  ensure
30
27
  if env_ptr && !env_ptr.null?
31
28
  if FreeEnvironmentStringsW(env_ptr) == PDK::Util::Windows::WIN32_FALSE
32
- PDK.logger.debug _('FreeEnvironmentStringsW memory leak')
29
+ PDK.logger.debug 'FreeEnvironmentStringsW memory leak'
33
30
  end
34
31
  end
35
32
  end
36
33
  module_function :environment_hash
37
34
 
38
35
  def set_environment_variable(name, val)
39
- raise ArgumentError, _('Environment variable name must not be nil or empty') if name.nil? || name.empty?
36
+ raise ArgumentError, 'Environment variable name must not be nil or empty' if name.nil? || name.empty?
40
37
 
41
38
  FFI::MemoryPointer.from_string_to_wide_string(name) do |name_ptr|
42
39
  if val.nil?
43
40
  if SetEnvironmentVariableW(name_ptr, FFI::MemoryPointer::NULL) == PDK::Util::Windows::WIN32_FALSE
44
- raise _('Failed to remove environment variable: %{name}') % { name: name }
41
+ raise 'Failed to remove environment variable: %{name}' % { name: name }
45
42
  end
46
43
  else
47
44
  FFI::MemoryPointer.from_string_to_wide_string(val) do |val_ptr|
48
45
  if SetEnvironmentVariableW(name_ptr, val_ptr) == PDK::Util::Windows::WIN32_FALSE
49
- raise _('Failed to set environment variaible: %{name}') % { name: name }
46
+ raise 'Failed to set environment variaible: %{name}' % { name: name }
50
47
  end
51
48
  end
52
49
  end
data/lib/pdk/util.rb CHANGED
@@ -85,7 +85,7 @@ module PDK
85
85
  def canonical_path(path)
86
86
  if Gem.win_platform?
87
87
  unless PDK::Util::Filesystem.exist?(path)
88
- raise PDK::CLI::FatalError, _("Cannot resolve a full path to '%{path}', as it does not currently exist.") % { path: path }
88
+ raise PDK::CLI::FatalError, "Cannot resolve a full path to '%{path}', as it does not currently exist." % { path: path }
89
89
  end
90
90
  PDK::Util::Windows::File.get_long_pathname(path)
91
91
  else
@@ -114,7 +114,7 @@ module PDK
114
114
  module_function :gem_install?
115
115
 
116
116
  def pdk_package_basedir
117
- raise PDK::CLI::FatalError, _('Package basedir requested for non-package install.') unless package_install?
117
+ raise PDK::CLI::FatalError, 'Package basedir requested for non-package install.' unless package_install?
118
118
  require 'pdk/util/version'
119
119
 
120
120
  File.dirname(PDK::Util::Version.version_file)
@@ -19,7 +19,7 @@ module PDK
19
19
  end
20
20
 
21
21
  def spinner_text
22
- _('Checking Puppet Environment settings (%{patterns}).') % {
22
+ 'Checking Puppet Environment settings (%{patterns}).' % {
23
23
  patterns: pattern.join(' '),
24
24
  }
25
25
  end
@@ -31,7 +31,7 @@ module PDK
31
31
  source: name,
32
32
  state: :failure,
33
33
  severity: 'error',
34
- message: _('Could not be read.'),
34
+ message: 'Could not be read.',
35
35
  )
36
36
  return 1
37
37
  end
@@ -46,9 +46,9 @@ module PDK
46
46
  next if ALLOWED_SETTINGS.include?(setting_name)
47
47
  # A hash indicates that the ini file has a section in it.
48
48
  message = if setting_value.is_a?(Hash)
49
- _("Invalid section '%{name}'") % { name: setting_name }
49
+ "Invalid section '%{name}'" % { name: setting_name }
50
50
  else
51
- _("Invalid setting '%{name}'") % { name: setting_name }
51
+ "Invalid setting '%{name}'" % { name: setting_name }
52
52
  end
53
53
 
54
54
  report.add_event(
@@ -68,7 +68,7 @@ module PDK
68
68
  source: name,
69
69
  state: :failure,
70
70
  severity: 'error',
71
- message: _("environment_timeout is set to '%{timeout}' but should be 0, 'unlimited' or not set.") % { timeout: timeout },
71
+ message: "environment_timeout is set to '%{timeout}' but should be 0, 'unlimited' or not set." % { timeout: timeout },
72
72
  )
73
73
  is_valid = false
74
74
  end
@@ -87,7 +87,7 @@ module PDK
87
87
  target_list = target_list.reject { |file| ignore_list.match(file) }
88
88
 
89
89
  if target_list.flatten.empty?
90
- PDK.logger.info(_('Validator \'%{validator}\' skipped for \'%{target}\'. No files matching \'%{pattern}\' found to validate.') % { validator: name, target: target, pattern: pattern })
90
+ PDK.logger.info('Validator \'%{validator}\' skipped for \'%{target}\'. No files matching \'%{pattern}\' found to validate.' % { validator: name, target: target, pattern: pattern })
91
91
 
92
92
  skipped << target
93
93
  end
@@ -121,7 +121,7 @@ module PDK
121
121
  # @see PDK::Validate::Validator.spinner_text
122
122
  # @abstract
123
123
  def spinner_text
124
- _('Running %{name} validator ...') % { name: name }
124
+ 'Running %{name} validator ...' % { name: name }
125
125
  end
126
126
 
127
127
  # @see PDK::Validate::Validator.spinner
@@ -138,11 +138,11 @@ module PDK
138
138
  # @param skipped [Array[String]] The list of skipped targets
139
139
  def process_skipped(report, skipped = [])
140
140
  skipped.each do |skipped_target|
141
- PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).') % { validator: name, target: skipped_target, pattern: pattern })
141
+ PDK.logger.debug('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).' % { validator: name, target: skipped_target, pattern: pattern })
142
142
  report.add_event(
143
143
  file: skipped_target,
144
144
  source: name,
145
- message: _('Target does not contain any files to validate (%{pattern}).') % { pattern: pattern },
145
+ message: 'Target does not contain any files to validate (%{pattern}).' % { pattern: pattern },
146
146
  severity: :info,
147
147
  state: :skipped,
148
148
  )
@@ -154,11 +154,11 @@ module PDK
154
154
  # @param invalid [Array[String]] The list of invalid targets
155
155
  def process_invalid(report, invalid = [])
156
156
  invalid.each do |invalid_target|
157
- PDK.logger.debug(_('%{validator}: Skipped \'%{target}\'. Target file not found.') % { validator: name, target: invalid_target })
157
+ PDK.logger.debug('%{validator}: Skipped \'%{target}\'. Target file not found.' % { validator: name, target: invalid_target })
158
158
  report.add_event(
159
159
  file: invalid_target,
160
160
  source: name,
161
- message: _('File does not exist.'),
161
+ message: 'File does not exist.',
162
162
  severity: :error,
163
163
  state: :error,
164
164
  )
@@ -19,7 +19,7 @@ module PDK
19
19
  end
20
20
 
21
21
  def spinner_text_for_targets(targets)
22
- _('Checking module metadata style (%{targets}).') % {
22
+ 'Checking module metadata style (%{targets}).' % {
23
23
  targets: PDK::Util.targets_relative_to_pwd(targets.flatten).join(' '),
24
24
  }
25
25
  end
@@ -36,7 +36,7 @@ module PDK
36
36
  end
37
37
 
38
38
  def parse_output(report, result, targets)
39
- raise ArgumentError, _('More than 1 target provided to PDK::Validate::MetadataJSONLintValidator.') if targets.count > 1
39
+ raise ArgumentError, 'More than 1 target provided to PDK::Validate::MetadataJSONLintValidator.' if targets.count > 1
40
40
 
41
41
  if result[:stdout].strip.empty?
42
42
  # metadata-json-lint will print nothing if there are no problems with
@@ -13,7 +13,7 @@ module PDK
13
13
  end
14
14
 
15
15
  def spinner_text
16
- _('Checking metadata syntax (%{patterns}).') % {
16
+ 'Checking metadata syntax (%{patterns}).' % {
17
17
  patterns: pattern.join(' '),
18
18
  }
19
19
  end
@@ -40,7 +40,7 @@ module PDK
40
40
  source: name,
41
41
  state: :failure,
42
42
  severity: 'error',
43
- message: _('Could not be read.'),
43
+ message: 'Could not be read.',
44
44
  )
45
45
  return 1
46
46
  end
@@ -37,7 +37,7 @@ module PDK
37
37
  end
38
38
 
39
39
  def spinner_text_for_targets(_targets)
40
- _('Checking Puppet EPP syntax (%{pattern}).') % { pattern: pattern.join(' ') }
40
+ 'Checking Puppet EPP syntax (%{pattern}).' % { pattern: pattern.join(' ') }
41
41
  end
42
42
 
43
43
  def parse_options(targets)
@@ -17,7 +17,7 @@ module PDK
17
17
  end
18
18
 
19
19
  def spinner_text_for_targets(_targets)
20
- _('Checking Puppet manifest style (%{pattern}).') % { pattern: pattern.join(' ') }
20
+ 'Checking Puppet manifest style (%{pattern}).' % { pattern: pattern.join(' ') }
21
21
  end
22
22
 
23
23
  def parse_options(targets)
@@ -0,0 +1,38 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Puppet
6
+ class PuppetPlanSyntaxValidator < PuppetSyntaxValidator
7
+ def name
8
+ 'puppet-plan-syntax'
9
+ end
10
+
11
+ def pattern
12
+ contextual_pattern('plans/**/*.pp')
13
+ end
14
+
15
+ def pattern_ignore; end
16
+
17
+ def spinner_text_for_targets(_targets)
18
+ 'Checking Puppet plan syntax (%{pattern}).' % { pattern: pattern.join(' ') }
19
+ end
20
+
21
+ def parse_options(targets)
22
+ # Due to PDK-1266 we need to run `puppet parser validate` with an empty
23
+ # modulepath. On *nix, Ruby treats `/dev/null` as an empty directory
24
+ # however it doesn't do so with `NUL` on Windows. The workaround for
25
+ # this to ensure consistent behaviour is to create an empty temporary
26
+ # directory and use that as the modulepath.
27
+ ['parser', 'validate', '--tasks', '--config', null_file, '--modulepath', validate_tmpdir].concat(targets)
28
+ end
29
+
30
+ def validate_tmpdir
31
+ require 'tmpdir'
32
+
33
+ @validate_tmpdir ||= Dir.mktmpdir('puppet-plan-parser-validate')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -41,7 +41,7 @@ module PDK
41
41
  end
42
42
 
43
43
  def spinner_text_for_targets(_targets)
44
- _('Checking Puppet manifest syntax (%{pattern}).') % { pattern: pattern.join(' ') }
44
+ 'Checking Puppet manifest syntax (%{pattern}).' % { pattern: pattern.join(' ') }
45
45
  end
46
46
 
47
47
  def parse_options(targets)
@@ -11,6 +11,7 @@ module PDK
11
11
  def validators
12
12
  [
13
13
  PuppetSyntaxValidator,
14
+ PuppetPlanSyntaxValidator,
14
15
  PuppetLintValidator,
15
16
  PuppetEPPValidator,
16
17
  ].freeze
@@ -25,7 +25,7 @@ module PDK
25
25
  end
26
26
 
27
27
  def spinner_text_for_targets(_targets)
28
- _('Checking Ruby code style (%{pattern}).') % { pattern: pattern }
28
+ 'Checking Ruby code style (%{pattern}).' % { pattern: pattern }
29
29
  end
30
30
 
31
31
  def parse_options(targets)
@@ -15,7 +15,7 @@ module PDK
15
15
  end
16
16
 
17
17
  def spinner_text
18
- _('Checking task metadata style (%{pattern}).') % {
18
+ 'Checking task metadata style (%{pattern}).' % {
19
19
  pattern: pattern.join(' '),
20
20
  }
21
21
  end
@@ -29,7 +29,7 @@ module PDK
29
29
  rescue PDK::Util::VendoredFile::DownloadError => e
30
30
  raise PDK::CLI::FatalError, e.message
31
31
  rescue JSON::ParserError
32
- raise PDK::CLI::FatalError, _('Failed to parse Task Metadata Schema file.')
32
+ raise PDK::CLI::FatalError, 'Failed to parse Task Metadata Schema file.'
33
33
  end
34
34
 
35
35
  def validate_target(report, target)
@@ -39,7 +39,7 @@ module PDK
39
39
  source: name,
40
40
  state: :failure,
41
41
  severity: 'error',
42
- message: _('Could not be read.'),
42
+ message: 'Could not be read.',
43
43
  )
44
44
  return 1
45
45
  end
@@ -54,7 +54,7 @@ module PDK
54
54
  begin
55
55
  errors = JSON::Validator.fully_validate(schema_file, PDK::Util::Filesystem.read_file(target)) || []
56
56
  rescue JSON::Schema::SchemaError => e
57
- raise PDK::CLI::FatalError, _('Unable to validate Task Metadata. %{error}.') % { error: e.message }
57
+ raise PDK::CLI::FatalError, 'Unable to validate Task Metadata. %{error}.' % { error: e.message }
58
58
  end
59
59
 
60
60
  if errors.empty?
@@ -4,10 +4,7 @@ module PDK
4
4
  module Validate
5
5
  module Tasks
6
6
  class TasksNameValidator < InternalRubyValidator
7
- INVALID_TASK_MSG = _(
8
- 'Invalid task name. Task names must start with a lowercase letter ' \
9
- 'and can only contain lowercase letters, numbers, and underscores.',
10
- )
7
+ INVALID_TASK_MSG = 'Invalid task name. Task names must start with a lowercase letter and can only contain lowercase letters, numbers, and underscores.'.freeze
11
8
 
12
9
  def name
13
10
  'task-name'
@@ -18,7 +15,7 @@ module PDK
18
15
  end
19
16
 
20
17
  def spinner_text
21
- _('Checking task names (%{pattern}).') % {
18
+ 'Checking task names (%{pattern}).' % {
22
19
  pattern: pattern.join(' '),
23
20
  }
24
21
  end