debian-mirror-gitlab/lib/gitlab/ci/config/external/file/local.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module External
module File
class Local < Base
2019-12-21 20:55:43 +05:30
extend ::Gitlab::Utils::Override
2018-12-13 13:39:08 +05:30
include Gitlab::Utils::StrongMemoize
2019-02-15 15:39:39 +05:30
def initialize(params, context)
@location = params[:local]
2018-12-13 13:39:08 +05:30
super
end
def content
strong_memoize(:content) { fetch_local_content }
end
2022-06-21 17:19:12 +05:30
def metadata
super.merge(
type: :local,
location: masked_location,
2022-07-16 23:28:13 +05:30
blob: masked_blob,
raw: masked_raw,
2022-06-21 17:19:12 +05:30
extra: {}
)
end
2018-12-13 13:39:08 +05:30
private
def validate_content!
2019-07-31 22:56:46 +05:30
if context.project&.repository.nil?
2022-04-01 21:47:47 +05:30
errors.push("Local file `#{masked_location}` does not have project!")
2019-07-31 22:56:46 +05:30
elsif content.nil?
2022-04-01 21:47:47 +05:30
errors.push("Local file `#{masked_location}` does not exist!")
2018-12-13 13:39:08 +05:30
elsif content.blank?
2022-04-01 21:47:47 +05:30
errors.push("Local file `#{masked_location}` is empty!")
2018-12-13 13:39:08 +05:30
end
end
def fetch_local_content
2022-07-23 23:45:48 +05:30
context.logger.instrument(:config_file_fetch_local_content) do
context.project.repository.blob_data_at(context.sha, location)
end
2022-05-07 20:08:51 +05:30
rescue GRPC::InvalidArgument
errors.push("Sha #{context.sha} is not valid!")
nil
2018-12-13 13:39:08 +05:30
end
2019-07-07 11:18:12 +05:30
2019-12-21 20:55:43 +05:30
override :expand_context_attrs
def expand_context_attrs
{
2019-07-07 11:18:12 +05:30
project: context.project,
sha: context.sha,
2020-04-08 14:13:33 +05:30
user: context.user,
2021-03-08 18:12:59 +05:30
parent_pipeline: context.parent_pipeline,
variables: context.variables
2019-12-21 20:55:43 +05:30
}
2019-07-07 11:18:12 +05:30
end
2022-07-16 23:28:13 +05:30
def masked_blob
strong_memoize(:masked_blob) do
context.mask_variables_from(
Gitlab::Routing.url_helpers.project_blob_url(context.project, ::File.join(context.sha, location))
)
end
end
def masked_raw
return unless context.project
strong_memoize(:masked_raw) do
context.mask_variables_from(
Gitlab::Routing.url_helpers.project_raw_url(context.project, ::File.join(context.sha, location))
)
end
end
2018-12-13 13:39:08 +05:30
end
end
end
end
end
end