Class: Ci::Components::FetchService
- Inherits:
-
Object
- Object
- Ci::Components::FetchService
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/ci/components/fetch_service.rb
Constant Summary collapse
- TEMPLATE_FILE =
'template.yml'
- COMPONENT_PATHS =
[ ::Gitlab::Ci::Components::InstancePath ].freeze
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(address:, current_user:) ⇒ FetchService
constructor
A new instance of FetchService.
Constructor Details
#initialize(address:, current_user:) ⇒ FetchService
Returns a new instance of FetchService.
14 15 16 17 |
# File 'app/services/ci/components/fetch_service.rb', line 14 def initialize(address:, current_user:) @address = address @current_user = current_user end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/ci/components/fetch_service.rb', line 19 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 |