pdk 1.16.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +167 -11
  3. data/README.md +1 -1
  4. data/lib/pdk.rb +26 -19
  5. data/lib/pdk/answer_file.rb +2 -93
  6. data/lib/pdk/cli.rb +8 -6
  7. data/lib/pdk/cli/config.rb +3 -1
  8. data/lib/pdk/cli/config/get.rb +3 -1
  9. data/lib/pdk/cli/convert.rb +7 -9
  10. data/lib/pdk/cli/env.rb +52 -0
  11. data/lib/pdk/cli/exec/command.rb +13 -0
  12. data/lib/pdk/cli/exec_group.rb +78 -43
  13. data/lib/pdk/cli/get.rb +20 -0
  14. data/lib/pdk/cli/get/config.rb +24 -0
  15. data/lib/pdk/cli/new.rb +2 -0
  16. data/lib/pdk/cli/new/class.rb +2 -1
  17. data/lib/pdk/cli/new/defined_type.rb +2 -1
  18. data/lib/pdk/cli/new/fact.rb +29 -0
  19. data/lib/pdk/cli/new/function.rb +29 -0
  20. data/lib/pdk/cli/new/provider.rb +2 -1
  21. data/lib/pdk/cli/new/task.rb +2 -1
  22. data/lib/pdk/cli/new/test.rb +2 -1
  23. data/lib/pdk/cli/new/transport.rb +2 -1
  24. data/lib/pdk/cli/release/publish.rb +11 -1
  25. data/lib/pdk/cli/remove.rb +20 -0
  26. data/lib/pdk/cli/remove/config.rb +80 -0
  27. data/lib/pdk/cli/set.rb +20 -0
  28. data/lib/pdk/cli/set/config.rb +119 -0
  29. data/lib/pdk/cli/update.rb +6 -8
  30. data/lib/pdk/cli/util.rb +7 -3
  31. data/lib/pdk/cli/util/option_validator.rb +6 -0
  32. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  33. data/lib/pdk/cli/validate.rb +26 -44
  34. data/lib/pdk/config.rb +264 -7
  35. data/lib/pdk/config/ini_file.rb +183 -0
  36. data/lib/pdk/config/ini_file_setting.rb +39 -0
  37. data/lib/pdk/config/namespace.rb +25 -5
  38. data/lib/pdk/config/setting.rb +3 -2
  39. data/lib/pdk/context.rb +99 -0
  40. data/lib/pdk/context/control_repo.rb +60 -0
  41. data/lib/pdk/context/module.rb +28 -0
  42. data/lib/pdk/context/none.rb +22 -0
  43. data/lib/pdk/control_repo.rb +40 -0
  44. data/lib/pdk/generate/defined_type.rb +25 -32
  45. data/lib/pdk/generate/fact.rb +25 -0
  46. data/lib/pdk/generate/function.rb +48 -0
  47. data/lib/pdk/generate/module.rb +14 -17
  48. data/lib/pdk/generate/provider.rb +15 -64
  49. data/lib/pdk/generate/puppet_class.rb +25 -31
  50. data/lib/pdk/generate/puppet_object.rb +83 -187
  51. data/lib/pdk/generate/task.rb +28 -46
  52. data/lib/pdk/generate/transport.rb +20 -74
  53. data/lib/pdk/module.rb +1 -1
  54. data/lib/pdk/module/convert.rb +43 -23
  55. data/lib/pdk/module/metadata.rb +6 -2
  56. data/lib/pdk/module/release.rb +3 -9
  57. data/lib/pdk/module/update.rb +7 -11
  58. data/lib/pdk/module/update_manager.rb +7 -0
  59. data/lib/pdk/report.rb +3 -3
  60. data/lib/pdk/report/event.rb +8 -2
  61. data/lib/pdk/template.rb +59 -0
  62. data/lib/pdk/template/fetcher.rb +98 -0
  63. data/lib/pdk/template/fetcher/git.rb +85 -0
  64. data/lib/pdk/template/fetcher/local.rb +28 -0
  65. data/lib/pdk/template/renderer.rb +96 -0
  66. data/lib/pdk/template/renderer/v1.rb +25 -0
  67. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
  68. data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
  69. data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
  70. data/lib/pdk/template/template_dir.rb +67 -0
  71. data/lib/pdk/tests/unit.rb +8 -1
  72. data/lib/pdk/util.rb +38 -39
  73. data/lib/pdk/util/bundler.rb +2 -1
  74. data/lib/pdk/util/changelog_generator.rb +11 -2
  75. data/lib/pdk/util/json_finder.rb +84 -0
  76. data/lib/pdk/util/puppet_strings.rb +3 -3
  77. data/lib/pdk/util/puppet_version.rb +2 -2
  78. data/lib/pdk/util/ruby_version.rb +5 -1
  79. data/lib/pdk/util/template_uri.rb +13 -14
  80. data/lib/pdk/util/vendored_file.rb +1 -2
  81. data/lib/pdk/validate.rb +79 -25
  82. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  83. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  84. data/lib/pdk/validate/external_command_validator.rb +208 -0
  85. data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
  86. data/lib/pdk/validate/invokable_validator.rb +220 -0
  87. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
  88. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
  89. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  90. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
  91. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  92. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
  93. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
  94. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
  95. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  96. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
  97. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
  98. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  99. data/lib/pdk/validate/validator.rb +118 -0
  100. data/lib/pdk/validate/validator_group.rb +104 -0
  101. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
  102. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  103. data/lib/pdk/version.rb +1 -1
  104. data/locales/pdk.pot +477 -313
  105. metadata +77 -35
  106. data/lib/pdk/module/template_dir.rb +0 -115
  107. data/lib/pdk/module/template_dir/base.rb +0 -268
  108. data/lib/pdk/module/template_dir/git.rb +0 -91
  109. data/lib/pdk/module/template_dir/local.rb +0 -21
  110. data/lib/pdk/template_file.rb +0 -96
  111. data/lib/pdk/validate/base_validator.rb +0 -215
  112. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
  113. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
  114. data/lib/pdk/validate/metadata_validator.rb +0 -26
  115. data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
  116. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
  117. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
  118. data/lib/pdk/validate/puppet_validator.rb +0 -26
  119. data/lib/pdk/validate/ruby/rubocop.rb +0 -72
  120. data/lib/pdk/validate/ruby_validator.rb +0 -26
  121. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
  122. data/lib/pdk/validate/tasks/name.rb +0 -90
  123. data/lib/pdk/validate/tasks_validator.rb +0 -29
  124. data/lib/pdk/validate/yaml/syntax.rb +0 -125
  125. data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -0,0 +1,183 @@
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ class Config
5
+ # Represents a configuration file using the INI file format
6
+ class IniFile < Namespace
7
+ # Ini Files have very strict valdiation rules which are set in the IniFileSetting class
8
+ # @see PDK::Config::Namespace.default_setting_class
9
+ def default_setting_class
10
+ PDK::Config::IniFileSetting
11
+ end
12
+
13
+ # Parses an IniFile document.
14
+ #
15
+ # @see PDK::Config::Namespace.parse_file
16
+ def parse_file(filename)
17
+ raise unless block_given?
18
+ data = load_data(filename)
19
+ return if data.nil? || data.empty?
20
+
21
+ ini_file = IniFileImpl.parse(data)
22
+ ini_file.to_hash.each do |name, value|
23
+ begin
24
+ new_setting = PDK::Config::IniFileSetting.new(name, self, value)
25
+ rescue StandardError
26
+ # We just ignore invalid initial settings
27
+ new_setting = PDK::Config::IniFileSetting.new(name, self, nil)
28
+ end
29
+
30
+ yield name, new_setting
31
+ end
32
+ end
33
+
34
+ # Serializes object data into an INI file string.
35
+ #
36
+ # @see PDK::Config::Namespace.serialize_data
37
+ def serialize_data(data)
38
+ default_lines = ''
39
+ lines = ''
40
+ data.each do |name, value|
41
+ next if value.nil?
42
+ if value.is_a?(Hash)
43
+ # Hashes are an INI section
44
+ lines += "\n[#{name}]\n"
45
+ value.each do |child_name, child_value|
46
+ next if child_value.nil?
47
+ lines += "#{child_name} = #{munge_serialized_value(child_value)}\n"
48
+ end
49
+ else
50
+ default_lines += "#{name} = #{munge_serialized_value(value)}\n"
51
+ end
52
+ end
53
+
54
+ default_lines + lines
55
+ end
56
+
57
+ private
58
+
59
+ def munge_serialized_value(value)
60
+ value = value.to_s unless value.is_a?(String)
61
+ # Add enclosing quotes if there's a space in the value
62
+ value = '"' + value + '"' if value.include?(' ')
63
+ value
64
+ end
65
+
66
+ # Adapted from https://raw.githubusercontent.com/puppetlabs/puppet/6c257fc7827989c2af2901f974666f0f23611153/lib/puppet/settings/ini_file.rb
67
+ # rubocop:disable Style/RegexpLiteral
68
+ # rubocop:disable Style/PerlBackrefs
69
+ # rubocop:disable Style/RedundantSelf
70
+ # rubocop:disable Style/StringLiterals
71
+ class IniFileImpl
72
+ DEFAULT_SECTION_NAME = 'default_section_name'.freeze
73
+
74
+ def self.parse(config_fh)
75
+ config = new([DefaultSection.new])
76
+ config_fh.each_line do |line|
77
+ case line.chomp
78
+ when /^(\s*)\[([[:word:]]+)\](\s*)$/
79
+ config.append(SectionLine.new($1, $2, $3))
80
+ when /^(\s*)([[:word:]]+)(\s*=\s*)(.*?)(\s*)$/
81
+ config.append(SettingLine.new($1, $2, $3, $4, $5))
82
+ else
83
+ config.append(Line.new(line))
84
+ end
85
+ end
86
+
87
+ config
88
+ end
89
+
90
+ def initialize(lines = [])
91
+ @lines = lines
92
+ end
93
+
94
+ def to_hash
95
+ result = {}
96
+
97
+ current_section_name = nil
98
+ @lines.each do |line|
99
+ if line.instance_of?(SectionLine)
100
+ current_section_name = line.name
101
+ result[current_section_name] = {}
102
+ elsif line.instance_of?(SettingLine)
103
+ if current_section_name.nil?
104
+ result[line.name] = munge_value(line.value)
105
+ else
106
+ result[current_section_name][line.name] = munge_value(line.value)
107
+ end
108
+ end
109
+ end
110
+
111
+ result
112
+ end
113
+
114
+ def munge_value(value)
115
+ value = value.to_s unless value.is_a?(String)
116
+ # Strip enclosing quotes
117
+ value = value.slice(1...-1) if value.start_with?('"') && value.end_with?('"')
118
+ value
119
+ end
120
+
121
+ def append(line)
122
+ line.previous = @lines.last
123
+ @lines << line
124
+ end
125
+
126
+ module LineNumber
127
+ attr_accessor :previous
128
+
129
+ def line_number
130
+ line = 0
131
+ previous_line = previous
132
+ while previous_line
133
+ line += 1
134
+ previous_line = previous_line.previous
135
+ end
136
+ line
137
+ end
138
+ end
139
+
140
+ Line = Struct.new(:text) do
141
+ include LineNumber
142
+
143
+ def to_s
144
+ text
145
+ end
146
+ end
147
+
148
+ SettingLine = Struct.new(:prefix, :name, :infix, :value, :suffix) do
149
+ include LineNumber
150
+
151
+ def to_s
152
+ "#{prefix}#{name}#{infix}#{value}#{suffix}"
153
+ end
154
+
155
+ def ==(other)
156
+ super(other) && self.line_number == other.line_number
157
+ end
158
+ end
159
+
160
+ SectionLine = Struct.new(:prefix, :name, :suffix) do
161
+ include LineNumber
162
+
163
+ def to_s
164
+ "#{prefix}[#{name}]#{suffix}"
165
+ end
166
+ end
167
+
168
+ class DefaultSection < SectionLine
169
+ attr_accessor :write_sectionline
170
+
171
+ def initialize
172
+ @write_sectionline = false
173
+ super("", DEFAULT_SECTION_NAME, "")
174
+ end
175
+ end
176
+ end
177
+ # rubocop:enable Style/StringLiterals
178
+ # rubocop:enable Style/RedundantSelf
179
+ # rubocop:enable Style/PerlBackrefs
180
+ # rubocop:enable Style/RegexpLiteral
181
+ end
182
+ end
183
+ end
@@ -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
@@ -34,6 +34,7 @@ module PDK
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