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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-07 18:09:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-07 18:09:49 +0300
commit84f9f0cb8137637708a41152347e7754c1e9fb83 (patch)
tree6db9d8931bdb3c5b932b36345373936e2a543126 /app/services
parent75f809a2ff829574ab91628407993187d55e14a4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/ci/components/fetch_service.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/services/ci/components/fetch_service.rb b/app/services/ci/components/fetch_service.rb
new file mode 100644
index 00000000000..45abb415174
--- /dev/null
+++ b/app/services/ci/components/fetch_service.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+module Ci
+ module Components
+ class FetchService
+ include Gitlab::Utils::StrongMemoize
+
+ TEMPLATE_FILE = 'template.yml'
+
+ COMPONENT_PATHS = [
+ ::Gitlab::Ci::Components::InstancePath
+ ].freeze
+
+ def initialize(address:, current_user:)
+ @address = address
+ @current_user = current_user
+ end
+
+ def execute
+ unless component_path_class
+ return ServiceResponse.error(
+ message: "#{error_prefix} the component path is not supported",
+ reason: :unsupported_path)
+ end
+
+ component_path = component_path_class.new(address: address, content_filename: TEMPLATE_FILE)
+ content = component_path.fetch_content!(current_user: current_user)
+
+ if content.present?
+ ServiceResponse.success(payload: { content: content, path: component_path })
+ else
+ ServiceResponse.error(message: "#{error_prefix} content not found", reason: :content_not_found)
+ end
+ rescue Gitlab::Access::AccessDeniedError
+ ServiceResponse.error(
+ message: "#{error_prefix} project does not exist or you don't have sufficient permissions",
+ reason: :not_allowed)
+ end
+
+ private
+
+ attr_reader :current_user, :address
+
+ def component_path_class
+ COMPONENT_PATHS.find { |klass| klass.match?(address) }
+ end
+ strong_memoize_attr :component_path_class
+
+ def error_prefix
+ "component '#{address}' -"
+ end
+ end
+ end
+end