pdk 3.0.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -1
  3. data/lib/pdk/cli/build.rb +6 -5
  4. data/lib/pdk/cli/bundle.rb +0 -2
  5. data/lib/pdk/cli/console.rb +0 -2
  6. data/lib/pdk/cli/convert.rb +3 -3
  7. data/lib/pdk/cli/env.rb +0 -2
  8. data/lib/pdk/cli/exec/command.rb +0 -2
  9. data/lib/pdk/cli/new/class.rb +0 -2
  10. data/lib/pdk/cli/new/defined_type.rb +0 -2
  11. data/lib/pdk/cli/new/fact.rb +0 -2
  12. data/lib/pdk/cli/new/function.rb +0 -2
  13. data/lib/pdk/cli/new/module.rb +0 -2
  14. data/lib/pdk/cli/new/provider.rb +0 -2
  15. data/lib/pdk/cli/new/task.rb +0 -2
  16. data/lib/pdk/cli/new/test.rb +0 -2
  17. data/lib/pdk/cli/release/prep.rb +0 -2
  18. data/lib/pdk/cli/release/publish.rb +0 -2
  19. data/lib/pdk/cli/release.rb +0 -9
  20. data/lib/pdk/cli/test/unit.rb +0 -2
  21. data/lib/pdk/cli/update.rb +3 -3
  22. data/lib/pdk/cli/util.rb +0 -38
  23. data/lib/pdk/cli/validate.rb +0 -7
  24. data/lib/pdk/cli.rb +0 -2
  25. data/lib/pdk/config/namespace.rb +3 -3
  26. data/lib/pdk/config/setting.rb +3 -3
  27. data/lib/pdk/config.rb +0 -80
  28. data/lib/pdk/module/convert.rb +8 -3
  29. data/lib/pdk/module/metadata.rb +18 -10
  30. data/lib/pdk/module/release.rb +9 -6
  31. data/lib/pdk/module/update_manager.rb +29 -3
  32. data/lib/pdk/report/event.rb +1 -1
  33. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +10 -13
  34. data/lib/pdk/template/renderer/v1/renderer.rb +3 -1
  35. data/lib/pdk/template.rb +0 -3
  36. data/lib/pdk/tests/unit.rb +3 -3
  37. data/lib/pdk/util/filesystem.rb +10 -0
  38. data/lib/pdk/util.rb +1 -0
  39. data/lib/pdk/version.rb +2 -2
  40. data/lib/pdk.rb +0 -14
  41. metadata +63 -98
  42. data/lib/pdk/analytics/client/google_analytics.rb +0 -141
  43. data/lib/pdk/analytics/client/noop.rb +0 -25
  44. data/lib/pdk/analytics/util.rb +0 -18
  45. data/lib/pdk/analytics.rb +0 -30
  46. data/lib/pdk/config/analytics_schema.json +0 -26
  47. data/lib/pdk/module/build.rb +0 -302
  48. data/lib/pdk/monkey_patches.rb +0 -268
@@ -9,7 +9,7 @@ module PDK
9
9
  'RedHat based Linux' => [
10
10
  {
11
11
  'operatingsystem' => 'CentOS',
12
- 'operatingsystemrelease' => ['7']
12
+ 'operatingsystemrelease' => ['7', '8', '9']
13
13
  },
14
14
  {
15
15
  'operatingsystem' => 'OracleLinux',
@@ -17,30 +17,38 @@ module PDK
17
17
  },
18
18
  {
19
19
  'operatingsystem' => 'RedHat',
20
- 'operatingsystemrelease' => ['8']
20
+ 'operatingsystemrelease' => ['7', '8', '9']
21
21
  },
22
22
  {
23
23
  'operatingsystem' => 'Scientific',
24
24
  'operatingsystemrelease' => ['7']
25
+ },
26
+ {
27
+ 'operatingsystem' => 'Rocky',
28
+ 'operatingsystemrelease' => ['8']
29
+ },
30
+ {
31
+ 'operatingsystem' => 'AlmaLinux',
32
+ 'operatingsystemrelease' => ['8']
25
33
  }
26
34
  ],
27
35
  'Debian based Linux' => [
28
36
  {
29
37
  'operatingsystem' => 'Debian',
30
- 'operatingsystemrelease' => ['10']
38
+ 'operatingsystemrelease' => ['10', '11', '12']
31
39
  },
32
40
  {
33
41
  'operatingsystem' => 'Ubuntu',
34
- 'operatingsystemrelease' => ['18.04']
42
+ 'operatingsystemrelease' => ['18.04', '20.04', '22.04']
35
43
  }
36
44
  ],
