2021-03-08 18:12:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Debian
|
|
|
|
class CreatePackageFileService
|
2022-08-13 15:12:31 +05:30
|
|
|
include ::Packages::FIPS
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def initialize(package:, current_user:, params: {})
|
2021-03-08 18:12:59 +05:30
|
|
|
@package = package
|
2022-11-25 23:54:43 +05:30
|
|
|
@current_user = current_user
|
2021-03-08 18:12:59 +05:30
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2022-08-13 15:12:31 +05:30
|
|
|
raise DisabledError, 'Debian registry is not FIPS compliant' if Gitlab::FIPS.enabled?
|
2021-03-08 18:12:59 +05:30
|
|
|
raise ArgumentError, "Invalid package" unless package.present?
|
2022-11-25 23:54:43 +05:30
|
|
|
raise ArgumentError, "Invalid user" unless current_user.present?
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
# Debian package file are first uploaded to incoming with empty metadata,
|
|
|
|
# and are moved later by Packages::Debian::ProcessChangesService
|
2022-11-25 23:54:43 +05:30
|
|
|
package_file = package.package_files.create!(
|
2022-08-27 11:52:29 +05:30
|
|
|
file: params[:file],
|
|
|
|
size: params[:file]&.size,
|
|
|
|
file_name: params[:file_name],
|
|
|
|
file_sha1: params[:file_sha1],
|
2021-03-08 18:12:59 +05:30
|
|
|
file_sha256: params[:file]&.sha256,
|
2022-08-27 11:52:29 +05:30
|
|
|
file_md5: params[:file_md5],
|
2021-03-08 18:12:59 +05:30
|
|
|
debian_file_metadatum_attributes: {
|
|
|
|
file_type: 'unknown',
|
|
|
|
architecture: nil,
|
|
|
|
fields: nil
|
|
|
|
}
|
|
|
|
)
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
if params[:file_name].end_with? '.changes'
|
|
|
|
::Packages::Debian::ProcessChangesWorker.perform_async(package_file.id, current_user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
package_file
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
attr_reader :package, :current_user, :params
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|