pdk 2.7.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/schema#",
3
+ "title": "Puppet Task Metadata",
4
+ "description": "The metadata format for Puppet Tasks",
5
+ "type": "object",
6
+ "properties": {
7
+ "description": {
8
+ "type": "string",
9
+ "description": "A longer description(one paragraph) of how to use the task"
10
+ },
11
+ "puppet_task_version": {
12
+ "type": "integer",
13
+ "description": "The version of this spec used",
14
+ "default": 1
15
+ },
16
+ "supports_noop": {
17
+ "type": "boolean",
18
+ "default": false,
19
+ "description": "This task respects the '_noop' metaparam. If this false or absent the task runner will refuse to run this task if noop is specified."
20
+ },
21
+ "remote": {
22
+ "type": "boolean",
23
+ "default": false,
24
+ "description": "This task is capable of operating on a remote target using connection information in the '_target' metaparam."
25
+ },
26
+ "input_method": {
27
+ "type": "string",
28
+ "enum": ["stdin", "environment", "both", "powershell"],
29
+ "description": "What input method should be used to pass params to the task"
30
+ },
31
+ "parameters": {
32
+ "$ref": "#/definitions/paramsObject",
33
+ "description": "An object mapping valid parameter names to corresponding json-schemas"
34
+ },
35
+ "implementations": {
36
+ "type": "array",
37
+ "items": {
38
+ "type": "object",
39
+ "required": ["name"],
40
+ "properties": {
41
+ "name": {
42
+ "type": "string",
43
+ "description": "Name of task executable file"
44
+ },
45
+ "requirements": {
46
+ "type": "array",
47
+ "additionalItems": {
48
+ "type": "string"
49
+ },
50
+ "description": "Features required on target to execute task"
51
+ },
52
+ "files": {
53
+ "type": "array",
54
+ "additionalItems": {
55
+ "type": "string"
56
+ },
57
+ "description": "File resources required by task"
58
+ }
59
+ }
60
+ },
61
+ "description": "Rules for selecting implementation resources based on features available on target"
62
+ },
63
+ "files": {
64
+ "type": "array",
65
+ "items": {
66
+ "type": "string"
67
+ },
68
+ "description": "Path to file resources saved in valid module directory to be provided to task"
69
+ },
70
+ "private": {
71
+ "type": "boolean",
72
+ "description": "Should this task appear by default in UI lists of tasks"
73
+ },
74
+ "extensions": {
75
+ "type": "object",
76
+ "description": "Task Runner specific metadata extensions",
77
+ "items": {
78
+ "type": "object"
79
+ }
80
+ }
81
+ },
82
+ "definitions": {
83
+ "parameterName": {
84
+ "description": "Valid names for parameter keys",
85
+ "type": "string",
86
+ "pattern": "^[a-z][a-z0-9_]*$"
87
+ },
88
+ "paramsObject": {
89
+ "type": "object",
90
+ "description": "An object with restricted keys and enumData support",
91
+ "propertyNames": {"$ref": "#/definitions/parameterName"},
92
+ "additionalProperties": {
93
+ "type": "object",
94
+ "description": "Extend Normal JSON schema to require an object and describe 'enumData' to map enum values to descriptions",
95
+ "properties": {
96
+ "description": {
97
+ "description": "A description of the parameter",
98
+ "type": "string"
99
+ },
100
+ "type": {
101
+ "description": "A puppet type string that describes a data type that will match the parameter value",
102
+ "type": "string"
103
+ },
104
+ "sensitive": {
105
+ "description": "Whether the task runner should treat the parameter value as sensitive",
106
+ "type": "boolean",
107
+ "default": false
108
+ },
109
+ "default": {
110
+ "description": "The default value to pass to the task implementation if the parameter isn't provided"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
@@ -12,8 +12,8 @@ module PDK
12
12
  # FalseClass.
13
13
  def self.boolean
14
14
  {
15
- proc: ->(value) { [true, false].include?(value) },
16
- message: 'must be a boolean: true or false',
15
+ proc: ->(value) { [true, false].include?(value) },
16
+ message: 'must be a boolean: true or false'
17
17
  }
18
18
  end
19
19
 
@@ -22,8 +22,8 @@ module PDK
22
22
  # regex for a version 4 UUID.
23
23
  def self.uuid
24
24
  {
25
- proc: ->(value) { value.match(%r{\A\h{8}(?:-\h{4}){3}-\h{12}\z}) },
26
- message: 'must be a version 4 UUID',
25
+ proc: ->(value) { value.match(/\A\h{8}(?:-\h{4}){3}-\h{12}\z/) },
26
+ message: 'must be a version 4 UUID'
27
27
  }
28
28
  end
29
29
  end
@@ -8,6 +8,7 @@ module PDK
8
8
  class YAML < Namespace
9
9
  def parse_file(filename)
10
10
  raise unless block_given?
11
+
11
12
  data = load_data(filename)
12
13
  return if data.nil? || data.empty?
13
14
 
@@ -22,15 +23,9 @@ module PDK
22
23
 
23
24
  data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) }
24
25
  rescue Psych::SyntaxError => e
25
- raise PDK::Config::LoadError, 'Syntax error when loading %{file}: %{error}' % {
26
- file: filename,
27
- error: "#{e.problem} #{e.context}",
28
- }
26
+ raise PDK::Config::LoadError, format('Syntax error when loading %{file}: %{error}', file: filename, error: "#{e.problem} #{e.context}")
29
27
  rescue Psych::DisallowedClass => e
30
- raise PDK::Config::LoadError, 'Unsupported class in %{file}: %{error}' % {
31
- file: filename,
32
- error: e.message,
33
- }
28
+ raise PDK::Config::LoadError, format('Unsupported class in %{file}: %{error}', file: filename, error: e.message)
34
29
  end
35
30
 
36
31
  # Serializes object data into a YAML string.
@@ -8,6 +8,7 @@ module PDK
8
8
  class YAMLWithSchema < JSONSchemaNamespace
9
9
  def parse_file(filename)
10
10
  raise unless block_given?
11
+
11
12
  data = load_data(filename)
12
13
  data = '' if data.nil?
13
14
  require 'yaml'
@@ -20,10 +21,7 @@ module PDK
20
21
  # Ensure the parsed document is actually valid
21
22
  validate_document!(@raw_data)
22
23
  rescue ::JSON::Schema::ValidationError => e
23
- raise PDK::Config::LoadError, 'The configuration file %{filename} is not valid: %{message}' % {
24
- filename: filename,
25
- message: e.message,
26
- }
24
+ raise PDK::Config::LoadError, format('The configuration file %{filename} is not valid: %{message}', filename: filename, message: e.message)
27
25
  end
28
26
 
29
27
  require 'pdk/config/json_schema_setting'
@@ -36,15 +34,9 @@ module PDK
36
34
  # we're left with the settings that we don't manage.
37
35
  self.unmanaged_settings = @raw_data.reject { |k, _| schema_property_names.include?(k) }
38
36
  rescue Psych::SyntaxError => e
39
- raise PDK::Config::LoadError, 'Syntax error when loading %{file}: %{error}' % {
40
- file: filename,
41
- error: "#{e.problem} #{e.context}",
42
- }
37
+ raise PDK::Config::LoadError, format('Syntax error when loading %{file}: %{error}', file: filename, error: "#{e.problem} #{e.context}")
43
38
  rescue Psych::DisallowedClass => e
44
- raise PDK::Config::LoadError, 'Unsupported class in %{file}: %{error}' % {
45
- file: filename,
46
- error: e.message,
47
- }
39
+ raise PDK::Config::LoadError, format('Unsupported class in %{file}: %{error}', file: filename, error: e.message)
48
40
  end
49
41
 
50
42
  # Serializes object data into a YAML string.
data/lib/pdk/config.rb CHANGED
@@ -24,12 +24,12 @@ module PDK
24
24
  def initialize(options = nil)
25
25
  options = {} if options.nil?
26
26
  @config_options = {
27
- 'system.path' => PDK::Config.system_config_path,
27
+ 'system.path' => PDK::Config.system_config_path,
28
28
  'system.module_defaults.path' => PDK::Config.system_answers_path,
29
- 'user.path' => PDK::Config.user_config_path,
30
- 'user.module_defaults.path' => PDK::AnswerFile.default_answer_file_path,
31
- 'user.analytics.path' => PDK::Config.analytics_config_path,
32
- 'context' => PDK.context,
29
+ 'user.path' => PDK::Config.user_config_path,
30
+ 'user.module_defaults.path' => PDK::AnswerFile.default_answer_file_path,
31
+ 'user.analytics.path' => PDK::Config.analytics_config_path,
32
+ 'context' => PDK.context
33
33
  }.merge(options)
34
34
  end
35
35
 
@@ -91,9 +91,7 @@ module PDK
91
91
  def project_config
92
92
  context = @config_options['context']
93
93
  @project ||= PDK::Config::Namespace.new('project') do
94
- if context.is_a?(PDK::Context::ControlRepo)
95
- mount :environment, PDK::ControlRepo.environment_conf_as_config(File.join(context.root_path, 'environment.conf'))
96
- end
94
+ mount :environment, PDK::ControlRepo.environment_conf_as_config(File.join(context.root_path, 'environment.conf')) if context.is_a?(PDK::Context::ControlRepo)
97
95
 
98
96
  mount :validate, PDK::Config::YAML.new('validate', file: File.join(context.root_path, 'pdk.yaml'), persistent_defaults: true) do
99
97
  setting 'ignore' do
@@ -124,9 +122,10 @@ module PDK
124
122
  return nil if root.nil? || root.empty?
125
123
 
126
124
  if keys.empty?
127
- if root.is_a?(Array)
125
+ case root
126
+ when Array
128
127
  name = root
129
- elsif root.is_a?(String)
128
+ when String
130
129
  name = split_key_string(root)
131
130
  else
132
131
  return nil
@@ -135,7 +134,7 @@ module PDK
135
134
  name = [root].concat(keys)
136
135
  end
137
136
 
138
- get_within_scopes(name[1..-1], [name[0]])
137
+ get_within_scopes(name[1..], [name[0]])
139
138
  end
140
139
 
141
140
  # Returns a configuration setting by name, using scope precedence rules. If no scopes are passed, then all scopes are queried using the default precedence rules
@@ -143,8 +142,8 @@ module PDK
143
142
  # @scopes [Nil, Array[String]] The list of scopes, in order, to query in turn for the setting_name. Invalid or missing scopes are ignored.
144
143
  # @return [PDK::Config::Namespace, Object, nil] The value of the configuration setting. Returns nil if it does no exist
145
144
  def get_within_scopes(setting_name, scopes = nil)
146
- raise ArgumentError, 'Expected an Array but got \'%{klass}\' for scopes' % { klass: scopes.class } unless scopes.nil? || scopes.is_a?(Array)
147
- raise ArgumentError, 'Expected an Array or String but got \'%{klass}\' for setting_name' % { klass: setting_name.class } unless setting_name.is_a?(Array) || setting_name.is_a?(String)
145
+ raise ArgumentError, format('Expected an Array but got \'%{klass}\' for scopes', klass: scopes.class) unless scopes.nil? || scopes.is_a?(Array)
146
+ raise ArgumentError, format('Expected an Array or String but got \'%{klass}\' for setting_name', klass: setting_name.class) unless setting_name.is_a?(Array) || setting_name.is_a?(String)
148
147
 
149
148
  setting_arr = setting_name.is_a?(String) ? split_key_string(setting_name) : setting_name
150
149
  all_scope_names = all_scopes.keys
@@ -165,6 +164,7 @@ module PDK
165
164
  # @yield [PDK::Config::Namespace, Object] The value of the configuration setting. Does not yield if the setting does not exist or is nil
166
165
  def with_scoped_value(setting_name, scopes = nil)
167
166
  raise ArgumentError, 'must be passed a block' unless block_given?
167
+
168
168
  value = get_within_scopes(setting_name, scopes)
169
169
  yield value unless value.nil?
170
170
  end
@@ -179,24 +179,23 @@ module PDK
179
179
  # @return [Object] The new value of the configuration setting
180
180
  def set(key, value, options = {})
181
181
  options = {
182
- force: false,
182
+ force: false
183
183
  }.merge(options)
184
184
 
185
185
  names = key.is_a?(String) ? split_key_string(key) : key
186
186
  raise ArgumentError, 'Invalid configuration names' if names.nil? || !names.is_a?(Array) || names.empty?
187
+
187
188
  scope_name = names[0]
188
- raise ArgumentError, "Unknown configuration root '%{name}'" % { name: scope_name } if all_scopes[scope_name].nil?
189
- deep_set_object(value, options[:force], send(all_scopes[scope_name]), *names[1..-1])
189
+ raise ArgumentError, format("Unknown configuration root '%{name}'", name: scope_name) if all_scopes[scope_name].nil?
190
+
191
+ deep_set_object(value, options[:force], send(all_scopes[scope_name]), *names[1..])
190
192
  end
191
193
 
192
194
  def self.bolt_analytics_config
193
195
  file = PDK::Util::Filesystem.expand_path('~/.puppetlabs/bolt/analytics.yaml')
194
196
  PDK::Config::YAML.new(file: file)
195
197
  rescue PDK::Config::LoadError => e
196
- PDK.logger.debug 'Unable to load %{file}: %{message}' % {
197
- file: file,
198
- message: e.message,
199
- }
198
+ PDK.logger.debug format('Unable to load %{file}: %{message}', file: file, message: e.message)
200
199
  PDK::Config::YAML.new
201
200
  end
202
201
 
@@ -222,7 +221,7 @@ module PDK
222
221
 
223
222
  # return nil if not exist
224
223
  def self.json_schema(name)
225
- File.join(json_schemas_path, name + '_schema.json')
224
+ File.join(json_schemas_path, "#{name}_schema.json")
226
225
  end
227
226
 
228
227
  def self.analytics_config_exist?
@@ -235,24 +234,21 @@ module PDK
235
234
  return unless PDK::CLI::Util.interactive?
236
235
 
237
236
  pre_message =
238
- 'PDK collects anonymous usage information to help us understand how ' \
239
- 'it is being used and make decisions on how to improve it. You can ' \
240
- 'find out more about what data we collect and how it is used in the ' \
241
- "PDK documentation at %{url}.\n" % { url: 'https://puppet.com/docs/pdk/latest/pdk_install.html' }
237
+ format('PDK collects anonymous usage information to help us understand how ' \
238
+ 'it is being used and make decisions on how to improve it. You can ' \
239
+ 'find out more about what data we collect and how it is used in the ' \
240
+ "PDK documentation at %{url}.\n", url: 'https://puppet.com/docs/pdk/latest/pdk_install.html')
242
241
  post_message =
243
- 'You can opt in or out of the usage data collection at any time by ' \
244
- 'editing the analytics configuration file at %{path} and changing ' \
245
- "the '%{key}' value." % {
246
- path: PDK::Config.analytics_config_path,
247
- key: 'disabled',
248
- }
242
+ format('You can opt in or out of the usage data collection at any time by ' \
243
+ 'editing the analytics configuration file at %{path} and changing ' \
244
+ "the '%{key}' value.", path: PDK::Config.analytics_config_path, key: 'disabled')
249
245
 
250
246
  questions = [
251
247
  {
252
- name: 'enabled',
248
+ name: 'enabled',
253
249
  question: 'Do you consent to the collection of anonymous PDK usage information?',
254
- type: :yes,
255
- },
250
+ type: :yes
251
+ }
256
252
  ]
257
253
 
258
254
  require 'pdk/cli/util/interview'
@@ -265,9 +261,9 @@ module PDK
265
261
 
266
262
  if answers.nil?
267
263
  PDK.logger.info 'No answer given, opting out of analytics collection.'
268
- PDK.config.set(%w[user analytics disabled], true)
264
+ PDK.config.set(['user', 'analytics', 'disabled'], true)
269
265
  else
270
- PDK.config.set(%w[user analytics disabled], !answers['enabled'])
266
+ PDK.config.set(['user', 'analytics', 'disabled'], !answers['enabled'])
271
267
  end
272
268
 
273
269
  PDK.logger.info(text: post_message, wrap: true)
@@ -275,7 +271,7 @@ module PDK
275
271
 
276
272
  private
277
273
 
278
- #:nocov: This is a private method and is tested elsewhere
274
+ # :nocov: This is a private method and is tested elsewhere
279
275
  def traverse_object(object, *names)
280
276
  return nil if object.nil? || !object.respond_to?(:[])
281
277
  return nil if names.nil?
@@ -289,25 +285,27 @@ module PDK
289
285
  value = object[name]
290
286
  if names.empty?
291
287
  return value if value.is_a?(PDK::Config::Namespace)
288
+
292
289
  # Duplicate arrays and hashes so that they are isolated from changes being made
293
- (value.is_a?(Hash) || value.is_a?(Array)) ? value.dup : value
290
+ value.is_a?(Hash) || value.is_a?(Array) ? value.dup : value
294
291
  else
295
292
  traverse_object(value, *names)
296
293
  end
297
294
  end
298
- #:nocov:
295
+ # :nocov:
299
296
 
300
- #:nocov: This is a private method and is tested elsewhere
297
+ # :nocov: This is a private method and is tested elsewhere
301
298
  # Takes a string representation of a setting and splits into its constituent setting parts e.g.
302
299
  # 'user.a.b.c' becomes ['user', 'a', 'b', 'c']
303
300
  # @return [Array[String]] The string split into each setting name as an array
304
301
  def split_key_string(key)
305
- raise ArgumentError, 'Expected a String but got \'%{klass}\'' % { klass: key.class } unless key.is_a?(String)
302
+ raise ArgumentError, format('Expected a String but got \'%{klass}\'', klass: key.class) unless key.is_a?(String)
303
+
306
304
  key.split('.')
307
305
  end
308
- #:nocov:
306
+ # :nocov:
309
307
 
310
- #:nocov:
308
+ # :nocov:
311
309
  # Returns all known scope names and their associated method name to call, to query the scope
312
310
  # Note - Order is important. This dictates the resolution precedence order (topmost is processed first)
313
311
  # @return [Hash[String, Symbol]] A hash of the scope name then method name to call to query the scope (as a Symbol)
@@ -315,12 +313,12 @@ module PDK
315
313
  # Note - Order is important. This dictates the resolution precedence order (topmost is processed first)
316
314
  {
317
315
  'project' => :project_config,
318
- 'user' => :user_config,
319
- 'system' => :system_config,
316
+ 'user' => :user_config,
317
+ 'system' => :system_config
320
318
  }.freeze
321
319
  end
322
320
 
323
- #:nocov: This is a private method and is tested elsewhere
321
+ # :nocov: This is a private method and is tested elsewhere
324
322
  # Deeply traverses an object tree via `[]` and sets the last
325
323
  # element to the value specified.
326
324
  #
@@ -333,9 +331,7 @@ module PDK
333
331
  current_value = namespace[name]
334
332
 
335
333
  # If the next thing in the traversal chain is another namespace, set the value using that child namespace.
336
- if current_value.is_a?(PDK::Config::Namespace)
337
- return deep_set_object(value, force, current_value, *names)
338
- end
334
+ return deep_set_object(value, force, current_value, *names) if current_value.is_a?(PDK::Config::Namespace)
339
335
 
340
336
  # We're at the end of the name traversal
341
337
  if names.empty?
@@ -378,11 +374,11 @@ module PDK
378
374
  return value
379
375
  end
380
376
 
381
- raise ArgumentError, "Unable to set '%{key}' to '%{value}' as it is not a Hash" % { key: namespace.name + '.' + name, value: hash_value } unless current_value.is_a?(Hash)
377
+ raise ArgumentError, format("Unable to set '%{key}' to '%{value}' as it is not a Hash", key: "#{namespace.name}.#{name}", value: hash_value) unless current_value.is_a?(Hash)
382
378
 
383
379
  namespace[name] = current_value.merge(hash_value)
384
380
  value
385
381
  end
386
- #:nocov:
382
+ # :nocov:
387
383
  end
388
384
  end
@@ -26,6 +26,7 @@ module PDK
26
26
  # @return [Array[String]] The modulepath setting for this control repository
27
27
  def module_paths
28
28
  return @module_paths unless @module_paths.nil?
29
+
29
30
  value = environment_conf['modulepath'] || ''
30
31
  # We have to use a hardcoded value here because File::PATH_SEPARATOR is ';' on Windows.
31
32
  # As the environment.conf is only used on Puppet Server, it's always ':'
@@ -41,12 +42,12 @@ module PDK
41
42
  .select { |path| PDK::Util::Filesystem.directory?(PDK::Util::Filesystem.expand_path(File.join(root_path, path))) }
42
43
  end
43
44
 
44
- #:nocov:
45
+ # :nocov:
45
46
  # @see PDK::Context::AbstractContext.display_name
46
47
  def display_name
47
48
  'a Control Repository context'
48
49
  end
49
- #:nocov:
50
+ # :nocov:
50
51
 
51
52
  private
52
53
 
@@ -17,12 +17,12 @@ module PDK
17
17
  PDK::Util.module_pdk_compatible?(root_path)
18
18
  end
19
19
 
20
- #:nocov:
20
+ # :nocov:
21
21
  # @see PDK::Context::AbstractContext.display_name
22
22
  def display_name
23
23
  'a Puppet Module context'
24
24
  end
25
- #:nocov:
25
+ # :nocov:
26
26
  end
27
27
  end
28
28
  end
@@ -5,12 +5,12 @@ module PDK
5
5
  # Represents a context which the PDK does not know. For example
6
6
  # an empty directory
7
7
  class None < PDK::Context::AbstractContext
8
- #:nocov:
8
+ # :nocov:
9
9
  # @see PDK::Context::AbstractContext.display_name
10
10
  def display_name
11
11
  'an unknown context'
12
12
  end
13
- #:nocov:
13
+ # :nocov:
14
14
 
15
15
  # @see PDK::Context::AbstractContext.parent_context
16
16
  def parent_context
data/lib/pdk/context.rb CHANGED
@@ -20,9 +20,7 @@ module PDK
20
20
 
21
21
  # Puppet Module detection
22
22
  metadata_file = File.join(current, 'metadata.json')
23
- if PDK::Util::Filesystem.file?(metadata_file) || PDK::Util.in_module_root?(context_path)
24
- return PDK::Context::Module.new(current, context_path)
25
- end
23
+ return PDK::Context::Module.new(current, context_path) if PDK::Util::Filesystem.file?(metadata_file) || PDK::Util.in_module_root?(context_path)
26
24
 
27
25
  previous = current
28
26
  current = PDK::Util::Filesystem.expand_path('..', current)
@@ -82,6 +80,7 @@ module PDK
82
80
  PDK.logger.debug("Detected #{current.display_name} at #{current.root_path.nil? ? current.context_path : current.root_path}")
83
81
  current = current.parent_context
84
82
  break if current.nil?
83
+
85
84
  depth += 1
86
85
  # Circuit breaker in case there are circular references
87
86
  break if depth > 20
@@ -89,11 +88,11 @@ module PDK
89
88
  nil
90
89
  end
91
90
 
92
- #:nocov: There's nothing to test here
91
+ # :nocov: There's nothing to test here
93
92
  def to_s
94
93
  "#<#{self.class}:#{object_id}>#{context_path}"
95
94
  end
96
- #:nocov:
95
+ # :nocov:
97
96
  end
98
97
  end
99
98
  end
@@ -2,7 +2,7 @@ require 'pdk'
2
2
 
3
3
  module PDK
4
4
  module ControlRepo
5
- CONTROL_REPO_FILES = %w[environment.conf Puppetfile].freeze
5
+ CONTROL_REPO_FILES = ['environment.conf', 'Puppetfile'].freeze
6
6
 
7
7
  DEFAULT_IGNORED = [
8
8
  '/pkg/',
@@ -11,7 +11,7 @@ module PDK
11
11
  # Strictly speaking this isn't default but if people have tricked older PDK into thinking that a
12
12
  # Control Repo is a module, they may have recursive symlinks in spec/fixtures/modules
13
13
  '/spec/fixtures/modules/',
14
- '/vendor/',
14
+ '/vendor/'
15
15
  ].freeze
16
16
 
17
17
  # Returns path to the root of the Control Repo being worked on.
@@ -38,10 +38,9 @@ module PDK
38
38
  File.dirname(environment_conf_path)
39
39
  elsif control_repo_root?(Dir.pwd)
40
40
  Dir.pwd
41
- else
42
- nil
43
41
  end
44
42
  return path if path.nil? || !strict_check
43
+
45
44
  PDK::Bolt.bolt_project_root?(path) ? nil : path
46
45
  end
47
46
  module_function :find_control_repo_root
@@ -25,12 +25,12 @@ module PDK
25
25
  define_name_parts = object_name.split('::')
26
26
  # drop the module name if the object name contains multiple parts
27
27
  define_name_parts.delete_at(0) if define_name_parts.length > 1
28
- files = { 'defined_type_spec.erb' => File.join('spec', 'defines', *define_name_parts) + '_spec.rb' }
28
+ files = { 'defined_type_spec.erb' => "#{File.join('spec', 'defines', *define_name_parts)}_spec.rb" }
29
29
  return files if spec_only?
30
30
 
31
- define_name_parts = object_name.split('::')[1..-1]
31
+ define_name_parts = object_name.split('::')[1..]
32
32
  define_name_parts << 'init' if define_name_parts.empty?
33
- files['defined_type.erb'] = File.join('manifests', *define_name_parts) + '.pp'
33
+ files['defined_type.erb'] = "#{File.join('manifests', *define_name_parts)}.pp"
34
34
 
35
35
  files
36
36
  end
@@ -9,11 +9,12 @@ module PDK
9
9
 
10
10
  def template_files
11
11
  files = {
12
- 'fact_spec.erb' => File.join('spec', 'unit', 'facter', object_name) + '_spec.rb',
12
+ 'fact_spec.erb' => "#{File.join('spec', 'unit', 'facter', object_name)}_spec.rb"
13
13
  }
14
14
  return files if spec_only?
15
+
15
16
  files.merge(
16
- 'fact.erb' => File.join('lib', 'facter', object_name) + '.rb',
17
+ 'fact.erb' => "#{File.join('lib', 'facter', object_name)}.rb"
17
18
  )
18
19
  end
19
20
 
@@ -24,16 +24,17 @@ module PDK
24
24
  # Drop the module name if the object name contains multiple parts
25
25
  func_name_parts.delete_at(0) if func_name_parts.length > 1
26
26
  files = {
27
- File.join('functions', 'function_spec.erb') => File.join('spec', 'functions', *func_name_parts) + '_spec.rb',
27
+ File.join('functions', 'function_spec.erb') => "#{File.join('spec', 'functions', *func_name_parts)}_spec.rb"
28
28
  }
29
29
  return files if spec_only?
30
- func_name_parts = object_name.split('::')[1..-1]
30
+
31
+ func_name_parts = object_name.split('::')[1..]
31
32
  template_file = File.join('functions', "#{options[:type]}_function.erb")
32
33
 
33
34
  files[template_file] = if options[:type].eql?('v4')
34
- File.join('lib', 'puppet', 'functions', module_name, *func_name_parts) + '.rb'
35
+ "#{File.join('lib', 'puppet', 'functions', module_name, *func_name_parts)}.rb"
35
36
  else
36
- File.join('functions', *func_name_parts) + '.pp'
37
+ "#{File.join('functions', *func_name_parts)}.pp"
37
38
  end
38
39
  files
39
40
  end