Class: Packages::Npm::ProcessTemporaryPackageFileService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/packages/npm/process_temporary_package_file_service.rb

Constant Summary collapse

ERRORS =
{
  unauthorized: ServiceResponse.error(message: 'Unauthorized', reason: :unauthorized),
  missing_versions: ServiceResponse.error(message: 'Missing versions', reason: :missing_versions),
  missing_deprecated_versions: ServiceResponse.error(
    message: 'Missing deprecated versions',
    reason: :missing_deprecated_versions
  )
}.freeze

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(package_file:, user:, params: {}) ⇒ ProcessTemporaryPackageFileService

Returns a new instance of ProcessTemporaryPackageFileService.



17
18
19
20
21
# File 'app/services/packages/npm/process_temporary_package_file_service.rb', line 17

def initialize(package_file:, user:, params: {})
  super(package_file.project, user, params)

  @package_file = package_file
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/packages/npm/process_temporary_package_file_service.rb', line 23

def execute
  json_doc = Gitlab::Json.parse(package_file.file.read)
  json_doc = json_doc.with_indifferent_access

  response = if params[:deprecate]
               handle_deprecation(json_doc)
             else
               handle_creation(json_doc)
             end

  response.error? ? response : ServiceResponse.success
rescue JSON::ParserError => e
  ServiceResponse.error(message: e.message, reason: :json_parser_error)
end