37
45
  'Fedora' => {
38
46
  'operatingsystem' => 'Fedora',
39
- 'operatingsystemrelease' => ['29']
47
+ 'operatingsystemrelease' => ['40']
40
48
  },
41
49
  'OSX' => {
42
50
  'operatingsystem' => 'Darwin',
43
- 'operatingsystemrelease' => ['16']
51
+ 'operatingsystemrelease' => ['21', '22', '23']
44
52
  },
45
53
  'SLES' => {
46
54
  'operatingsystem' => 'SLES',
@@ -52,11 +60,11 @@ module PDK
52
60
  },
53
61
  'Windows' => {
54
62
  'operatingsystem' => 'windows',
55
- 'operatingsystemrelease' => ['2019', '10']
63
+ 'operatingsystemrelease' => ['2019', '2022', '10', '11']
56
64
  },
57
65
  'AIX' => {
58
66
  'operatingsystem' => 'AIX',
59
- 'operatingsystemrelease' => ['6.1', '7.1', '7.2']
67
+ 'operatingsystemrelease' => ['7.2', '7.3']
60
68
  }
61
69
  }.freeze
62
70
 
@@ -117,7 +125,7 @@ module PDK
117
125
  def to_json(*_args)
118
126
  require 'json'
119
127
 
120
- JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? }) # rubocop:disable Style/CollectionCompact
128
+ JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? })
121
129
  end
122
130
 
123
131
  def write!(path)
@@ -162,7 +170,7 @@ module PDK
162
170
 
163
171
  # Do basic validation and parsing of the name parameter.
164
172
  def process_name(data)
165
- validate_name(data['name'])
173
+ validate_name(data['name']) unless PDK.context.is_a?(PDK::Context::ControlRepo)
166
174
  author, modname = data['name'].split(%r{[-/]}, 2)
167
175
  data['name'] = [author, modname].join('-')
168
176
 
@@ -1,5 +1,6 @@
1
1
  require 'pdk'
2
2
  require 'uri'
3
+ require 'puppet/modulebuilder'
3
4
 
4
5
  module PDK
5
6
  module Module
@@ -77,7 +78,7 @@ module PDK
77
78
  # Use the default as a last resort
78
79
  package_file = default_package_filename if package_file.nil?
79
80
  else
80
- package_file = run_build(options)
81
+ package_file = run_build
81
82
  end
82
83
 
83
84
  run_publish(options.dup, package_file) unless skip_publish?
@@ -95,7 +96,7 @@ module PDK
95
96
  def default_package_filename
96
97
  return @default_tarball_filename unless @default_tarball_filename.nil?
97
98
 
98
- builder = PDK::Module::Build.new(module_dir: module_path)
99
+ builder = Puppet::Modulebuilder::Builder.new(module_path, nil, PDK.logger)
99
100
  @default_tarball_filename = builder.package_file
100
101
  end
101
102
 
@@ -135,8 +136,11 @@ module PDK
135
136
  end
136
137
 
137
138
  # @return [String] Path to the built tarball
138
- def run_build(opts)
139
- PDK::Module::Build.invoke(opts.dup)
139
+ def run_build
140
+ module_dir = PDK::Util::Filesystem.expand_path(module_path || Dir.pwd)
141
+ target_dir = File.join(module_dir, 'pkg')
142
+ builder = Puppet::Modulebuilder::Builder.new(module_dir, target_dir, PDK.logger)
143
+ builder.build
140
144
  end
141
145
 
142
146
  def run_publish(_opts, tarball_path)
@@ -238,8 +242,7 @@ module PDK
238
242
  def pdk_compatible?
239
243
  return @pdk_compatible unless @pdk_compatible.nil?
240
244
 
241
- builder = PDK::Module::Build.new(module_dir: module_path)
242
- @pdk_compatible = builder.module_pdk_compatible?
245
+ @pdk_compatible = PDK::Util.module_pdk_compatible?(module_path)
243
246
  end
244
247
  # :nocov:
245
248
 
@@ -11,6 +11,7 @@ module PDK
11
11
  @modified_files = Set.new
12
12
  @added_files = Set.new
13
13
  @removed_files = Set.new
14
+ @executable_files = Set.new
14
15
  @diff_cache = {}
15
16
  end
16
17
 
@@ -37,6 +38,13 @@ module PDK
37
38
  @removed_files << path
38
39
  end
39
40
 
