Skip to content

Commit a1dedbc

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 28f946b commit a1dedbc

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

lib/puppet/modulebuilder/builder.rb

+25-36
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+
'!/CHANGELOG*',
15+
'!/LICENSE',
16+
'!/README*',
17+
'!/REFERENCE.md',
18+
'!/bolt_plugin.json',
19+
'!/data/**',
20+
'!/docs/**',
21+
'!/files/**',
22+
'!/hiera.yaml',
23+
'!/locales/**',
24+
'!/manifests/**',
25+
'!/metadata.json',
26+
'!/plans/**',
27+
'!/scripts/**',
28+
'!/tasks/**',
29+
'!/templates/**',
30+
'!/types/**',
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,10 @@ 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(IGNORED)
254+
ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source))
263255

264-
DEFAULT_IGNORED.each { |r| ignored.add(r) }
265-
266-
ignored
267-
end
256+
ignored
268257
end
269258

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

0 commit comments

Comments
 (0)