pdk 1.14.1 → 1.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -2
  3. data/lib/pdk.rb +28 -19
  4. data/lib/pdk/answer_file.rb +2 -95
  5. data/lib/pdk/bolt.rb +19 -0
  6. data/lib/pdk/cli.rb +4 -5
  7. data/lib/pdk/cli/bundle.rb +5 -1
  8. data/lib/pdk/cli/config.rb +3 -1
  9. data/lib/pdk/cli/config/get.rb +3 -1
  10. data/lib/pdk/cli/console.rb +1 -1
  11. data/lib/pdk/cli/convert.rb +16 -10
  12. data/lib/pdk/cli/exec.rb +2 -1
  13. data/lib/pdk/cli/exec/command.rb +45 -4
  14. data/lib/pdk/cli/exec_group.rb +78 -43
  15. data/lib/pdk/cli/get.rb +20 -0
  16. data/lib/pdk/cli/get/config.rb +24 -0
  17. data/lib/pdk/cli/module/build.rb +1 -1
  18. data/lib/pdk/cli/module/generate.rb +1 -1
  19. data/lib/pdk/cli/new/class.rb +2 -2
  20. data/lib/pdk/cli/new/defined_type.rb +2 -2
  21. data/lib/pdk/cli/new/provider.rb +2 -2
  22. data/lib/pdk/cli/new/task.rb +2 -2
  23. data/lib/pdk/cli/new/test.rb +2 -2
  24. data/lib/pdk/cli/new/transport.rb +2 -2
  25. data/lib/pdk/cli/release.rb +192 -0
  26. data/lib/pdk/cli/release/prep.rb +39 -0
  27. data/lib/pdk/cli/release/publish.rb +40 -0
  28. data/lib/pdk/cli/remove.rb +20 -0
  29. data/lib/pdk/cli/remove/config.rb +80 -0
  30. data/lib/pdk/cli/set.rb +20 -0
  31. data/lib/pdk/cli/set/config.rb +119 -0
  32. data/lib/pdk/cli/update.rb +18 -8
  33. data/lib/pdk/cli/util.rb +7 -3
  34. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  35. data/lib/pdk/cli/validate.rb +26 -44
  36. data/lib/pdk/config.rb +265 -8
  37. data/lib/pdk/config/ini_file.rb +183 -0
  38. data/lib/pdk/config/ini_file_setting.rb +39 -0
  39. data/lib/pdk/config/namespace.rb +26 -6
  40. data/lib/pdk/config/setting.rb +3 -2
  41. data/lib/pdk/context.rb +99 -0
  42. data/lib/pdk/context/control_repo.rb +60 -0
  43. data/lib/pdk/context/module.rb +28 -0
  44. data/lib/pdk/context/none.rb +22 -0
  45. data/lib/pdk/control_repo.rb +90 -0
  46. data/lib/pdk/generate.rb +1 -0
  47. data/lib/pdk/generate/defined_type.rb +25 -32
  48. data/lib/pdk/generate/module.rb +42 -35
  49. data/lib/pdk/generate/provider.rb +16 -65
  50. data/lib/pdk/generate/puppet_class.rb +25 -31
  51. data/lib/pdk/generate/puppet_object.rb +84 -189
  52. data/lib/pdk/generate/resource_api_object.rb +55 -0
  53. data/lib/pdk/generate/task.rb +28 -46
  54. data/lib/pdk/generate/transport.rb +21 -75
  55. data/lib/pdk/module.rb +1 -1
  56. data/lib/pdk/module/build.rb +38 -25
  57. data/lib/pdk/module/convert.rb +61 -42
  58. data/lib/pdk/module/metadata.rb +1 -3
  59. data/lib/pdk/module/release.rb +254 -0
  60. data/lib/pdk/module/update.rb +24 -16
  61. data/lib/pdk/module/update_manager.rb +8 -1
  62. data/lib/pdk/report.rb +18 -12
  63. data/lib/pdk/report/event.rb +6 -3
  64. data/lib/pdk/template.rb +59 -0
  65. data/lib/pdk/template/fetcher.rb +98 -0
  66. data/lib/pdk/template/fetcher/git.rb +85 -0
  67. data/lib/pdk/template/fetcher/local.rb +28 -0
  68. data/lib/pdk/template/renderer.rb +96 -0
  69. data/lib/pdk/template/renderer/v1.rb +25 -0
  70. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
  71. data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
  72. data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
  73. data/lib/pdk/template/template_dir.rb +67 -0
  74. data/lib/pdk/tests/unit.rb +5 -0
  75. data/lib/pdk/util.rb +55 -45
  76. data/lib/pdk/util/bundler.rb +9 -9
  77. data/lib/pdk/util/changelog_generator.rb +120 -0
  78. data/lib/pdk/util/env.rb +28 -11
  79. data/lib/pdk/util/filesystem.rb +62 -2
  80. data/lib/pdk/util/git.rb +60 -8
  81. data/lib/pdk/util/json_finder.rb +84 -0
  82. data/lib/pdk/util/puppet_strings.rb +3 -3
  83. data/lib/pdk/util/puppet_version.rb +4 -5
  84. data/lib/pdk/util/ruby_version.rb +9 -6
  85. data/lib/pdk/util/template_uri.rb +60 -48
  86. data/lib/pdk/util/version.rb +4 -4
  87. data/lib/pdk/validate.rb +79 -25
  88. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  89. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  90. data/lib/pdk/validate/external_command_validator.rb +208 -0
  91. data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
  92. data/lib/pdk/validate/invokable_validator.rb +215 -0
  93. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
  94. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
  95. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  96. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
  97. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  98. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
  99. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
  100. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
  101. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  102. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
  103. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
  104. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  105. data/lib/pdk/validate/validator.rb +118 -0
  106. data/lib/pdk/validate/validator_group.rb +104 -0
  107. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
  108. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  109. data/lib/pdk/version.rb +1 -1
  110. data/locales/pdk.pot +755 -319
  111. metadata +66 -24
  112. data/lib/pdk/module/templatedir.rb +0 -391
  113. data/lib/pdk/template_file.rb +0 -96
  114. data/lib/pdk/validate/base_validator.rb +0 -215
  115. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
  116. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
  117. data/lib/pdk/validate/metadata_validator.rb +0 -26
  118. data/lib/pdk/validate/puppet/puppet_epp.rb +0 -137
  119. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
  120. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -137
  121. data/lib/pdk/validate/puppet_validator.rb +0 -26
  122. data/lib/pdk/validate/ruby/rubocop.rb +0 -72
  123. data/lib/pdk/validate/ruby_validator.rb +0 -26
  124. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
  125. data/lib/pdk/validate/tasks/name.rb +0 -90
  126. data/lib/pdk/validate/tasks_validator.rb +0 -29
  127. data/lib/pdk/validate/yaml/syntax.rb +0 -125
  128. data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -0,0 +1,39 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ class Config