41
+ # Store a pending file execute mode change.
42
+ #
43
+ # @param path [String] The path to the file to be made executable.
44
+ def make_file_executable(path)
45
+ @executable_files << path
46
+ end
47
+
40
48
  # Generate a summary of the changes that will be applied to the module.
41
49
  #
42
50
  # @raise (see #calculate_diffs)
@@ -49,7 +57,8 @@ module PDK
49
57
  {
50
58
  added: @added_files,
51
59
  removed: @removed_files.select { |f| PDK::Util::Filesystem.exist?(f) },
52
- modified: @diff_cache.compact
60
+ modified: @diff_cache.compact,
61
+ 'made executable': @executable_files
53
62
  }
54
63
  end
55
64
 
@@ -60,7 +69,8 @@ module PDK
60
69
  def changes?
61
70
  !changes[:added].empty? ||
62
71
  !changes[:removed].empty? ||
63
- changes[:modified].any? { |_, value| !value.nil? }
72
+ changes[:modified].any? { |_, value| !value.nil? } ||
73
+ !changes[:'made executable'].empty?
64
74
  end
65
75
 
66
76
  # Check if the update manager will change the specified file upon sync.
@@ -72,13 +82,15 @@ module PDK
72
82
  def changed?(path)
73
83
  changes[:added].any? { |add| add[:path] == path } ||
74
84
  changes[:removed].include?(path) ||
75
- changes[:modified].key?(path)
85
+ changes[:modified].key?(path) ||
86
+ changes[:'made executable'].include?(path)
76
87
  end
77
88
 
78
89
  def clear!
79
90
  @modified_files.clear
80
91
  @added_files.clear
81
92
  @removed_files.clear
93
+ @executable_files.clear
82
94
  nil
83
95
  end
84
96
 
@@ -100,6 +112,10 @@ module PDK
100
112
  files_to_write.each do |file|
101
113
  write_file(file[:path], file[:content])
102
114
  end
115
+
116
+ @executable_files.each do |file|
117
+ update_execute_bits(file)
118
+ end
103
119
  end
104
120
 
105
121
  # Remove a file from disk.
@@ -215,6 +231,16 @@ module PDK
215
231
 
216
232
  output.join($INPUT_RECORD_SEPARATOR)
217
233
  end
234
+
235
+ # Set the execute bits on a file
236
+ def update_execute_bits(path)
237
+ require 'pdk/util/filesystem'
238
+
239
+ PDK.logger.debug(format("making '%{path}' executable", path: path))
240
+ PDK::Util::Filesystem.make_executable(path)
241
+ rescue Errno::EACCES
242
+ raise PDK::CLI::ExitWithError, format("You do not have permission to make '%{path}' executable", path: path)
243
+ end
218
244
  end
219
245
  end
220
246
  end
@@ -53,7 +53,7 @@ module PDK
53
53
  # @raise [ArgumentError] (see #sanitise_data)
54
54
  def initialize(data)
55
55
  sanitise_data(data).each do |key, value|
56
- instance_variable_set("@#{key}", value)
56
+ instance_variable_set(:"@#{key}", value)
57
57
  end
58
58
  end
59
59
 
@@ -43,7 +43,6 @@ module PDK
43
43
  # @api private
44
44
  def config_for(dest_path, sync_config_path = nil)
45
45
  require 'pdk/util'
46
- require 'pdk/analytics'
47
46
 
48
47
  module_root = PDK::Util.module_root
49
48
  sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil?
@@ -56,22 +55,20 @@ module PDK
56
55
  @config = conf_defaults
57
56
  @config.deep_merge!(@sync_config, knockout_prefix: '---') unless @sync_config.nil?
58
57
  end
59
- file_config = @config.fetch(:global, {})
58
+ file_config = @config.fetch('common', {}).clone
60
59
  file_config['module_metadata'] = @module_metadata
61
60
  file_config.merge!(@config.fetch(dest_path, {})) unless dest_path.nil?
62
61
  file_config.merge!(@config).tap do |c|
63
62
  if uri.default?
64
- file_value = if c['unmanaged']
65
- 'unmanaged'
66
- elsif c['delete']
67
- 'deleted'
68
- elsif @sync_config&.key?(dest_path)
69
- 'customized'
70
- else
71
- 'default'
72
- end
73
-
74
- PDK.analytics.event('TemplateDir', 'file', label: dest_path, value: file_value)
63
+ if c['unmanaged']
64
+ 'unmanaged'
65
+ elsif c['delete']
66
+ 'deleted'
67
+ elsif @sync_config&.key?(dest_path)
68
+ 'customized'
69
+ else
70
+ 'default'
71
+ end
75
72
  end
