2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module External
|
|
|
|
class Processor
|
|
|
|
IncludeError = Class.new(StandardError)
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
attr_reader :context, :logger
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def initialize(values, context)
|
2018-12-13 13:39:08 +05:30
|
|
|
@values = values
|
2019-12-21 20:55:43 +05:30
|
|
|
@external_files = External::Mapper.new(values, context).process
|
2018-12-13 13:39:08 +05:30
|
|
|
@content = {}
|
2022-01-26 12:08:38 +05:30
|
|
|
@logger = context.logger
|
2019-07-31 22:56:46 +05:30
|
|
|
rescue External::Mapper::Error,
|
|
|
|
OpenSSL::SSL::SSLError => e
|
2019-02-15 15:39:39 +05:30
|
|
|
raise IncludeError, e.message
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
return @values if @external_files.empty?
|
|
|
|
|
|
|
|
validate_external_files!
|
|
|
|
merge_external_files!
|
|
|
|
append_inline_content!
|
|
|
|
remove_include_keyword!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_external_files!
|
|
|
|
@external_files.each do |file|
|
2022-01-26 12:08:38 +05:30
|
|
|
logger.instrument(:config_external_verify) do
|
|
|
|
raise IncludeError, file.error_message unless file.valid?
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_external_files!
|
|
|
|
@external_files.each do |file|
|
2022-01-26 12:08:38 +05:30
|
|
|
logger.instrument(:config_external_merge) do
|
|
|
|
@content.deep_merge!(file.to_hash)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def append_inline_content!
|
|
|
|
@content.deep_merge!(@values)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_include_keyword!
|
|
|
|
@content.tap { @content.delete(:include) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|