Module: API::Helpers::Packages::Maven

Extended by:
Grape::API::Helpers
Defined in:
lib/api/helpers/packages/maven.rb,
lib/api/helpers/packages/maven/basic_auth_helpers.rb

Defined Under Namespace

Modules: BasicAuthHelpers

Instance Method Summary collapse

Instance Method Details

#extract_format(file_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/api/helpers/packages/maven.rb', line 20

def extract_format(file_name)
  name, _, format = file_name.rpartition('.')

  if %w[md5 sha1].include?(format)
    unprocessable_entity! if Gitlab::FIPS.enabled? && format == 'md5'

    [name, format]
  else
    [file_name, format]
  end
end

#fetch_package(file_name:, project: nil, group: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/api/helpers/packages/maven.rb', line 32

def fetch_package(file_name:, project: nil, group: nil)
  order_by_package_file = file_name.include?(::Packages::Maven::Metadata.filename) &&
    params[:path].exclude?(::Packages::Maven::FindOrCreatePackageService::SNAPSHOT_TERM)

  ::Packages::Maven::PackageFinder.new(
    current_user,
    project || group,
    path: params[:path],
    order_by_package_file: order_by_package_file
  ).execute
end

#groupObject



48
49
50
# File 'lib/api/helpers/packages/maven.rb', line 48

def group
  nil
end

#head_request_on_aws_file?(file, supports_direct_download) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'lib/api/helpers/packages/maven.rb', line 72

def head_request_on_aws_file?(file, supports_direct_download)
  Gitlab.config.packages.object_store.enabled &&
    supports_direct_download &&
    file.class.direct_download_enabled? &&
    request.head? &&
    file.fog_credentials[:provider] == 'AWS'
end

#present_carrierwave_file_with_head_support!(package_file, supports_direct_download: true) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/api/helpers/packages/maven.rb', line 52

def present_carrierwave_file_with_head_support!(package_file, supports_direct_download: true)
  package_file.package.touch_last_downloaded_at
  file = package_file.file

  if head_request_on_aws_file?(file, supports_direct_download) && !file.file_storage?
    return redirect(signed_head_url(file))
  end

  present_carrierwave_file!(file, supports_direct_download: supports_direct_download)
end

#projectObject



44
45
46
# File 'lib/api/helpers/packages/maven.rb', line 44

def project
  nil
end

#signed_head_url(file) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/api/helpers/packages/maven.rb', line 63

def signed_head_url(file)
  fog_storage = ::Fog::Storage.new(file.fog_credentials)
  fog_dir = fog_storage.directories.new(key: file.fog_directory)
  fog_file = fog_dir.files.new(key: file.path)
  expire_at = ::Fog::Time.now + file.fog_authenticated_url_expiration

  fog_file.collection.head_url(fog_file.key, expire_at)
end