76
73
  end
77
74
  end
@@ -95,7 +95,9 @@ module PDK
95
95
  end
96
96
  end
97
97
 
98
- yield dest_path, dest_content, dest_status
98
+ dest_executable = config['manage_execute_permissions'] && PDK::Util::Filesystem.stat(File.join(template_loc, template_file)).executable?
99
+
100
+ yield dest_path, dest_content, dest_status, dest_executable
99
101
  end
100
102
  end
101
103
  # :nocov:
data/lib/pdk/template.rb CHANGED
@@ -44,9 +44,6 @@ module PDK
44
44
  template_dir = TemplateDir.instance(uri, fetcher.path, context)
45
45
  template_dir.metadata = fetcher.metadata
46
46
 
47
- template_type = uri.default? ? 'default' : 'custom'
48
- PDK.analytics.event('TemplateDir', 'initialize', label: template_type)
49
-
50
47
  yield template_dir
51
48
  end
52
49
  nil
@@ -246,10 +246,10 @@ module PDK
246
246
  raise PDK::CLI::FatalError, format('Failed to find valid JSON in output from rspec: %{output}', output: output[:stdout]) unless rspec_json
247
247
 
248
248
  if rspec_json['examples'].empty?
249
- rspec_message = rspec_json['messages'][0]
250
- return [] if rspec_message == 'No examples found.'
249
+ return [] if rspec_json['messages'][0] == 'No examples found.'
250
+ return [] if rspec_json['messages'].include?("\nAll examples were filtered out")
251
251
 
252
- raise PDK::CLI::FatalError, format('Unable to enumerate examples. rspec reported: %{message}', message: rspec_message)
252
+ raise PDK::CLI::FatalError, format('Unable to enumerate examples. rspec reported: %{message}', message: rspec_json['messages'])
253
253
  else
254
254
  examples = []
255
255
  rspec_json['examples'].each do |example|
@@ -27,6 +27,11 @@ module PDK
27
27
  end
28
28
  module_function :read_file
29
29
 
30
+ def make_executable(file)
31
+ FileUtils.chmod('a+x', file)
32
+ end
33
+ module_function :make_executable
34
+
30
35
  # :nocov:
31
36
  # These methods just wrap core Ruby functionality and
32
37
  # can be ignored for code coverage
@@ -133,6 +138,11 @@ module PDK
133
138
  end
134
139
  end
135
140
  module_function :mv
141
+
142
+ def executable?(*args)
143
+ File.executable?(*args)
144
+ end
145
+ module_function :executable?
136
146
  # :nocov:
137
147
  end
138
148
  end
data/lib/pdk/util.rb CHANGED
@@ -32,6 +32,7 @@ module PDK
32
32
  def exit_process(exit_code)
33
33
  exit exit_code
34
34
  end
35
+ module_function :exit_process
35
36
  # :nocov:
36
37
 
37
38
  # Searches upwards from current working directory for the given target file.
data/lib/pdk/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PDK
2
- VERSION = '3.0.1'.freeze
3
- TEMPLATE_REF = '3.0.1'.freeze
2
+ VERSION = '3.3.0'.freeze
3
+ TEMPLATE_REF = '3.3.0'.freeze
4
4
  end
data/lib/pdk.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module PDK
2
- autoload :Analytics, 'pdk/analytics'
3
2
  autoload :AnswerFile, 'pdk/answer_file'
4
3
  autoload :Bolt, 'pdk/bolt'
5
4
  autoload :Config, 'pdk/config'
@@ -58,17 +57,4 @@ module PDK
58
57
 
59
58
  requested_feature_flags.include?(flagname)
60
59
  end
61
-
62
- def self.analytics
63
- @analytics ||= PDK::Analytics.build_client(
64
- logger: PDK.logger,
65
- disabled: PDK::Util::Env['PDK_DISABLE_ANALYTICS'] || PDK.config.get_within_scopes('analytics.disabled', ['user', 'system']),
66
- user_id: PDK.config.get_within_scopes('analytics.user-id', ['user', 'system']),
67
- app_id: "UA-139917834-#{PDK::Util.development_mode? ? '2' : '1'}",
68
- client: :google_analytics,
69
- app_name: 'pdk',
70
- app_version: PDK::VERSION,
71
- app_installer: PDK::Util.package_install? ? 'package' : 'gem'
72
- )
73
- end
74
60
  end