pdk 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 9b3de42650b7bdd05b69c6bb9ee6b0150f628c6e6eb9fb22ff938fcf095cd6f2
4
- data.tar.gz: 13c89a19fb58166b235d75259d72e391e66cf3a86269cbaf8257bfdd69761b64
2
+ SHA1:
3
+ metadata.gz: 9ccc8605ca4505c8e57540dafa991de341002352
4
+ data.tar.gz: b6f8526bbc058be672452fc714b2647d38dbd1a8
5
5
  SHA512:
6
- metadata.gz: 150e3a0047aaca9f19ee203bda23b07e49b177b91f266bfd63a159bac0772c1888a161a671b7b57d3eccbacbad5aec21f794d4eccd175a0ef0717714d322e81c
7
- data.tar.gz: a146f216b223a1f93c362dd646d145cdc6149753981ec266fc78f72b181dd34e1279775d317d9eae5e801e6d94d1094f12f07234e2340cadda675774797966a4
6
+ metadata.gz: 9479fdc94261aa410a8ca51c6752386bc24379ffc840e1910c930a830d47b5d544cf8b548a5a06bf44b31239c5d19b60f16c7f0eb224d5b3e1d1afda8d30d056
7
+ data.tar.gz: 20e678cb7755ad127c93e0429a944a7407399e4b42a24566ae0aad02b05ba87b13f849929d3e54dcf80d30a8d0148c92ecc07e11be6582b662ccc458fa2ad7b3
@@ -4,6 +4,39 @@ All changes to this repo will be documented in this file.
4
4
  See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) for a high-level summary.
5
5
 
6
6
 
