Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config/yaml/loader.rb')
-rw-r--r--lib/gitlab/ci/config/yaml/loader.rb47
1 files changed, 41 insertions, 6 deletions
diff --git a/lib/gitlab/ci/config/yaml/loader.rb b/lib/gitlab/ci/config/yaml/loader.rb
index 1e9ac2b3dd5..bf20cd9c027 100644
--- a/lib/gitlab/ci/config/yaml/loader.rb
+++ b/lib/gitlab/ci/config/yaml/loader.rb
@@ -17,20 +17,23 @@ module Gitlab
end
def load
- yaml_result = load_uninterpolated_yaml
-
- return yaml_result unless yaml_result.valid?
+ if Feature.disabled?(:ci_text_interpolation, Feature.current_request, type: :gitlab_com_derisk)
+ return legacy_load
+ end
- interpolator = Interpolation::Interpolator.new(yaml_result, inputs, variables)
+ interpolator = Interpolation::TextInterpolator.new(yaml_documents, inputs, variables)
interpolator.interpolate!
if interpolator.valid?
- # This Result contains only the interpolated config and does not have a header
- Yaml::Result.new(config: interpolator.to_hash, error: nil, interpolated: interpolator.interpolated?)
+ loaded_yaml = yaml(interpolator.to_result).load!
+
+ Yaml::Result.new(config: loaded_yaml, error: nil, interpolated: interpolator.interpolated?)
else
Yaml::Result.new(error: interpolator.error_message, interpolated: interpolator.interpolated?)
end
+ rescue ::Gitlab::Config::Loader::FormatError => e
+ Yaml::Result.new(error: e.message, error_class: e)
end
def load_uninterpolated_yaml
@@ -43,6 +46,38 @@ module Gitlab
attr_reader :content, :inputs, :variables
+ def yaml(content)
+ ensure_custom_tags
+
+ ::Gitlab::Config::Loader::Yaml.new(content, additional_permitted_classes: AVAILABLE_TAGS)
+ end
+
+ def yaml_documents
+ docs = content
+ .split(::Gitlab::Config::Loader::MultiDocYaml::MULTI_DOC_DIVIDER, MAX_DOCUMENTS + 1)
+ .map { |d| yaml(d) }
+
+ docs.reject!(&:blank?)
+
+ Yaml::Documents.new(docs)
+ end
+
+ def legacy_load
+ yaml_result = load_uninterpolated_yaml
+
+ return yaml_result unless yaml_result.valid?
+
+ interpolator = Interpolation::Interpolator.new(yaml_result, inputs, variables)
+
+ interpolator.interpolate!
+
+ if interpolator.valid?
+ Yaml::Result.new(config: interpolator.to_hash, error: nil, interpolated: interpolator.interpolated?)
+ else
+ Yaml::Result.new(error: interpolator.error_message, interpolated: interpolator.interpolated?)
+ end
+ end
+
def load_yaml!
ensure_custom_tags