Skip to content

Commit 31fbb03

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 31fbb03

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

lib/puppet/modulebuilder/builder.rb

+23-37
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55
module Puppet::Modulebuilder
66
# Class to build Puppet Modules from source
77
class Builder
8-
DEFAULT_IGNORED = [
9-
'/.*',
10-
'/pkg/',
11-
'~*',
12-
'/coverage',
13-
'/checksums.json',
14-
'/REVISION',
15-
'/spec/fixtures/modules/',
16-
'/vendor/'
8+
IGNORED = [
9+
'/*',
10+
'!/manifests',
11+
'!/README*',
12+
'!/metadata.json',
13+
'!/LICENSE',
14+
'!/hiera.yaml',
15+
'!/data',
16+
'!/templates',
17+
'!/files',
18+
'!/CHANGELOG*',
19+
'!/docs',
20+
'!/REFERENCE.md',
21+
'!/locales',
22+
'!/scripts',
23+
'!/tasks',
24+
'!/plans',
25+
'!/types',
26+
'!/bolt_plugin.json',
1727
].freeze
1828

1929
attr_reader :destination, :logger
@@ -168,21 +178,6 @@ def warn_symlink(path)
168178
from: symlink_path.relative_path_from(module_path), to: symlink_path.realpath.relative_path_from(module_path))
169179
end
170180

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-
186181
# Checks if the path contains any non-ASCII characters.
187182
#
188183
# Java will throw an error when it encounters a path containing
@@ -251,20 +246,11 @@ def build_package
251246
def ignored_files
252247
require 'pathspec'
253248

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))
249+
ignored = PathSpec.new
250+
ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source))
251+
ignored = ignored.add(IGNORED.join("\n"))
263252

264-
DEFAULT_IGNORED.each { |r| ignored.add(r) }
265-
266-
ignored
267-
end
253+
ignored
268254
end
269255

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

0 commit comments

Comments
 (0)