Skip to content

Commit a52e02a

Browse files
committed
Implement allowlist for puppet module content
This implements puppetlabs/puppet-specifications#157 * By default every file is ignored * Only files from the official specification for puppet modules are added to the allowlist * support for .pdkignore, .pmtignore and .gitignore is removed
1 parent ea9757d commit a52e02a

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

lib/puppet/modulebuilder/builder.rb

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@
55
module Puppet::Modulebuilder
66
# Class to build Puppet Modules from source
77
class Builder
8-
DEFAULT_IGNORED = [
8+
# Due to the way how PathSpec generates the regular expression,
9+
# `/*` doesn't match directories starting with a dot,
10+
# so we need `/.*` as well.
11+
IGNORED = [
12+
'/*',
913
'/.*',
10-
'/pkg/',
11-
'~*',
12-
'/coverage',
13-
'/checksums.json',
14-
'/REVISION',
15-
'/spec/fixtures/modules/',
16-
'/vendor/'
14+
'!/manifests',
15+
'!/README*',
16+
'!/metadata.json',
17+
'!/LICENSE',
18+
'!/hiera.yaml',
19+
'!/data',
20+
'!/templates',
21+
'!/files',
22+
'!/CHANGELOG*',
23+
'!/docs',
24+
'!/REFERENCE.md',
25+
'!/locales',
26+
'!/scripts',
27+
'!/tasks',
28+
'!/plans',
29+
'!/types',
30+
'!/bolt_plugin.json',
1731
].freeze
1832

1933
attr_reader :destination, :logger
@@ -168,21 +182,6 @@ def warn_symlink(path)
168182
from: symlink_path.relative_path_from(module_path), to: symlink_path.realpath.relative_path_from(module_path))
169183
end
170184

171-
# Select the most appropriate ignore file in the module directory.
172-
#
173-
# In order of preference, we first try `.pdkignore`, then `.pmtignore`
174-
# and finally `.gitignore`.
175-
#
176-
# @return [String] The path to the file containing the patterns of file
177-
# paths to ignore.
178-
def ignore_file
179-
@ignore_file ||= [
180-
File.join(source, '.pdkignore'),
181-
File.join(source, '.pmtignore'),
182-
File.join(source, '.gitignore')
183-
].find { |file| file_exists?(file) && file_readable?(file) }
184-
end
185-
186185
# Checks if the path contains any non-ASCII characters.
187186
#
188187
# Java will throw an error when it encounters a path containing
@@ -251,20 +250,11 @@ def build_package
251250
def ignored_files
252251
require 'pathspec'
253252

254-
@ignored_files ||=
255-
begin
256-
ignored = if ignore_file.nil?
257-
PathSpec.new
258-
else
259-
PathSpec.new(read_file(ignore_file, open_args: 'rb:UTF-8'))
260-
end
261-
262-
ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source))
253+
ignored = PathSpec.new
254+
ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source))
255+
ignored = ignored.add(IGNORED.join("\n"))
263256

264-
DEFAULT_IGNORED.each { |r| ignored.add(r) }
265-
266-
ignored
267-
end
257+
ignored
268258
end
269259

270260
# Create a temporary build directory where the files to be included in

0 commit comments

Comments
 (0)