blob: 0e296aa0b5b2899bcf98b6182c5c8f3e3f4ae115 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# frozen_string_literal: true
require 'objspace'
module Gitlab
module Ci
class Config
module External
class Mapper
# Fetches file contents and verifies them
class Verifier < Base
private
# rubocop: disable Metrics/CyclomaticComplexity
def process_without_instrumentation(files)
files.each do |file|
# When running a pipeline, some Ci::ProjectConfig sources prepend the config content with an
# "internal" `include`. We use this condition to exclude that `include` from the included file set.
context.expandset << file unless context.internal_include?
verify_max_includes!
verify_execution_time!
file.validate_location!
file.preload_context if file.valid?
end
# We do not combine the loops because we need to load the context of all files via `BatchLoader`.
files.each do |file| # rubocop:disable Style/CombinableLoops
verify_execution_time!
file.validate_context! if file.valid?
file.preload_content if file.valid?
end
# We do not combine the loops because we need to load the content of all files via `BatchLoader`.
files.each do |file| # rubocop:disable Style/CombinableLoops
verify_execution_time!
file.validate_content! if file.valid?
file.load_and_validate_expanded_hash! if file.valid?
next unless file.valid?
# We are checking the file.content.to_s because that is returning the actual content of the file,
# whereas file.content would return the BatchLoader.
context.total_file_size_in_bytes += ObjectSpace.memsize_of(file.content.to_s)
verify_max_total_pipeline_size!
end
end
# rubocop: enable Metrics/CyclomaticComplexity
def verify_max_includes!
return if context.expandset.count <= context.max_includes
raise Mapper::TooManyIncludesError, "Maximum of #{context.max_includes} nested includes are allowed!"
end
def verify_execution_time!
context.check_execution_time!
end
def verify_max_total_pipeline_size!
return if context.total_file_size_in_bytes <= context.max_total_yaml_size_bytes
raise Mapper::TooMuchDataInPipelineTreeError, "Total size of combined CI/CD configuration is too big"
end
end
end
end
end
end
end
|