5
+ class IniFileSetting < PDK::Config::Setting
6
+ # Initialises the PDK::Config::JSONSchemaSetting object.
7
+ #
8
+ # @see PDK::Config::Setting.initialize
9
+ def initialize(_name, namespace, initial_value = nil)
10
+ raise 'The IniFileSetting object can only be created within the IniFile Namespace' unless namespace.is_a?(PDK::Config::IniFile)
11
+ super
12
+ validate!(initial_value) unless initial_value.nil?
13
+ end
14
+
15
+ # Verifies that the new setting value is valid in an Ini File
16
+ #
17
+ # @see PDK::Config::Setting.validate!
18
+ def validate!(value)
19
+ # We're very restrictive here. Realistically Ini files only have string types
20
+ return if value.nil? || value.is_a?(String) || value.is_a?(Integer)
21
+ # The only other valid-ish type is a Hash
22
+ unless value.is_a?(Hash)
23
+ raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
24
+ key: qualified_name,
25
+ class: value.class,
26
+ }
27
+ end
28
+ # Any hashes can only have a single String/Integer value
29
+ value.each do |child_name, child_value|
30
+ next if child_value.nil? || child_value.is_a?(String) || child_value.is_a?(Integer)
31
+ raise ArgumentError, _('The setting %{key} may only be a String or Integer, not %{class}') % {
32
+ key: qualified_name + '.' + child_name,
33
+ class: child_value.class,
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -27,13 +27,14 @@ module PDK
27
27
  # used for settings which a randomly generated, instead of being deterministic, e.g. analytics user-id
28
28
  # @param block [Proc] a block that is evaluated within the new instance.
29
29
  def initialize(name = nil, file: nil, parent: nil, persistent_defaults: false, &block)
30
- @file = File.expand_path(file) unless file.nil?
30
+ @file = PDK::Util::Filesystem.expand_path(file) unless file.nil?
31
31
  @settings = {}
32
32
  @name = name.to_s
33
33
  @parent = parent
34
34
  @persistent_defaults = persistent_defaults
35
35
  @mounts = {}
36
36
  @loaded_from_file = false
37
+ @read_only = false
37
38
 
38
39
  instance_eval(&block) if block_given?
39
40
  end
@@ -48,7 +49,7 @@ module PDK
48
49
  #
49
50
  # @return [nil]
50
51
  def setting(key, &block)
51
- @settings[key.to_s] ||= PDK::Config::Setting.new(key.to_s, self)
52
+ @settings[key.to_s] ||= default_setting_class.new(key.to_s, self)
52
53
  @settings[key.to_s].instance_eval(&block) if block_given?
53
54
  end
54
55
 
@@ -97,7 +98,8 @@ module PDK
97
98
  # Check if it's a setting, otherwise nil
98
99
  return nil if settings[key.to_s].nil?
99
100
  return settings[key.to_s].value unless settings[key.to_s].value.nil?
100
- default_value = settings[key.to_s].default
101
+ # Duplicate arrays and hashes so that they are isolated from changes being made
102
+ default_value = PDK::Util.deep_duplicate(settings[key.to_s].default)
101
103
  return default_value if default_value.nil? || !@persistent_defaults
102
104
  # Persist the default value
103
105
  settings[key.to_s].value = default_value
@@ -205,8 +207,26 @@ module PDK
205
207
  child_namespace? && file.nil?
206
208
  end
207
209
 
210
+ # Disables the namespace, and child namespaces, from writing changes to disk.
211
+ # Typically this is only needed for unit testing.
212
+ # @api private
213
+ def read_only!
214
+ @read_only = true
215
+ @mounts.each { |_, child| child.read_only! }
216
+ end
217
+
208
218
  private
209
219
 
220
+ # Returns the object class to create settings with. Subclasses may override this to use specific setting classes
221
+ #
222
+ # @return [Class[PDK::Config::Setting]]
223
+ #
224
+ # @abstract
225
+ # @private
226
+ def default_setting_class
227
+ PDK::Config::Setting
228
+ end
229
+
210
230
  # Determines whether a setting name should be resolved using the filter
211
231
  # Returns true when filter is nil.
212
232
  # Returns true if the filter is exactly the same name as the setting.
@@ -253,7 +273,7 @@ module PDK
253
273
  # Need to use `@settings` and `@mounts` here to stop recursive calls
254
274
  return unless @mounts[key.to_s].nil?
255
275
  return unless @settings[key.to_s].nil?
256
- @settings[key.to_s] = PDK::Config::Setting.new(key.to_s, self, initial_value)
276
+ @settings[key.to_s] = default_setting_class.new(key.to_s, self, initial_value)
257
277
  end
258
278
 
259
279
  # Set the value of the named key.
@@ -281,7 +301,7 @@ module PDK
281
301
  return if filename.nil?
282
302
  return unless PDK::Util::Filesystem.file?(filename)
283
303
 
284
- PDK::Util::Filesystem.read_file(file)
304
+ PDK::Util::Filesystem.read_file(filename)
285
305
  rescue Errno::ENOENT => e
286
306
  raise PDK::Config::LoadError, e.message
287
307
  rescue Errno::EACCES
@@ -302,7 +322,7 @@ module PDK
302
322
  #
303
323
  # @return [nil]
304
324
  def save_data
305
- return if file.nil?
325
+ return if file.nil? || @read_only
306
326
 
307
327
  PDK::Util::Filesystem.mkdir_p(File.dirname(file))
308
328
 
@@ -46,8 +46,9 @@ module PDK
46
46
  [namespace.name, @name].join('.')
47
47
  end
48
48
 
49
- def value # rubocop:disable Style/TrivialAccessors
50
- @value
49
+ def value
50
+ # Duplicate arrays and hashes so that they are isolated from changes being made
51
+ PDK::Util.deep_duplicate(@value)
51
52
  end
52
53
 
53
54
  def value=(obj)
@@ -0,0 +1,99 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Context
5
+ autoload :None, 'pdk/context/none'
6
+ autoload :Module, 'pdk/context/module'
7
+ autoload :ControlRepo, 'pdk/context/control_repo'
8
+
9
+ # Automatically determines the PDK Context given a path. Create will continue up the directory tree until it
10
+ # finds a valid context
11
+ # @return [PDK::Context::AbstractContext] Returns a PDK::Context::None if the context could not be determined
12
+ def self.create(context_path)
13
+ return PDK::Context::None.new(context_path) unless PDK::Util::Filesystem.directory?(context_path)
14
+
15
+ previous = nil
16
+ current = PDK::Util::Filesystem.expand_path(context_path)
17
+ until !PDK::Util::Filesystem.directory?(current) || current == previous
18
+ # Control Repo detection
19
+ return PDK::Context::ControlRepo.new(current, context_path) if PDK.feature_flag?('controlrepo') && PDK::ControlRepo.control_repo_root?(current)
20
+
21
+ # Puppet Module detection
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
26
+
27
+ previous = current
28
+ current = PDK::Util::Filesystem.expand_path('..', current)
29
+ end
30
+ PDK::Context::None.new(context_path)
31
+ end
32
+
33
+ # Abstract class which all PDK Contexts will subclass from.
34
+ # @abstract
35
+ class AbstractContext
36
+ # The root of this context, for example the module root when inside a module. This can be different from context_path
37
+ # For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
38
+ # that is the root of the Module context. Defaults to the context_path if not set.
39
+ # @return [String]
40
+ def root_path
41
+ @root_path || @context_path
42
+ end
43
+
44
+ # The path used to create this context, for example the current working directory. This can be different from root_path
45
+ # For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
46
+ # that is the root of the Module context
47
+ # @return [String]
48
+ attr_reader :context_path
49
+
50
+ # @param context_path [String] The path where this context was created from e.g. Dir.pwd
51
+ def initialize(context_path)
52
+ @context_path = context_path
53
+ @root_path = nil
54
+ end
55
+
56
+ # Whether the current context is compatible with the PDK e.g. in a Module context, whether it has the correct metadata.json content
57
+ # @return [Boolean] Default is not compatible
58
+ def pdk_compatible?
59
+ false
60
+ end
61
+
62
+ # The friendly name to display for this context
63
+ # @api private
64
+ # @abstract
65
+ def display_name; end
66
+
67
+ # The context which this context is in. For example a Module Context (/controlrepo/site/profile) can be inside of a Control Repo context (/controlrepo)
68
+ # The default is to search in the parent directory of this context
69
+ # @return [PDK::Context::AbstractContext, Nil] Returns the parent context or nil if there is no parent.
70
+ def parent_context
71
+ # Default detection is just look for the context in the parent directory of this context
72
+ @parent_context || PDK::Context.create(File.dirname(root_path))
73
+ end
74
+
75
+ # Writes the current context information, and parent contexts, to the PDK Debug Logger.
76
+ # This is mainly used by the PDK CLI when in debug mode to assist users to figure out why the PDK is misbehaving.
77
+ # @api private
78
+ def to_debug_log
79
+ current = self
80
+ depth = 1
81
+ loop do
82
+ PDK.logger.debug("Detected #{current.display_name} at #{current.root_path.nil? ? current.context_path : current.root_path}")
83
+ current = current.parent_context
84
+ break if current.nil?
85
+ depth += 1
86
+ # Circuit breaker in case there are circular references
87
+ break if depth > 20
88
+ end
89
+ nil
90
+ end
91
+
92
+ #:nocov: There's nothing to test here
93
+ def to_s
94
+ "#<#{self.class}:#{object_id}>#{context_path}"
95
+ end
96
+ #:nocov:
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,60 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Context
5
+ # Represents a context for a directory based Control Repository
6
+ class ControlRepo < PDK::Context::AbstractContext
7
+ # @param repo_root [String] The root path for the control repo.
8
+ # @param context_path [String] The path where this context was created from e.g. Dir.pwd
9
+ # @see PDK::Context::AbstractContext
10
+ def initialize(repo_root, context_path)
11
+ super(context_path)
12
+ @root_path = repo_root
13
+ @environment_conf = nil
14
+ end
15
+
16
+ # @see PDK::Context::AbstractContext.pdk_compatible?
17
+ def pdk_compatible?
18
+ # Currently there is nothing to determine compatibility with the PDK for a
19
+ # Control Repo. For now assume everything is compatible
20
+ true
21
+ end
22
+
23
+ # The modulepath setting for this control repository as an array of strings. These paths are relative
24
+ # and may contain interpolation strings (e.g. $basemodulepath)
25
+ # @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
26
+ # @return [Array[String]] The modulepath setting for this control repository
27
+ def module_paths
28
+ return @module_paths unless @module_paths.nil?
29
+ value = environment_conf['modulepath'] || ''
30
+ # We have to use a hardcoded value here because File::PATH_SEPARATOR is ';' on Windows.
31
+ # As the environment.conf is only used on Puppet Server, it's always ':'
32
+ # Based on - https://github.com/puppetlabs/puppet/blob/f3e6d7e6d87f46408943a8e2176afb82ff6ea096/lib/puppet/settings/environment_conf.rb#L98-L106
33
+ @module_paths = value.split(':')
34
+ end
35
+
36
+ # The relative module_paths that exist on disk.
37
+ # @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
38
+ # @return [Array[String]] The relative module paths on disk
39
+ def actualized_module_paths
40
+ @actualized_module_paths ||= module_paths.reject { |path| path.start_with?('$') }
41
+ .select { |path| PDK::Util::Filesystem.directory?(PDK::Util::Filesystem.expand_path(File.join(root_path, path))) }
42
+ end
43
+
44
+ #:nocov:
45
+ # @see PDK::Context::AbstractContext.display_name
46
+ def display_name
47
+ _('a Control Repository context')
48
+ end
49
+ #:nocov:
50
+
51
+ private
52
+
53
+ # Memoization helper to read the environment.conf file.
54
+ # @return [PDK::Config::IniFile]
55
+ def environment_conf
56
+ @environment_conf ||= PDK::ControlRepo.environment_conf_as_config(File.join(root_path, 'environment.conf'))
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,28 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Context
5
+ # Represents a context for a Puppet Module
6
+ class Module < PDK::Context::AbstractContext
7
+ # @param module_root [String] The root path for the module.
8
+ # @param context_path [String] The path where this context was created from e.g. Dir.pwd
9
+ # @see PDK::Context::AbstractContext
10
+ def initialize(module_root, context_path)
11
+ super(context_path)
12
+ @root_path = module_root
13
+ end
14
+
15
+ # @see PDK::Context::AbstractContext.pdk_compatible?
16
+ def pdk_compatible?
17
+ PDK::Util.module_pdk_compatible?(root_path)
18
+ end
19
+
20
+ #:nocov:
21
+ # @see PDK::Context::AbstractContext.display_name
22
+ def display_name
23
+ _('a Puppet Module context')
24
+ end
25
+ #:nocov:
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Context
5
+ # Represents a context which the PDK does not know. For example
6
+ # an empty directory
7
+ class None < PDK::Context::AbstractContext
8
+ #:nocov:
9
+ # @see PDK::Context::AbstractContext.display_name
10
+ def display_name
11
+ _('an unknown context')
12
+ end
13
+ #:nocov:
14
+
15
+ # @see PDK::Context::AbstractContext.parent_context
16
+ def parent_context
17
+ # An unknown context has no parent
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,90 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module ControlRepo
5
+ CONTROL_REPO_FILES = %w[environment.conf Puppetfile].freeze
6
+
7
+ DEFAULT_IGNORED = [
8
+ '/pkg/',
9
+ '~*',
10
+ '/coverage',
11
+ # Strictly speaking this isn't default but if people have tricked older PDK into thinking that a
12
+ # Control Repo is a module, they may have recursive symlinks in spec/fixtures/modules
13
+ '/spec/fixtures/modules/',
14
+ '/vendor/',
15
+ ].freeze
16
+
17
+ # Returns path to the root of the Control Repo being worked on.
18
+ #
19
+ # An environment.conf is required for a PDK compatible Control Repo,
20
+ # whereas Puppetfile is optional.
21
+ #
22
+ # Note - A Bolt Project can also be a Control Repo.
23
+ #
24
+ # Note - Non-Directory environments can exist however directory based
25
+ # environments are the supported/preferred way.
26
+ #
27
+ # @see https://puppet.com/docs/pe/latest/control_repo.html
28
+ #
29
+ # @param strict_check [Boolean] When strict_check is true, only return the path
30
+ # if the Control Repo is strictly _only_ a control repository. For example,
31
+ # not also a Puppet Bolt project directory Default is false.
32
+ #
33
+ # @return [String, nil] Fully qualified base path to Control Repo, or nil if
34
+ # the current working dir does not appear to be within a Control Repo.
35
+ def find_control_repo_root(strict_check = false)
36
+ environment_conf_path = PDK::Util.find_upwards('environment.conf')
37
+ path = if environment_conf_path
38
+ File.dirname(environment_conf_path)
39
+ elsif control_repo_root?(Dir.pwd)
40
+ Dir.pwd
41
+ else
42
+ nil
43
+ end
44
+ return path if path.nil? || !strict_check
45
+ PDK::Bolt.bolt_project_root?(path) ? nil : path
46
+ end
47
+ module_function :find_control_repo_root
48
+
49
+ # Returns true or false depending on if any of the common files in a Control Repo
50
+ # are found in the specified directory. If a directory is not specified, the current
51
+ # working directory is used.
52
+ #
53
+ # @return [boolean] True if any folders from CONTROL_REPO_FILES are found in the current dir,
54
+ # false otherwise.
55
+ def control_repo_root?(path = Dir.pwd)
56
+ CONTROL_REPO_FILES.any? { |file| PDK::Util::Filesystem.file?(File.join(path, file)) }
57
+ end
58
+ module_function :control_repo_root?
59
+
60
+ # Returns a PDK::Config::Namespace for the specified environment.conf file.
61
+ # Note there is no validation of the path.
62
+ #
63
+ # @param path [String] The path to the environment.conf file
64
+ #
65
+ # @return [PDK::Config::IniFile] The configuration file
66
+ def environment_conf_as_config(path)
67
+ PDK::Config::IniFile.new('environment', file: path) do
68
+ setting :modulepath do
69
+ # As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
70
+ default_to { 'modules:$basemodulepath' }
71
+ end
72
+
73
+ setting :manifest do
74
+ # As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
75
+ default_to { 'manifests/' }
76
+ end
77
+ end
78
+ end
79
+ module_function :environment_conf_as_config
80
+
81
+ def default_ignored_pathspec(ignore_dotfiles = true)
82
+ require 'pathspec'
83
+
84
+ PathSpec.new(DEFAULT_IGNORED).tap do |ps|
85
+ ps.add('.*') if ignore_dotfiles
86
+ end
87
+ end
88
+ module_function :default_ignored_pathspec
89
+ end
90
+ end
@@ -7,6 +7,7 @@ module PDK
7
7
  autoload :Provider, 'pdk/generate/provider'
8
8
  autoload :PuppetClass, 'pdk/generate/puppet_class'
9
9
  autoload :PuppetObject, 'pdk/generate/puppet_object'
10
+ autoload :ResourceAPIObject, 'pdk/generate/resource_api_object'
10
11
  autoload :Task, 'pdk/generate/task'
11
12
  autoload :Transport, 'pdk/generate/transport'
12
13