Class: Gitlab::Ci::Config::External::File::Base
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::External::File::Base
show all
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/config/external/file/base.rb
Constant Summary
collapse
- YAML_ALLOWLIST_EXTENSION =
/.+\.(yml|yaml)$/i
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params, context) ⇒ Base
Returns a new instance of Base.
15
16
17
18
19
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 15
def initialize(params, context)
@params = params
@context = context
@errors = []
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def context
@context
end
|
#errors ⇒ Object
Returns the value of attribute errors.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def errors
@errors
end
|
#location ⇒ Object
Returns the value of attribute location.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def location
@location
end
|
#params ⇒ Object
Returns the value of attribute params.
11
12
13
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11
def params
@params
end
|
Instance Method Details
#content ⇒ Object
41
42
43
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 41
def content
raise NotImplementedError, 'subclass must implement fetching raw content'
end
|
#eql?(other) ⇒ Boolean
56
57
58
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 56
def eql?(other)
other.hash == hash
end
|
#error_message ⇒ Object
37
38
39
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 37
def error_message
errors.first
end
|
#hash ⇒ Object
60
61
62
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 60
def hash
[params, context.project&.full_path, context.sha].hash
end
|
#invalid_extension? ⇒ Boolean
29
30
31
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 29
def invalid_extension?
location.nil? || !::File.basename(location).match?(YAML_ALLOWLIST_EXTENSION)
end
|
#invalid_location_type? ⇒ Boolean
25
26
27
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 25
def invalid_location_type?
!location.is_a?(String)
end
|
#load_and_validate_expanded_hash! ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 92
def load_and_validate_expanded_hash!
return errors.push("`#{masked_location}`: #{content_result.error}") unless content_result.valid?
if content_result.interpolated? && context.user.present?
::Gitlab::UsageDataCounters::HLLRedisCounter
.track_event('ci_interpolation_users', values: context.user.id)
end
context.logger.instrument(:config_file_expand_content_includes) do
expanded_content_hash end
validate_hash!
end
|
#matching? ⇒ Boolean
21
22
23
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 21
def matching?
location.present?
end
|
49
50
51
52
53
54
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 49
def metadata
{
context_project: context.project&.full_path,
context_sha: context.sha
}
end
|
#preload_content ⇒ Object
70
71
72
73
74
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 70
def preload_content
content
end
|
#preload_context ⇒ Object
This method is overridden to load context into the memoized result or to lazily load context via BatchLoader
66
67
68
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 66
def preload_context
end
|
#to_hash ⇒ Object
45
46
47
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 45
def to_hash
expanded_content_hash
end
|
#valid? ⇒ Boolean
33
34
35
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 33
def valid?
errors.none?
end
|
#validate_content! ⇒ Object
88
89
90
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 88
def validate_content!
errors.push("Included file `#{masked_location}` is empty or does not exist!") if content.blank?
end
|
#validate_context! ⇒ Object
84
85
86
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 84
def validate_context!
raise NotImplementedError, 'subclass must implement `validate_context!`'
end
|
#validate_location! ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/gitlab/ci/config/external/file/base.rb', line 76
def validate_location!
if invalid_location_type?
errors.push("Included file `#{masked_location}` needs to be a string")
elsif invalid_extension?
errors.push("Included file `#{masked_location}` does not have YAML extension!")
end
end
|