2020-07-17 02:09:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module PackagesHelpers
|
|
|
|
MAX_PACKAGE_FILE_SIZE = 50.megabytes.freeze
|
|
|
|
|
|
|
|
def require_packages_enabled!
|
|
|
|
not_found! unless ::Gitlab.config.packages.enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_dependency_proxy_enabled!
|
|
|
|
not_found! unless ::Gitlab.config.dependency_proxy.enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_read_package!(subject = user_project)
|
|
|
|
authorize!(:read_package, subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_create_package!(subject = user_project)
|
|
|
|
authorize!(:create_package, subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_destroy_package!(subject = user_project)
|
|
|
|
authorize!(:destroy_package, subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_packages_access!(subject = user_project)
|
|
|
|
require_packages_enabled!
|
|
|
|
authorize_read_package!(subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_workhorse!(subject: user_project, has_length: true, maximum_size: MAX_PACKAGE_FILE_SIZE)
|
|
|
|
authorize_upload!(subject)
|
|
|
|
|
|
|
|
Gitlab::Workhorse.verify_api_request!(headers)
|
|
|
|
|
|
|
|
status 200
|
|
|
|
content_type Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE
|
|
|
|
|
|
|
|
params = { has_length: has_length }
|
|
|
|
params[:maximum_size] = maximum_size unless has_length
|
2020-09-30 17:10:09 -04:00
|
|
|
::Packages::PackageFileUploader.workhorse_authorize(**params)
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_upload!(subject = user_project)
|
|
|
|
authorize_create_package!(subject)
|
|
|
|
require_gitlab_workhorse!
|
|
|
|
end
|
2020-09-09 08:08:22 -04:00
|
|
|
|
2020-09-30 08:09:53 -04:00
|
|
|
def track_package_event(event_name, scope, **args)
|
|
|
|
::Packages::CreateEventService.new(nil, current_user, event_name: event_name, scope: scope).execute
|
2020-09-09 08:08:22 -04:00
|
|
|
track_event(event_name, **args)
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|