debian-mirror-gitlab/app/services/packages/pypi/create_package_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Pypi
2020-11-24 15:15:51 +05:30
class CreatePackageService < ::Packages::CreatePackageService
2020-07-28 23:09:34 +05:30
include ::Gitlab::Utils::StrongMemoize
def execute
::Packages::Package.transaction do
2020-11-24 15:15:51 +05:30
meta = Packages::Pypi::Metadatum.new(
package: created_package,
2022-05-07 20:08:51 +05:30
required_python: params[:requires_python] || ''
2020-07-28 23:09:34 +05:30
)
2020-11-24 15:15:51 +05:30
unless meta.valid?
2021-06-08 01:23:25 +05:30
raise ActiveRecord::RecordInvalid, meta
2020-11-24 15:15:51 +05:30
end
2022-08-13 15:12:31 +05:30
params.delete(:md5_digest) if Gitlab::FIPS.enabled?
2020-11-24 15:15:51 +05:30
Packages::Pypi::Metadatum.upsert(meta.attributes)
2020-07-28 23:09:34 +05:30
::Packages::CreatePackageFileService.new(created_package, file_params).execute
2021-02-22 17:27:13 +05:30
created_package
2020-07-28 23:09:34 +05:30
end
end
private
def created_package
strong_memoize(:created_package) do
2020-11-24 15:15:51 +05:30
find_or_create_package!(:pypi)
2020-07-28 23:09:34 +05:30
end
end
def file_params
{
2021-02-22 17:27:13 +05:30
build: params[:build],
2020-07-28 23:09:34 +05:30
file: params[:content],
file_name: params[:content].original_filename,
file_md5: params[:md5_digest],
file_sha256: params[:sha256_digest]
}
end
end
end
end