7
+ ## [v1.13.0](https://github.com/puppetlabs/pdk/tree/v1.13.0) (2019-08-29)
8
+ [Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.12.0...v1.13.0)
9
+
10
+ **Implemented enhancements:**
11
+
12
+ - Don't buffer output from bundle commands [\#364](https://github.com/puppetlabs/pdk/issues/364)
13
+ - Provide official docker image with pdk [\#336](https://github.com/puppetlabs/pdk/issues/336)
14
+ - \(PDK-1175\) pdk new unit\_test [\#735](https://github.com/puppetlabs/pdk/pull/735) ([rodjek](https://github.com/rodjek))
15
+ - \(PDK-871\) Relax dependencies on tty-\* gems [\#730](https://github.com/puppetlabs/pdk/pull/730) ([rodjek](https://github.com/rodjek))
16
+ - \(PDK-1363\) Apply init templates during module convert [\#729](https://github.com/puppetlabs/pdk/pull/729) ([rodjek](https://github.com/rodjek))
17
+ - \(PDK-1107\) Add pdk config get CLI command [\#715](https://github.com/puppetlabs/pdk/pull/715) ([glennsarti](https://github.com/glennsarti))
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Problem running "pdk validate manifests/" with pdk 1.12.0 [\#722](https://github.com/puppetlabs/pdk/issues/722)
22
+ - Windows MSI installer fails with PDK 1.12.0 [\#721](https://github.com/puppetlabs/pdk/issues/721)
23
+ - Handle deleted template files for new module [\#725](https://github.com/puppetlabs/pdk/pull/725) ([seanmil](https://github.com/seanmil))
24
+ - \(GH-722\) Do not emit nil targets for validators against a directory [\#724](https://github.com/puppetlabs/pdk/pull/724) ([glennsarti](https://github.com/glennsarti))
25
+ - \(maint\) avoid interfering with local ruby configs [\#86](https://github.com/puppetlabs/pdk/pull/86) ([DavidS](https://github.com/DavidS))
26
+
27
+ **Merged pull requests:**
28
+
29
+ - \(FIXUP\) Remove nokogiri version pin from package-testing [\#738](https://github.com/puppetlabs/pdk/pull/738) ([scotje](https://github.com/scotje))
30
+ - \(PDK-1464\) Update nokogiri due to CVE-2019-5477 [\#733](https://github.com/puppetlabs/pdk/pull/733) ([glennsarti](https://github.com/glennsarti))
31
+ - \(PDK-1465\) Remove net-ssh from gemspec [\#732](https://github.com/puppetlabs/pdk/pull/732) ([glennsarti](https://github.com/glennsarti))
32
+ - \(PDK-1384\) Updates to be compatible with latest Cri [\#731](https://github.com/puppetlabs/pdk/pull/731) ([scotje](https://github.com/scotje))
33
+ - \(docs\) minor fixups to README [\#727](https://github.com/puppetlabs/pdk/pull/727) ([jbondpdx](https://github.com/jbondpdx))
34
+ - \(PDK-1107\) Config fetch and \[\] should have no side effects [\#726](https://github.com/puppetlabs/pdk/pull/726) ([glennsarti](https://github.com/glennsarti))
35
+ - \(MAINT\) Bump version to 1.13.0.pre [\#720](https://github.com/puppetlabs/pdk/pull/720) ([scotje](https://github.com/scotje))
36
+ - \(MAINT\) Allow use of RSPEC\_PATTERN env var when running package tests [\#719](https://github.com/puppetlabs/pdk/pull/719) ([scotje](https://github.com/scotje))
37
+ - \(maint\) Remove Hipchat notifications [\#716](https://github.com/puppetlabs/pdk/pull/716) ([glennsarti](https://github.com/glennsarti))
38
+ - \(PDK-1432\) Autogenerate PowerShell modules from code [\#701](https://github.com/puppetlabs/pdk/pull/701) ([glennsarti](https://github.com/glennsarti))
39
+
7
40
  ## [v1.12.0](https://github.com/puppetlabs/pdk/tree/v1.12.0) (2019-07-31)
8
41
  [Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.11.1...v1.12.0)
9
42
 
data/README.md CHANGED
@@ -107,13 +107,11 @@ This command runs all available unit tests.
107
107
 
108
108
  ### `pdk bundle` command
109
109
 
110
- This command executes arbitrary commands in a bundler context within the module you're currently working on. Arguments to this command are passed straight through to bundler. This command is experimental and can lead to errors that can't be resolved by the pdk itself.
111
-
112
- Note that for most uses, you must use the `--` to separate bundler options from pdk options. Compare the following two commands:
110
+ This command executes arbitrary commands in a bundler context within the module you're currently working on. Arguments to this command are passed straight through to bundler. This command is experimental and can lead to errors that can't be resolved by PDK itself.
113
111
 
114
112
  ## Module Compatibility
115
113
 
116
- **PDK Version Compatibility:** Modules created with PDK version validate against and run on all Puppet and Ruby version combinations currently under maintenance (see https://docs.puppet.com/puppet/latest/about_agent.html and https://puppet.com/misc/puppet-enterprise-lifecycle)
114
+ **PDK Version Compatibility:** Modules created with PDK validate against and run on all Puppet and Ruby version combinations currently under maintenance (see https://docs.puppet.com/puppet/latest/about_agent.html and https://puppet.com/misc/puppet-enterprise-lifecycle)
117
115
 
118
116
  ## Contributing
119
117
 
@@ -143,6 +143,7 @@ module PDK::CLI
143
143
 
144
144
  require 'pdk/cli/bundle'
145
145
  require 'pdk/cli/build'
146
+ require 'pdk/cli/config'
146
147
  require 'pdk/cli/convert'
147
148
  require 'pdk/cli/new'
148
149
  require 'pdk/cli/test'
@@ -0,0 +1,20 @@
1
+ module PDK::CLI
2
+ @config_cmd = @base_cmd.define_command do
3
+ name 'config'
4
+ usage _('config [subcommand] [options]')
5
+ summary _('Configure the Puppet Development Kit.')
6
+ default_subcommand 'help'
7
+
8
+ run do |_opts, args, _cmd|
9
+ if args == ['help']
10
+ PDK::CLI.run(%w[config --help])
11
+ exit 0
12
+ end
13
+
14
+ PDK::CLI.run(%w[config help]) if args.empty?
15
+ end
16
+ end
17
+ @config_cmd.add_command Cri::Command.new_basic_help
18
+ end
19
+
20
+ require 'pdk/cli/config/get'
@@ -0,0 +1,24 @@
1
+ module PDK::CLI
2
+ @config_get_cmd = @config_cmd.define_command do
3
+ name 'get'
4
+ usage _('config get [name]')
5
+ summary _('Retrieve the configuration for <name>. If not specified, retrieve all configuration settings')
6
+
7
+ run do |_opts, args, _cmd|
8
+ item_name = args[0]
9
+ resolved_config = PDK.config.resolve(item_name)
10
+ # If the user wanted to know a setting but it doesn't exist, raise an error
11
+ if resolved_config.empty? && !item_name.nil?
12
+ PDK.logger.error(_("Configuration item '%{name}' does not exist") % { name: item_name })
13
+ exit 1
14
+ end
15
+ # If the user requested a setting and it's the only one resolved, then just output the value
16
+ if resolved_config.count == 1 && resolved_config.keys[0] == item_name
17
+ puts _('%{value}') % { value: resolved_config.values[0] }
18
+ exit 0
19
+ end
20
+ # Otherwise just output everything
21
+ resolved_config.keys.sort.each { |key| puts _('%{name}=%{value}') % { name: key, value: resolved_config[key] } }
22
+ end
23
+ end
24
+ end
@@ -2,12 +2,12 @@ require 'bundler'
2
2
  require 'childprocess'
3
3
  require 'English'
4
4
  require 'tempfile'
5
- require 'tty-spinner'
6
5
  require 'tty-which'
7
6
 
8
7
  require 'pdk/util'
9
8
  require 'pdk/util/git'
10
9
  require 'pdk/util/ruby_version'
10
+ require 'pdk/cli/util/spinner'
11
11
 
12
12
  module PDK
13
13
  module CLI
@@ -2,12 +2,12 @@ require 'bundler'
2
2
  require 'childprocess'
3
3
  require 'English'
4
4
  require 'tempfile'
5
- require 'tty-spinner'
6
5
  require 'tty-which'
7
6
 
8
7
  require 'pdk/util'
9
8
  require 'pdk/util/git'
10
9
  require 'pdk/util/ruby_version'
10
+ require 'pdk/cli/util/spinner'
11
11
 
12
12
  module PDK
13
13
  module CLI
@@ -1,7 +1,7 @@
1
- require 'tty-spinner'
2
1
  require 'tty-which'
3
2
 
4
3
  require 'pdk/util'
4
+ require 'pdk/cli/util/spinner'
5
5
 
6
6
  module PDK
7
7
  module CLI
@@ -16,3 +16,4 @@ require 'pdk/cli/new/module'
16
16
  require 'pdk/cli/new/provider'
17
17
  require 'pdk/cli/new/task'
18
18
  require 'pdk/cli/new/transport'
19
+ require 'pdk/cli/new/unit_test'
@@ -0,0 +1,49 @@
1
+ module PDK::CLI
2
+ @new_define_cmd = @new_cmd.define_command do
3
+ name 'unit_test'
4
+ usage _('unit_test [options] <name>')
5
+ summary _('(Experimental) Create a new unit test for the object named <name>')
6
+ description _(<<-EOF
7
+ Generate a new rspec-puppet unit test for an existing class or defined type.
8
+
9
+ Please note, this is an experimental feature; the functionality and UX is
10
+ subject to change in future releases.
11
+ EOF
12
+ )
13
+ PDK::CLI.puppet_version_options(self)
14
+ PDK::CLI.puppet_dev_option(self)
15
+
16
+ run do |opts, args, _cmd|
17
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
18
+ PDK::CLI::Util.ensure_in_module!(
19
+ message: _('Unit tests can only be created from inside a valid module directory.'),
20
+ log_level: :info,
21
+ )
22
+
23
+ object_name = args[0]
24
+ module_dir = Dir.pwd
25
+
26
+ if object_name.nil? || object_name.empty?
27
+ puts command.help
28
+ exit 1
29
+ end
30
+
31
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
32
+ PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
33
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
34
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
35
+
36
+ begin
37
+ generator, obj = PDK::Util::PuppetStrings.find_object(object_name)
38
+
39
+ PDK::CLI::Util.analytics_screen_view('new_unit_test', opts)
40
+
41
+ generator.new(module_dir, obj['name'], opts.merge(spec_only: true)).run
42
+ rescue PDK::Util::PuppetStrings::NoObjectError
43
+ raise PDK::CLI::ExitWithError, _('Unable to find anything called "%{object}" to generate unit tests for.') % { object: object_name }
44
+ rescue PDK::Util::PuppetStrings::NoGeneratorError => e
45
+ raise PDK::CLI::ExitWithError, _('PDK does not support generating unit tests for "%{object_type}" objects.') % { object_type: e.message }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -4,6 +4,8 @@ module PDK
4
4
  module CLI
5
5
  module Util
6
6
  class Interview < TTY::Prompt::AnswersCollector
7
+ READER = defined?(TTY::Reader) ? TTY::Reader : TTY::Prompt::Reader
8
+
7
9
  def pastel
8
10
  @pastel ||= Pastel.new
9
11
  end
@@ -60,7 +62,7 @@ module PDK
60
62
  @prompt.puts ''
61
63
  end
62
64
  @answers
63
- rescue TTY::Prompt::Reader::InputInterrupt
65
+ rescue READER::InputInterrupt
64
66
  nil
65
67
  end
66
68
  end
@@ -0,0 +1,13 @@
1
+ require 'tty-spinner'
2
+
3
+ require 'pdk/cli/util'
4
+
5
+ # Replace the built-in tty check in tty-spinner with our own implementation
6
+ # that allows us to mock the behaviour during acceptance tests.
7
+ module TTY
8
+ class Spinner
9
+ def tty?
10
+ PDK::CLI::Util.interactive?
11
+ end
12
+ end
13
+ end
@@ -15,7 +15,7 @@ module PDK
15
15
  @user ||= PDK::Config::JSON.new('user', file: PDK::Config.user_config_path) do
16
16
  mount :module_defaults, PDK::Config::JSON.new(file: PDK.answers.answer_file_path)
17
17
 
18
- mount :analytics, PDK::Config::YAML.new(file: PDK::Config.analytics_config_path) do
18
+ mount :analytics, PDK::Config::YAML.new(file: PDK::Config.analytics_config_path, persistent_defaults: true) do
19
19
  value :disabled do
20
20
  validate PDK::Config::Validator.boolean
21
21
  default_to { PDK::Config.bolt_analytics_config.fetch('disabled', true) }
@@ -33,6 +33,14 @@ module PDK
33
33
  end
34
34
  end
35
35
 
36
+ # Resolves *all* filtered settings from all namespaces
37
+ #
38
+ # @param filter [String] Only resolve setting names which match the filter. See PDK::Config::Namespace.be_resolved? for matching rules
39
+ # @return [Hash{String => Object}] All resolved settings for example {'user.module_defaults.author' => 'johndoe'}
40
+ def resolve(filter = nil)
41
+ user.resolve(filter)
42
+ end
43
+
36
44
  def self.bolt_analytics_config
37
45
  file = File.expand_path('~/.puppetlabs/bolt/analytics.yaml')
38
46
  PDK::Config::YAML.new(file: file)
@@ -20,12 +20,16 @@ module PDK
20
20
  # contents of the namespace (defaults to nil).
21
21
  # @option params [self] :parent the parent {self} that this namespace is
22
22
  # a child of (defaults to nil).
23
+ # @option params [self] :persistent_defaults whether default values should be persisted
24
+ # to disk when evaluated. By default they are not persisted to disk. This is typically
25
+ # used for settings which a randomly generated, instead of being deterministic, e.g. analytics user-id
23
26
  # @param block [Proc] a block that is evaluated within the new instance.
24
- def initialize(name = nil, file: nil, parent: nil, &block)
27
+ def initialize(name = nil, file: nil, parent: nil, persistent_defaults: false, &block)
25
28
  @file = File.expand_path(file) unless file.nil?
26
29
  @values = {}
27
30
  @name = name.to_s
28
31
  @parent = parent
32
+ @persistent_defaults = persistent_defaults
29
33
 
30
34
  instance_eval(&block) if block_given?
31
35
  end
@@ -104,11 +108,6 @@ module PDK
104
108
  data.fetch(key.to_s, default_value)
105
109
  end
106
110
 
107
- # Set the value of the named key.
108
- #
109
- # If the key has been pre-configured with {#value}, then the value of the
110
- # key will be validated against any validators that have been configured.
111
- #
112
111
  # After the value has been set in memory, the value will then be
113
112
  # persisted to disk.
114
113
  #
@@ -117,9 +116,8 @@ module PDK
117
116
  #
118
117
  # @return [nil]
119
118
  def []=(key, value)
120
- @values[key.to_s].validate!([name, key.to_s].join('.'), value) if @values.key?(key.to_s)
121
-
122
- data[key.to_s] = value
119
+ set_volatile_value(key, value)
120
+ # Persist the change
123
121
  save_data
124
122
  end
125
123
 
@@ -143,6 +141,28 @@ module PDK
143
141
  end
144
142
  end
145
143
 
144
+ # Resolves all filtered settings, including child namespaces, fully namespaced and filling in default values.
145
+ #
146
+ # @param filter [String] Only resolve setting names which match the filter. See #be_resolved? for matching rules
147
+ # @return [Hash{String => Object}] All resolved settings for example {'user.module_defaults.author' => 'johndoe'}
148
+ def resolve(filter = nil)
149
+ # Explicitly force values to be loaded if they have not already
150
+ # done so. This will not cause them to be persisted to disk
151
+ (@values.keys - data.keys).each { |key_name| self[key_name] }
152
+ resolved = {}
153
+ data.each do |data_name, obj|
154
+ case obj
155
+ when PDK::Config::Namespace
156
+ # Query the child namespace
157
+ resolved.merge!(obj.resolve(filter))
158
+ else
159
+ setting_name = [name, data_name.to_s].join('.')
160
+ resolved[setting_name] = self[data_name] if be_resolved?(setting_name, filter)
161
+ end
162
+ end
163
+ resolved
164
+ end
165
+
146
166
  # @return [Boolean] true if the namespace has a parent, otherwise false.
147
167
  def child_namespace?
148
168
  !parent.nil?
@@ -173,6 +193,21 @@ module PDK
173
193
 
174
194
  private
175
195
 
196
+ # Determines whether a setting name should be resolved using the filter
197
+ # Returns true when filter is nil.
198
+ # Returns true if the filter is exactly the same name as the setting.
199
+ # Returns true if the name is a sub-key of the filter e.g.
200
+ # Given a filter of user.module_defaults, `user.module_defaults.author` will return true, but `user.analytics.disabled` will return false.
201
+ #
202
+ # @param name [String] The setting name to test.
203
+ # @param filter [String] The filter used to test on the name.
204
+ # @return [Boolean] Whether the name passes the filter.
205
+ def be_resolved?(name, filter = nil)
206
+ return true if filter.nil? # If we're not filtering, this value should always be resolved
207
+ return true if name == filter # If it's exactly the same name then it should be resolved
208
+ name.start_with?(filter + '.') # If name is a subkey of the filter then it should be resolved
209
+ end
210
+
176
211
  # @abstract Subclass and override {#parse_data} to implement parsing logic
177
212
  # for a particular config file format.
178
213
  #
@@ -185,6 +220,19 @@ module PDK
185
220
  {}
186
221
  end
187
222
 
223
+ # Set the value of the named key.
224
+ #
225
+ # If the key has been pre-configured with {#value}, then the value of the
226
+ # key will be validated against any validators that have been configured.
227
+ #
228
+ # @param key [String,Symbol] the name of the configuration value.
229
+ # @param value [Object] the value of the configuration value.
230
+ def set_volatile_value(key, value)
231
+ @values[key.to_s].validate!([name, key.to_s].join('.'), value) if @values.key?(key.to_s)
232
+
233
+ data[key.to_s] = value
234
+ end
235
+
188
236
  # Read the file associated with the namespace.
189
237
  #
190
238
  # @raise [PDK::Config::LoadError] if the file is removed during read.
@@ -228,7 +276,7 @@ module PDK
228
276
  def save_data
229
277
  return if file.nil?
230
278
 
231
- FileUtils.mkdir_p(File.dirname(file))
279
+ PDK::Util::Filesystem.mkdir_p(File.dirname(file))
232
280
 
233
281
  PDK::Util::Filesystem.write_file(file, serialize_data(to_h))
234
282
  rescue Errno::EACCES
@@ -243,24 +291,27 @@ module PDK
243
291
  #
244
292
  # @return [Hash<String => Object>] the contents of the namespace.
245
293
  def data
294
+ # It's possible for parse_data to return nil, so just return an empty hash
246
295
  @data ||= parse_data(load_data, file).tap do |h|
247
- h.default_proc = default_config_value
248
- end
296
+ h.default_proc = default_config_value unless h.nil?
297
+ end || {}
249
298
  end
250
299
 
251
300
  # The default behaviour of the namespace when the requested value does
252
301
  # not exist.
253
302
  #
254
303
  # If the value has been pre-configured with {#value} to have a default
255
- # value, resolve the default value and set it in the namespace
256
- # (triggering a call to {#save_data}. Otherwise, set the value to a new
257
- # Hash to allow for arbitrary level of nested values.
304
+ # value, resolve the default value and set it in the namespace and optionally
305
+ # save the new default.
306
+ # Otherwise, set the value to a new Hash to allow for arbitrary level of nested values.
258
307
  #
259
308
  # @return [Proc] suitable for use by {Hash#default_proc}.
260
309
  def default_config_value
261
310
  ->(hash, key) do
262
311
  if @values.key?(key) && @values[key].default?
263
- self[key] = @values[key].default
312
+ set_volatile_value(key, @values[key].default)
313
+ save_data if @persistent_defaults
314
+ hash[key]
264
315
  else
265
316
  hash[key] = {}.tap do |h|
266
317
  h.default_proc = default_config_value
@@ -8,5 +8,13 @@ require 'pdk/module/metadata'
8
8
  require 'pdk/module/templatedir'
9
9
 
10
10
  module PDK
11
- module Generate; end
11
+ module Generate
12
+ GENERATORS = [
13
+ PDK::Generate::DefinedType,
14
+ PDK::Generate::Provider,
15
+ PDK::Generate::PuppetClass,
16
+ PDK::Generate::Task,
17
+ PDK::Generate::Transport,
18
+ ].freeze
19
+ end
12
20
  end