Module: API::Helpers::PackagesHelpers

Included in:
PackagesManagerClientsHelpers
Defined in:
lib/api/helpers/packages_helpers.rb

Constant Summary collapse

MAX_PACKAGE_FILE_SIZE =
50.megabytes.freeze

Instance Method Summary collapse

Instance Method Details

#authorize_create_package!(subject = user_project) ⇒ Object


20
21
22
# File 'lib/api/helpers/packages_helpers.rb', line 20

def authorize_create_package!(subject = user_project)
  authorize!(:create_package, subject)
end

#authorize_destroy_package!(subject = user_project) ⇒ Object


24
25
26
# File 'lib/api/helpers/packages_helpers.rb', line 24

def authorize_destroy_package!(subject = user_project)
  authorize!(:destroy_package, subject)
end

#authorize_packages_access!(subject = user_project) ⇒ Object


28
29
30
31
# File 'lib/api/helpers/packages_helpers.rb', line 28

def authorize_packages_access!(subject = user_project)
  require_packages_enabled!
  authorize_read_package!(subject)
end

#authorize_read_package!(subject = user_project) ⇒ Object


16
17
18
# File 'lib/api/helpers/packages_helpers.rb', line 16

def authorize_read_package!(subject = user_project)
  authorize!(:read_package, subject)
end

#authorize_upload!(subject = user_project) ⇒ Object


46
47
48
49
# File 'lib/api/helpers/packages_helpers.rb', line 46

def authorize_upload!(subject = user_project)
  authorize_create_package!(subject)
  require_gitlab_workhorse!
end

#authorize_workhorse!(subject: user_project, has_length: true, maximum_size: MAX_PACKAGE_FILE_SIZE) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/api/helpers/packages_helpers.rb', line 33

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
  ::Packages::PackageFileUploader.workhorse_authorize(params)
end

#package_event(event_name, **args) ⇒ Object


51
52
53
# File 'lib/api/helpers/packages_helpers.rb', line 51

def package_event(event_name, **args)
  track_event(event_name, **args)
end

#require_dependency_proxy_enabled!Object


12
13
14
# File 'lib/api/helpers/packages_helpers.rb', line 12

def require_dependency_proxy_enabled!
  not_found! unless ::Gitlab.config.dependency_proxy.enabled
end

#require_packages_enabled!Object


8
9
10
# File 'lib/api/helpers/packages_helpers.rb', line 8

def require_packages_enabled!
  not_found! unless ::Gitlab.config.packages.enabled
end